帮忙看一下汇编写的交通灯程序,帮忙挑错。谢谢各位大侠
时间:10-02
整理:3721RD
点击:
;==========定义符号===============
GREEN BIT P0.7 ;绿色灯
YELLOW BIT P1.0
RED BIT P2.7
DY_CK BIT P1.5
DG_CK BIT P1.6
DR_CK BIT P1.7
WORK0_0 EQU 23H
TIMECOU EQU 22H ;用于计数
;---------------------------------
;----------入口地址---------------
ORG 0000H
LJMP MAIN
ORG 000BH ;定时器0入口
LJMP T0_S
;------定时器0初始化子程序--------
T0_INIT:
MOV TMOD,#01H
MOV TH0,#03CH
MOV TL0,#0B0H
SETB TR0
SETB ET0
SETB EA
RET
;==========主程序=================
MAIN:
;----------初始化-----------------
MOV SP,#2FH
CALL T0_INIT
MOV P0,0FFH
MOV P1,0FFH
MOV P2,0FFH
;---------取倒计时时间------------
DE9:
ANL P3,#03CH
CJNE P3,#0,DE10
LJMP DAO9
DE10:
ANL P3,#03CH
CJNE P3,#004H,DE25
LJMP DAO10
DE25:
ANL P3,#03CH
CJNE P3,#008H,DE36
LJMP DAO25
DE36:
ANL P3,#03CH
CJNE P3,#00CH,DE48
LJMP DAO36
DE48:
ANL P3,#03CH
CJNE P3,#010H,DE74
LJMP DAO48
DE74:
ANL P3,#03CH
CJNE P3,#18H,DE86
LJMP DAO74
DE86:
ANL P3,#03CH
CJNE P3,#01CH,DE98
LJMP DAO86
DE98:
ANL P3,#03CH
CJNE P3,#020H,DE180
LJMP DAO98
DE180:
ANL P3,#03CH
CJNE P3,#03CH,DE9
LJMP DAO180
DAO9:
MOV A,#9
LJMP WORK0_0
DAO10:
MOV A,#10
LJMP WORK0_0
DAO25:
MOV A,#25
LJMP WORK0_0
DAO36:
MOV A,#36
LJMP WORK0_0
DAO48:
MOV A,#48
LJMP WORK0_0
DAO74:
MOV A,#74
LJMP WORK0_0
DAO86:
MOV A,#86
LJMP WORK0_0
DAO98:
MOV A,#98
LJMP WORK0_0
DAO180:
MOV A,#180
LJMP WORK0_0
;-------检测红绿黄哪路来电---------
SCANRGY:
JNB DY_CK,DISY
JNB DR_CK,DISR
JNB DG_CK,DISG
;------------赋值显示-------------
WORK0_0:
MOV B,#10
div AB
ANL A,#00001111B
MOV DPTR,#TAB
MOVC A,@A+DPTR
MOV P2,A
ANL B,#11110000B
MOV DPTR,#TAB
MOVC B,@B+DPTR
MOV P0,B
;---点亮对应颜色灯,并进入倒计时---
DISR:
CLR RED
LCALL WORK0_0
LCALL T0_S
DJNZ A,WORK0_0
LJMP MAIN
DISG:
CLR GREEN
LCALL WORK0_0
LCALL T0_S
DJNZ A,WORK0_0
LJMP MAIN
DISY:
CLR YELLOW
LCALL T0_S
LCALL T0_S
LCALL T0_S
LJMP MAIN
;------中断服务子程序1秒延时------
T0_S:
MOV TH0,#03CH
MOV TL0,#0B0H
PUSH ACC
PUSH PSW
MOV TIMECON,#20
DEC TIMECON
DJNZ TIMECON,#0,RES
RES:
POP PSW
POP ACC
RETI
;---------延时1秒子程序-----------
;DELAY_2:MOV R5,#10
;DEL2_01:MOV R6,#200
;DEL2_02:MOV R7,#250
;DEL2_03:DJNZ R7,DEL2_03
; DJNZ R6,DEL2_02
; DJNZ R5,DEL2_01
; RET
;=============显示字表============
TAB: DB 081H,0B7H,0C2H,092H,0B4H,098H,088H,0B3H,080H,090H
END ;程序结束