#include <reg52.h> #define uchar unsigned char #define uint unsigned int int seccnt,m=0; char tzsta,msta; sbit led=P2^0; sbit beep=P1^5; void ini()//定时器0 { seccnt=0; msta=tzsta=0; TMOD=0x01; TH0=0x0FF; TL0=0x9C; TR0=1; } void on()//蜂鸣器和灯的功能 { if(m<=500) { beep=~beep; } if(m>=10000) { led = ~led; m=0; } } void main() { ini(); while(1) { while(TF0==0); TL0=0x9C; TH0=0x0FF; TF0=0; m=m+1; on(); } }