单片机:按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; } } }
标签:50000,cnt,TL0,报警,TH0,单片机,K1,65536,256 来源: https://www.cnblogs.com/xkdn/p/15085392.html