交通燈模擬實驗程序
交通燈模擬實驗程序
GEWEIEQU21H;個位數據
SHIWEIEQU23H;十位數據
SCANLEDEQU25H
SCANMODEEQU26H
REDEQU28H;定義燈的緩沖區(qū)
GREENEQU29H
YELLOWEQU32H
NUMTIMEQU33H
LEDEQU34H
ORG000H
JMPSTART
ORG0BH
JMPTIMER0;定時器0中斷入口
ORG100H
START: MOV SP,#50H
MOV R0,#20H
MOV R5,#20
CLR0: MOV @R0,#00H
INCR0
DJNZR5,CLR0
MOV TMOD,#01H;設置定時器
MOV TH0,#HIGH(65536-5000)
MOV TL0,#LOW(65536-5000)
SETBTR0
MOV IE,#10000010B;端口初始化
MOV P0,#0FFH
MOV P1,#0FFH
MOV P2,#00H
MOV P3,#0FFH
MOV R3,#10
MOV R2,#3
MOV R1,#10
MOV R7,#200
MOV RED,#10
MOV YELLOW,#3
MOV GREEN,#10
MOV NUMTIM,#10
MOV LED,#0FFH
AJMP$
;=============================================================
TIMER0:PUSHACC;定時器部分,負責交通燈的及時和數碼管動態(tài)掃描
PUSHPSW
MOV TH0,#HIGH(65536-5000);重新賦初值
MOV TL0,#LOW(65536-5000)
DJNZR7,RET0
MOV R7,#200
MOV A,SCANMODE;調用掃描
MOV B,#4
DIVAB
MOV A,B
RLA
MOV DPTR,#TAB_SCAN
JMP@A+DPTR
TAB_SCAN:AJMPRED_LIGHT
AJMPYEL_LIGHT
AJMPGRE_LIGHT
AJMPYEL_LIGHT
RET0: MOV A,NUMTIM
LCALLBIN_BCD
MOV SHIWEI,A
MOV GEWEI,B
INCSCANLED
MOV A,SCANLED
MOV B,#4
DIVAB
MOV A,B
RLA
MOV DPTR,#TAB_SCAN0
JMP@A+DPTR
TAB_SCAN0:AJMPSCAN_L1
AJMPSCAN_L2
SCAN_L1: MOV P2,#11111011B
MOV A,SHIWEI
JMPEND_SCAN
SCAN_L2: MOV P2,#11111101B
MOV A,GEWEI
JMPEND_SCAN
END_SCAN: MOV DPTR,#TABLE
MOV CA,@A+DPTR
MOV P0,A
MOV A,LED
MOV P1,A
POPPSW
POPACC
RETI
RED_LIGHT: MOV LED,#11111100B
MOV NUMTIM,RED
DECRED
MOV A,RED
CJNEA,#0FFH,RET0
MOV RED,#10
MOV A,SCANMODE
ADDA,#01H
MOV SCANMODE,A
JMPRET0
YEL_LIGHT: MOV LED,#11110011B
MOV NUMTIM,YELLOW
DECYELLOW
MOV A,YELLOW
CJNEA,#0FFH,RET0
MOV YELLOW,#3
MOV A,SCANMODE
ADDA,#01H
MOV SCANMODE,A
JMPRET0
GRE_LIGHT: MOV LED,#11001111B
MOV NUMTIM,GREEN
DECGREEN
MOV A,GREEN
CJNEA,#0FFH,RET1
MOV GREEN,#10
MOV A,SCANMODE
ADDA,#01H
MOV SCANMODE,A
RET1:JMPRET0
BIN_BCD: MOV B,#10
DIVAB
RET
DELAY: MOV R5,#02
D1: MOV R6,#200
D2: MOV R7,#200
DJNZR7,$
DJNZR6,D2
DJNZR5,D1
RET
TABLE:DB0C0H,0F9H,0A4H,0B0H,99H,92H,82H,0F8H,80H,90H;共陽字碼表
END