发布网友 发布时间:2022-05-15 05:23
共1个回答
热心网友 时间:2023-10-09 23:32
//51单片机。写一个P2口的流水灯 仿真+程序
#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;}
}
}