標(biāo)題: 51單片機(jī)流水燈代碼 [打印本頁]

作者: 51dpj5    時間: 2024-4-6 18:28
標(biāo)題: 51單片機(jī)流水燈代碼
#include <reg51.h>

#define LED P2

void delay(unsigned int time) {
    unsigned int i, j;
    for(i = 0; i < time; i++)
        for(j = 0; j < 300; j++);
}

void odd_even_blink() {
    unsigned char count;
    for(count = 0; count < 3; count++) {
        LED = 0xAA;
        delay(1000);
        LED = 0x55;
        delay(1000);
    }
    LED = 0x00;
    delay(1000);
}

void water_light() {
    unsigned char count;
    for(count = 0; count < 3; count++) {
        unsigned char i;
        for(i = 0x01; i <= 0x80; i <<= 1) {
            LED = i;
            delay(300);
        }
        for(i = 0x40; i >= 0x02; i >>= 1) {
            LED = i;
            delay(300);
        }
    }
}

void main() {
    while(1) {
        odd_even_blink();
        water_light();
    }
}






歡迎光臨 (http://www.torrancerestoration.com/bbs/) Powered by Discuz! X3.1