灯光起来其实是看你对单片机引脚的输出,用二进制表示
你可以打开电脑的计算器,从查看那里选择 程序员 类型的计算器,使用二进制
1000 0000表示左边第一个灯,1100 0000表示左边两个灯
然后转回十进制或十六进制赋值给引脚p0,假设流水灯使用p0口
while(1)就是灯一个一个的亮,1 2 3 4 5 6 7 8最后全亮
追答#include
unsigned char code ledchar[] = {0xFe,0xFC,0xF8,0xF0,0xE0,0xC0,0x80,0x00};
void delay(unsigned int z)
{
unsigned int i;
unsigned char j;
for(i=0; i<z; i++)
for(j=0; j<110; j++);
}
void main()
{
unsigned char i = 0;
while(1)
{
if(key==0)
{
delay(10); //延时10ms
if(key==0)
{
flag = 1;
while(!key); //等待松手
}
}
if(flag)
{
flag = 0;
for(i=0; i<8; i++)
{
P0 = ledchar[i];
delay(1000); //延时1秒
}
}
}
}
基本上是可以达到你说的那个要求的,我没试验,你自己试试,
最上面的那个数组,是按照 led正极 接电源,负极接IO口的,如果你是反的可以把数组里的代码取反就好了
P0 = ledchar[i]; 就是在点亮LED,如果你接的不是P0口的话,自己看下是接在那个口的,改下就可以了