实验四、中断实验报告一、实验内容参照实验电路,设计交通灯控制系统。模拟交通信号灯控制:一般情况下正常显示,东西-南北交替放行,各方向通行时间为30秒。有救护车或警车到达时,两个方向交通信号灯全为红色,以便让急救车或警车通过,设通行时间为10秒,之后交通恢复正常。用单次脉冲模拟急救车或警车申请外部中断。二、程序流程图3实验仿真电路ABCDEFGABCDEFGD0D1D2D3D4D5D6D0D1D2D3D4D5D6R1Y1G1R2Y2G2Y2G2R2Y1G1R1XTAL218XTAL119ALE30EA31PSEN29RST9P0.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/A1427U1AT89C5123456781RP1RESPACK-7+5V+5VR110k中华人民共和国雄起!制作者:徐宏明4、实验程序ORG0000HJMPMAINORG0003H;外部中断0的入口地址JMPX0_INTORG000BH;T0中断的入口地址JMPT0_INT;***************************************MAIN:MOVTMOD,#01HMOVTH0,#3CHMOVTL0,#0B0HMOVR1,#20;定时1sSETBTR0SETBET0SETBPT0SETBEX0SETBIT0SETBEAMOVSP,#60HM_LOOP:;***************************************N_B:MOV30H,#11H;南北MOVP1,30HMOVR5,#30;CALLDISPLAYMOVR2,#27LOOP1:CALLWAIT_1SDJNZR2,LOOP1;判断是否过了27s;--------------------------MOV30H,#21HMOVP1,30HMOVR2,#3LOOP11:CALLWAIT_1SDJNZR2,LOOP11;判断是否过了3秒;***************************************D_X:MOV30H,#0AH;东西MOVP1,30HMOVR5,#30CALLDISPLAYMOVR2,#27LOOP2:CALLWAIT_1SDJNZR2,LOOP2;判断是否过了27s;--------------------------MOV30H,#0CHMOVP1,30HMOVR2,#3LOOP22:CALLWAIT_1SDJNZR2,LOOP22;判断是否过了3秒JMPM_LOOP;***************************************WAIT_1S:;等待新秒出现JNB20H.0,$CLR20H.0DECR5CALLDISPLAYRET;-----------------------------DISPLAY:MOVA,R5MOVB,#10DIVABMOVDPTR,#TAB1MOVCA,@A+DPTRMOVP2,AMOVA,BMOVDPTR,#TAB1MOVCA,@A+DPTRMOVP0,ARETTAB1:DB3FH,06H,5BH,4FH,66H,6DH,7DH,07H,7FH,6FH;***************************************X0_INT:MOVP1,#09H;全部红灯PUSHACCPUSHBPUSHPSWSETBRS0;换工作区MOVR5,#10;倒计时显示CALLDISPLAYMOVR1,#20;定时1s;----------------MOVR2,#10;倒计时LOOP3:CALLWAIT_1SDJNZR2,LOOP3;判断是否到了10s;----------------POPPSW;恢复原区CALLDISPLAY;显示原值MOVP1,30H;显示原灯POPBPOPACCRETI;-----------------------------T0_INT:;T0中断,高优先级MOVTL0,#0B0HMOVTH0,#3CH;50ms中断一次DJNZR1,EXIT_T0MOVR1,#20;定时1sSETB20H.0;每到一秒就置一EXIT_T0:RETI;***************************************END