实验六蜂鸣器报警显示实验一、实验内容一旦有报警信号产生,电路中蜂鸣器将鸣叫报警,同时旋转灯显示。二、实验目的1.巩固Proteus软件和keil软件的使用方法;2.学习外部中断技术的基本使用方法;3.学习定时器T0,T1的使用方法;4.学习中断处理程序的编程方法。三、实验电路及连线XTAL218XTAL119ALE30EA31PSEN29RST9P0.0/AD039P0.1/AD138P0.2/AD237P0.3/AD336P0.4/AD435P0.5/AD534P0.6/AD633P0.7/AD732P1.01P1.12P1.23P1.34P1.45P1.56P1.67P1.78P3.0/RXD10P3.1/TXD11P3.2/INT012P3.3/INT113P3.4/T014P3.7/RD17P3.6/WR16P3.5/T115P2.7/A1528P2.0/A821P2.1/A922P2.2/A1023P2.3/A1124P2.4/A1225P2.5/A1326P2.6/A1427U1AT89C51LS2SOUNDER报警开启/关闭C122pFC222pFC310uFX112MR110kD1R2280D2R3280D3R4280D4R5280D5R6280D6R7280D7R8280D8R92801234567812345687四、程序流程图五、实验代码#includereg52.h#includeintrins.h#defineuintunsignedint#defineucharunsignedcharsbitSPK=P3^7;ucharFRQ=0x00;voidDelayms(uintms){uchari;开始延时定时器、中断初始化FRQ++主程序流程图开始启动定时器T0、T1初始化旋转灯NY中断取消关闭定时器T0、T1中断返回外部中断0中断服务程序流程图开始中断返回TH0=0xfeTL0=FRQSPK取反T0中断服务程序流程图开始中断返回TH1=(65536-45000)/256TL1=(65536-45000)%256P2循环移位T1中断服务程序流程图while(ms--){for(i=0;i120;i++);}}voidmain(){P2=0x00;TMOD=0x11;TH0=0x00;TL0=0xff;TH1=(65536-45000)/256;TL1=(65536-45000)%256;IT0=1;IE=0x8b;IP=0x01;TR0=0;TR1=0;while(1){FRQ++;Delayms(1);}}voidEX0_INT()interrupt0{TR0=!TR0;TR1=!TR1;if(P2==0x00)P2=0xe0;elseP2=0x00;}voidT0_INT()interrupt1{TH0=0xfe;TL0=FRQ;SPK=~SPK;}voidT1_INT()interrupt3{TH1=(65536-45000)/256;TL1=(65536-45000)%256;P2=_crol_(P2,1);}六、实验现象及结果分析