51单片机C程序怎样把LED灯从左到右点亮然后又从右到左点亮然后循环

2024-10-31 15:16:46
推荐回答(3个)
回答1:

#include

unsigned char ledtab[]={0x7f,0xbf,0xdf,0xef,0xf7,0xfb,0xfd,0xfe}
void delay(unsigned char a)
{
unsigned char i,j;
for(i=0;ifor(j=0;j<120;j++);
}
main()
{
unsigned char i;
while(1)
{
for(i=0;i<8;i++){P0=ledtab[i];delay(100);}
for(i=0;i<8;i++){P0=ledtab[7-i];delay(100);}
}
}

回答2:

#include
#include
void delay(int x)
{
int a,b;
for(a=0;a {
for(b=0;b<120;b++)
; }
}

void main()
{
while(1)
{
unsigned char i;
for(i=0;i<8;i++)
{
P2=_crol_(0x01,i);
delay(150); }
}
}
}

回答3:

参考:

http://hi.baidu.com/do_sermon/item/e69c66d832d426e3795daa82