单片机:按K1键报警1秒

#include<reg51.h>
#define uchar unsigned char
uchar cnt;
sbit fmq=P2^5;
sbit key=P3^2;
void t0isr() interrupt 1
{
TH0=(65536-50000)/256;
TL0=(65536-50000)%256;
TH0=0X4C;
TL0=0X00;
cnt++;
if(cnt>20)
{
TR0=0;
cnt=0;
fmq=1;
}
}
main()
{
TMOD=0x01;
TH0=(65536-50000)/256;
TL0=(65536-50000)%256;
TH0=0X4C;
TL0=0X00;
ET0=1;
EA=1;
while(1)
{
if(key==0)
{
while(key==0);
TR0=1;
fmq=0;
}
}
}

 

上一篇:【题解】AcWing 1390.通电围栏


下一篇:【翻译】寻找重串与 Main-Lorentz 算法