51单片机的八个LED循环点亮,如何写代码?
1个回答
展开全部
#include<reg52.h>
#define uchar unsigned char
#define uint unsigned int
unsigned char TAB[]= {0xff,0xfe,0xfd,0xfb,0xf7,0xef,0xdf,0xbf,0x7f,0xff,0x7f,0xbf,0xdf,0xef,0xf7,0xfb,0xfd,0xfe,0xff}; // 改变这里 LED 各种花样
uchar t,i;
void main()
{
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)
{
}
}
void timer1() interrupt 3
{
TH1=(65535-50000)/256; // 50ms一次
TL1=(65535-50000)%256;
t++;
if(t==20)
{
t=0;
P2=TAB[i];
i++;
if(i==18) { i=0;}
}
}
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询