//51单片机控制八个发光二极管左右循环。
#include
#defineucharunsignedchar
#defineuintunsignedint
unsignedcharTAB[]={0xff,0xfe,0xfd,0xfb,0xf7,0xef,0xdf,0xbf,0x7f,0xff,0x7f,0xbf,0xdf,0xef,0xf7,0xfb,0xfd,0xfe,0xff};//改变这里LED各种花样
uchart,i;
voidmain()
{
TMOD=0x10;
TH1=(65535-50000)/256; //50ms一次
TL1=(65535-50000)%256;
EA=1;
ET1=1;//开定时器1中断
TR1=1;//启动定时器1
t=0;
i=0;
while(1)
{
}
}
voidtimer1()interrupt3
{
TH1=(65535-50000)/256; //50ms一次
TL1=(65535-50000)%256;
t++;
if(t==20)
{
t=0;
P2=TAB[i];
i++;
if(i==18){i=0;}
}
}