我也做了一个,有紧急情况处理
;交通灯 ORG 0000H LJMP BEGIN ORG 0100H BEGIN: AJMP MAIN ORG 0013H AJMP INT_1 MAIN: MOV SP,#60H MOV TMOD,#01H ;定时器工作方式 SETB IT1 ;中断设置,外部中断1 SETB EX1 SETB EA MOV DPTR,#TAB EW_R BIT P1.0 EW_Y BIT P1.1 EW_G BIT P1.2 SN_R BIT P1.3 SN_Y BIT P1.4 SN_G BIT P1.5 ;--------起始-------- MOV P1,#0FFH CLR EW_R CLR SN_R ACALL DEALY1 ;-------1----------- LOOP: MOV P1,#0FFH CLR EW_R CLR SN_G MOV R1,#10 ;延时10s ACALL DISP MOV R2,#5 ;绿灯闪5次 LOOP0: CPL SN_G ACALL DEALY0 DJNZ R2,LOOP0 CLR SN_Y ACALL DEALY1 ;--------2-------- MOV P1,#0FFH CLR EW_G CLR SN_R MOV R1,#10 ;延时10S ACALL DISP MOV R2,#5 LOOP1: CPL EW_G ACALL DEALY0 DJNZ R2,LOOP1 CLR EW_Y ACALL DEALY1 SJMP LOOP ;-------延时子程序--------- DEALY0: MOV R0,#10 ;延时为500ms SJMP TIMER DEALY1: MOV R0,#20 ;延时为1s TIMER: MOV TH0,#3CH MOV TL0,#0B0H SETB TR0 **: JNB TF0,$ DJNZ R0,NEXT SJMP STOP NEXT: MOV TH0,#3CH MOV TL0,#0B0H JBC TF0,** STOP: NOP RET ;---------显示程序----------------- DISP: NOP LOOPD: MOV A,R1 MOVC A,@A+DPTR MOV P0,A ACALL DEALY1 DJNZ R1,LOOPD MOV A,R1 MOVC A,@A+DPTR MOV P0,A ACALL DEALY1 RET ;---------紧急情况------------- ;-----------现场保护---------- INT_1: MOV 30H,TCON MOV 31H,TL0 MOV 32H,TH0 MOV 33H,R0 MOV 34H,R1 MOV 35H,R2 MOV 36H,P1 MOV 37H,A ;----------中断服务程序----------- CLR EA MOV P1,#0FFH CLR EW_R CLR SN_R MOV R1,#10 ACALL DISP MOV R2,#5 LOOP2: CPL EW_R CPL SN_R ACALL DEALY0 DJNZ R2,LOOP2 ;-----------恢复现场---------------- SETB EA MOV TCON,30H MOV TL0,31H MOV TH0,32H MOV R0,33H MOV R1,34H MOV R2,35H MOV P1,36H MOV A,37H ;----------返回---------------- RETI ;----------------字形码------------- TAB: DB 82H,0E7H,91H,0C1H,0E4H,0C8H,88H,0E3H,80H,0C0H,0A0H END |
|