注p0口为东西红灯\x0d\x0a; p1口为东西黄灯\x0d\x0a;p2口为东西绿灯\x0d\x0a;p3南北红灯\x0d\x0a;p4南北黄灯\x0d\x0a;p5南北绿灯\x0d\x0a\x0d\x0a;绿灯停留3s;黄灯闪烁5次,每次0.2s,红的停留4s \x0d\x0aORG 0000H\x0d\x0a LJMP MAIN\x0d\x0a ORG 0030H\x0d\x0aMAIN:MOV DPTR,#B1\x0d\x0a MOV R2,#4\x0d\x0a MOV A,#0H\x0d\x0aF3:MOV R1,A\x0d\x0a MOVC A,@A+DPTR\x0d\x0a JNB ACC.4,SS1 ;判断东西方向黄灯是否亮,若亮则转移到黄灯闪烁程序\x0d\x0a JNB ACC.1,SS2 ;判断南北方向黄灯是否亮,若亮则转移到黄灯闪烁程序\x0d\x0a MOV P1,A\x0d\x0a LCALL DY1S\x0d\x0aSS:MOV A,R1\x0d\x0a INC A\x0d\x0a DJNZ R2,F3\x0d\x0a SJMP MAIN\x0d\x0a\x0d\x0aSS1:MOV R0,#10\x0d\x0aXH1:CPL ACC.4\x0d\x0a MOV P1,A\x0d\x0a LCALL DYS\x0d\x0a DJNZ R0,XH1\x0d\x0a SJMP SS\x0d\x0aSS2:MOV R0,#10\x0d\x0aXH2:CPL ACC.1\x0d\x0a MOV P1,A\x0d\x0a LCALL DYS\x0d\x0a DJNZ R0,XH2\x0d\x0a SJMP SS\x0d\x0a\x0d\x0aDY1S:MOV R5,#30\x0d\x0aDLP0:MOV R6,#100\x0d\x0aDLP1:MOV R7,#250 ;F=6MHZ\x0d\x0aDLP2:DJNZ R7,DLP2 ;2X250X2uS=1ms\x0d\x0a DJNZ R6,DLP1 ;1x100=0.1S\x0d\x0a DJNZ R5,DLP0 ;0.1X30=3s\x0d\x0a RET\x0d\x0a\x0d\x0aDYS:MOV R6,#200\x0d\x0aDLP3:MOV R7,#250 ;F=6MHZ\x0d\x0aDLP4:DJNZ R7,DLP4 ;2X250X1uS=500us=1ms\x0d\x0a DJNZ R6,DLP3 ;1x200=0.2S\x0d\x0a RET\x0d\x0aB1: DB 11011110B,11101110B,11110011B,11110101B\x0d\x0a END
温馨提示:答案为网友推荐,仅供参考