27,382
社区成员
发帖
与我相关
我的任务
分享
#include"reg51.h"
sbit beep=P1^5;
int num=0;
void main(){
TMOD=0x01;
TH1=(65536-50000)/256;
TL1=(65536-50000)%256;
EA=1;
ET0=1; //你一打开定时器0他就会开始计时,只不过开始第一次的中断的时间比较久,是从TH0跟
TR0=1; //TL0都等于0开始,直到产生中断进入中断服务程序
while(1);}
void beeper() interrupt 1{
TH0=(65536-50000)/256;
TL0=(65536-50000)%256;
if(++num==20){
beep=~beep;
num=0;}
}