單片機(jī)LED燈計(jì)數(shù)
代碼如下:
#include
sbit P1_7 = P1 ^ 7;
sbit P1_6 = P1 ^ 6;
sbit P1_5 = P1 ^ 5;
sbit P1_4 = P1 ^ 4;
void delay(unsigned char i) {
unsigned int j = 0,k = 0;
for(k = 0; k < i; k++)
for(j = 0; j < 255; j++);
}
void main(void) {
char i = 0;
while (1) {
P1_7 = 0;
delay(200);
P1_6 = 0;
delay(200);
P1_5 = 0;
delay(200);
P1_4 = 0;
delay(200);
P1_7 = 1;
delay(200);
P1_6 = 1;
delay(200);
P1_5 = 1;
delay(200);
P1_4 = 1;
delay(200);
}
}
評(píng)論