资源描述:
《单片机外部中断处理(模拟交通灯).doc》由会员上传分享,免费在线阅读,更多相关内容在应用文档-天天文库。
1、;**********************************************; MCS-51系列单片机仿真实验系统 硬件实验项目; 外部中断处理(急救车与交通灯实验);**********************************************Flashequ0;LED状态STOPequ1SYequP1.0;南北黄灯SGequP1.1;南北绿灯SRequP1.2;南北红灯EYequP1.3;东西黄灯EGequP1.4;东西绿灯ERequP1.5;东西红灯org0l
2、jmpStartorg3setbSTOP;南北、东西均红灯retiStart:movSP,#70movTCON,#01h;下降沿,IT0movIE,#81h;EA允许,EX0clrSR;南北红灯亮setbSY;南北黄灯灭setbSG;南北绿灯灭clrER;东西红灯亮setbEY;东西黄灯灭setbEG;东西绿灯灭clrSTOPLoop:jbSTOP,AllRedclrSR;南北红灯,东西绿灯setbSYsetbSGsetbERsetbEYclrEGmova,#60callDelayjbSTOP,A
3、llRedclrSR;南北红灯,东西黄灯闪setbSYsetbSGsetbERsetbEYsetbEGclrFlashmovr7,#20Loop1:movc,FlashmovEY,cmova,#1callDelaycplFlashdjnzr7,Loop1jbSTOP,AllRedsetbSR;南北绿灯,东西红灯setbSYclrSGclrERsetbEYsetbEGmova,#60callDelayjbSTOP,AllRedsetbSR;东西红灯,南北黄灯闪setbSYsetbSGclrERset
4、bEYsetbEGclrFlashmovr7,#20Loop2:movc,FlashmovSY,cmova,#1callDelaycplFlashdjnzr7,Loop2ljmpLoopAllRed:;两个方向交通信号灯全红clrSRsetbSYsetbSGclrERsetbEYsetbEGclrSTOPmova,#50callDelayljmpLoopDelay:;延时子程序movr1,#8fHmovr0,#80DelayLoop:jbSTOP,ExitDelaydjnzr0,DelayLoop
5、djnzr1,DelayLoopdjnzACC,DelayExitDelay:retEnd;**********数据区传送子程序*************ORG07B0HMOVR2,40HMOVR3,40HMOVR4,1E00HMOVR5,1E0FHMOVR6,#1FFFHMOVR7,#1FFFHSE22:MOVDPL,R3MOVDPH,R2;建立源程序首址MOVXA,@DPTR;取数MOVDPL,R5MOVDPH,R4;目的地首址MOVX@DPTR,A;传送CJNER3,#0FFH,LO42IN
6、CR2LO42:INCR3;源地址加1CJNER5,#0FFH,LO43INCR4LO43:INCR5;目地址加1CJNER7,#00H,LO44CJNER6,#00H,LO45;字节数减1SJMP$NOPLO44:DECR7SJMPSE22LO45:DECR7DECR6SJMPSE22;未完继续END;**************多分支程序***************ORG0A10HMEMS:MOVA,20HMOVDPTR,#KKKK;散转首址RLA;(20)*2JMP@A+DPTR;转到(2
7、0)*2+DPTRKKKK:AJMPMEMSP0AJMPMEMSP1AJMPMEMSP2SJMPMEMSP3MEMSP0:MOV20H,#0C0H;0字循环LJMPSOX0MEMSP1:MOV20H,#0F9H;1字循环LJMPSOX0MEMSP2:MOV20H,#0A4H;2字循环LJMPSOX0MEMSP3:MOV20H,#0B0H;3字循环LJMPSOX0;---------------------------------------------SOX0:MOVA,20HMOVR0,#0DC
8、HMOVR1,#0DDHMOVX@R0,AMOVA,#01HSOX1:MOVX@R1,AMOVR2,#20HLCALLDELYRLA;显示子程序SJMPSOX1;---------------------------------------------DELY:PUSH02HDEL2:PUSH02HDEL3:PUSH02H;延时DEL4:DJNZR2,DEL4POP02HDJNZR2,DEL3POP02HDJNZR2,DEL2POP02HDJNZR2,DELYRET;-------