编写一段程序实现以下功能;两个按键
1.一段按键按键按下一次实现LED状态翻转
另外一个按键控制流水灯的暂停和停运,随时随停,随按随走
对整个程序进行文字说明 表明编程思路和实现的逻辑
作业还是自己做吧
#include<reg52.h>
#define uint unsigned int
#define uchar unsigned char
sbit key2=P3^4;
sbit key3=P3^6;
sbit LED1=P1^0;
sbit LED2=P1^1;
uint count1=0;
uint count2=0;
uchar dat_A,dat_B;
bit flag=0;
void delay(uint i)
{
while(--i);
}
void init()
{
TMOD=0x21;
TH0=0xfc; //1毫秒@11.0592MHz
TL0=0x66;
TH1=0xfd;
TL1=0xfd;
SM0=0;
SM1=1;
TR0=1;
TR1=1;
EA=1;
ET0=1;
}
void SendData(uchar dat)
{
SBUF = dat; //发送当前数据
while(!TI); //等待发送完毕
TI = 0; //清除发送标志
}
void main()
{
init();
while(1)
{
if(key2==0)
{
delay(1000);
if(key2==0)
{
LED1=~LED1;
while(!key2);
}
}
if(key3==0)
{
delay(1000);
if(key3==0 && flag==0)
flag=1;
}
else
{
if(flag==1)
{
EA=0;//关中断
flag=0;
dat_A=count1; //分解低8位
dat_B=count1>>8;//分解高8位
count1=0;
SendData(dat_A);//发送低8位
SendData(dat_B);//发送高8位
EA=1;//开中断
}
}
}
}
void timer() interrupt 1
{
TH0=0xfc;
TL0=0x66;
count2++;
if(count2<1500)
LED2=0;
else LED2=1;
if(count2>=2000)
count2=0;
if(flag==1)
count1++;
}