1.通过数组实现led流水灯
#include <reg52.h>
int m;
unsigned char code leds[8] = {0x7f, 0xbf, 0xdf, 0xef, 0xf7, 0xfb, 0xfd, 0xfe};
void delay(unsigned int i)
{
unsigned int j;
unsigned char k;
for(j=i; j>0; j--)
for(k=125; k>0 ;k--);
}
int main()
{
while(1)
{
for(m = 0; m < 8; m++)
{
P1 = leds[m];
delay(500);
}
}
return 0;
}
使用
if语句实现led灯的控制,i类似于标志位控制进行循环转移
i = 0;
while(1)
{
P1 = leds[i++];
delay(5000);
if(i == 8) i = 0;
}
2.通过独立按键实现LED灯的闪烁流动
运用独立按键需I/O端口&#