关于定时/计数/蜂鸣器基本运用

T1计数(10次)工作方式2(可自动重载初值),T0定时工作方式1(一次/50ms),外部输入端P3.5

#include<reg51.h>
sbit fm = P1^0;
sbit led = P1^7;
void fmjishi(unsigned int a){
	while(a--);
}
void fming(unsigned int a,unsigned int b,unsigned int e){
	while(b--){
		e = ~e;
		fm = e;
		fmjishi(a);
	}
}
void jishi(unsigned int a,unsigned int b){//定时
	 while(a--){
	 	TH0 = (65536 - 50000)/256;//单次50ms
		TL0	= (65536 - 50000)%256;
		TR0 = 1;
		if(b!=0){
	   		fming(5,10,1);
	   		fming(15,25,0);
		}
		while(!TF0);
		TF0 = 0;
	 }
}
void jishu(unsigned int a){//计数
	TH1 = 256 - a;
	TL1 = 256 - a;
	TR1 = 1;
	while(1){
		while(!TF1);
		TF1 = 0;
		break;
	}
}
void main(){
	unsigned int a=3; 
	TMOD = 0x61;
	jishu(10);//计数十次
	while(a--){
		 led = 0;
	   	jishi(60,a);//60*50
	   	led = 1;
	   	jishi(30,a);//30*50
	}
}

led闪烁-蜂鸣器警报