交通灯模拟实验程序
GEWEI EQU 21H ;个位数据
SHIWEI EQU 23H ;十位数据
SCANLED EQU 25H
SCANMODE EQU 26H
RED EQU 28H ;定义灯的缓冲区
GREEN EQU 29H
YELLOW EQU 32H
NUMTIM EQU 33H
LED EQU 34H
ORG 000H
JMP START
ORG 0BH
JMP TIMER0 ;定时器0中断入口
ORG 100H
START: MOV SP,#50H
MOV R0,#20H
MOV R5,#20
CLR0: MOV @R0,#00H
INC R0
DJNZ R5,CLR0
MOV TMOD,#01H ;设置定时器
MOV TH0,#HIGH(65536-5000)
MOV TL0,#LOW(65536-5000)
SETB TR0
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:PUSH ACC ;定时器部分,负责交通灯的及时和数码管动态扫描
PUSH PSW
MOV TH0,#HIGH(65536-5000) ;重新赋初值
MOV TL0,#LOW(65536-5000)
DJNZ R7,RET0
MOV R7,#200
MOV A,SCANMODE ;调用扫描
MOV B,#4
DIV AB
MOV A,B
RL A
MOV DPTR,#TAB_SCAN
JMP @A+DPTR
TAB_SCAN: AJMP RED_LIGHT
AJMP YEL_LIGHT
AJMP GRE_LIGHT
AJMP YEL_LIGHT
RET0: MOV A,NUMTIM
LCALL BIN_BCD
MOV SHIWEI,A
MOV GEWEI,B
INC SCANLED
MOV A,SCANLED
MOV B,#4
DIV AB
MOV A,B
RL A
MOV DPTR,#TAB_SCAN0
JMP @A+DPTR
TAB_SCAN0:AJMP SCAN_L1
AJMP SCAN_L2
SCAN_L1: MOV P2,#11111011B
MOV A,SHIWEI
JMP END_SCAN
SCAN_L2: MOV P2,#11111101B
MOV A,GEWEI
JMP END_SCAN
END_SCAN: MOV DPTR,#TABLE
MOV C A,@A+DPTR
MOV P0,A
MOV A,LED
MOV P1,A
POP PSW
POP ACC
RETI
RED_LIGHT: MOV LED,#11111100B
MOV NUMTIM,RED
DEC RED
MOV A,RED
CJNE A,#0FFH,RET0
MOV RED,#10
MOV A,SCANMODE
ADD A,#01H
MOV SCANMODE,A
JMP RET0
YEL_LIGHT: MOV LED,#11110011B
MOV NUMTIM,YELLOW
DEC YELLOW
MOV A,YELLOW
CJNE A,#0FFH,RET0
MOV YELLOW,#3
MOV A,SCANMODE
ADD A,#01H
MOV SCANMODE,A
JMP RET0
GRE_LIGHT: MOV LED,#11001111B
MOV NUMTIM,GREEN
DEC GREEN
MOV A,GREEN
CJNE A,#0FFH,RET1
MOV GREEN,#10
MOV A,SCANMODE
ADD A,#01H
MOV SCANMODE,A
RET1:JMP RET0
BIN_BCD: MOV B,#10
DIV AB
RET
DELAY: MOV R5,#02
D1: MOV R6,#200
D2: MOV R7,#200
DJNZ R7,$
DJNZ R6,D2
DJNZ R5,D1
RET
TABLE:DB 0C0H,0F9H,0A4H,0B0H,99H,92H,82H,0F8H,80H,90H ;共阳字码表
END
上一篇:12864显示屏4*4键盘实验
下一篇:键控门铃程序
推荐阅读最新更新时间:2024-03-16 15:52