《求助》基于51单片机的拖尾灯
#include<reg52.h>
#define uint unsigned int
#define uchar unsigned char
uchar abit=16; //流到哪位
uchar atimer0_n;
uchar code abit8[9]={1,2,4,8,16,32,64,128,0};
uchar nn;
char a,b,c,d;
main()
{ TMOD = 0x11;
TL0 = 0x00; //2.5ms
TH0 = 0xF7;
TF0 = 0;
TR0 = 1;
EA=1;ET0=1;
while(1)
{
a=abit;
if(a>7||a<0)
a=8;
b=abit-1;
if(b>7||b<0)
b=8;
c=abit-2;
if(c>7||c<0)
c=8;
d=abit-3;
if(d>7||d<0)
d=8;
atimer0_n++;
if(atimer0_n==255)
atimer0_n=0;
if(atimer0_n<5)
P1=0xff-abit8[a];
if(atimer0_n<40)
P1=0xff-abit8[b];
if(atimer0_n<150)
P1=0xff-abit8[c];
if(atimer0_n<255)
P1=0xff-abit8[d];
}
}
atimer0 () interrupt 1
{
TL0 = 0x00; //50ms
TH0 = 0x4C;
nn++;
if(nn==2)
{
nn=0;abit--;
if(abit==0)
abit=16;
}
}