📄 traffic.asm
字号:
#include ht48c10-1.inc
;-------------------------------------------------------
data .section 'data' ;== data section ==
count1 db ? ;delay loop counter 1
count2 db ? ;delay loop counter 2
count3 db ? ;delay loop counter 3
flash db ? ;light flash register
rglight db ? ;light register
;-------------------------------------------------------
code .section at 0 'code' ;== program section ==
org 00H ;
jmp start ;
org 04h ;external interrupt subroutine
reti ;for guarantee
org 08h ;timer/event 0 interrupt subroutine
reti ;for guarantee
org 0ch ;timer/event 1 interrupt subroutine
reti ;for guarantee
start: ;
clr intc ;initialize registers
clr tmrc ;to guarantee performance
clr tmr ;(interrupts)
set pac ;(ports)
set pbc ;(input mode)
set pcc ;
main:
mov a,0 ;(1) ;
mov pac,a ;set port A to output port
mov pa,a ;zero port A (all light on)
loop: ;light loop
mov a,0 ;;load table-read pointer
mov tblp,a ;;
tabrdl rglight ;(2) ;load light state by looking up table
mov a,rglight ;(3) ;;output light state to port A
mov pa,a ;;
call delayl ;(4) ;delay for a 'long' while
inc tblp ;(5) ;
mov a,7 ;load flash counter
mov flash,a ;
flash1: ;flash1 loop
tabrdl rglight ;load light state
mov a,rglight ;;
mov pa,a ;;output light state to port A
call delays ;(6) ;delay for a 'little' while
inc tblp ;
sdz flash ;if flash light over?
jmp flash1 ;no. flash again
tabrdl rglight ;(yes. go ahead) load light state
mov a,rglight ;;output light state to port A
mov pa,a ;;
call delaym ;(7) ;delay for a 'medium' while
inc tblp ;
;--------------------------------;
tabrdl rglight ;load light state
mov a,rglight ;;output light state to port A
mov pa,a ;;
call delayl ;delay for a 'long' while
inc tblp ;
mov a,7 ;;load flash counter
mov flash,a ;;
flash2: ;flash2 loop
tabrdl rglight ;load light state
mov a,rglight ;;output light state to port A
mov pa,a ;
call delays ;delay for a 'little' while
inc tblp ;
sdz flash ;if flash light over?
jmp flash2 ;no. flash again
tabrdl rglight ;(yes. go ahead) load light state
mov a,rglight ;;output light state to port A
mov pa,a ;;
call delaym ;delay for a 'medium' while
jmp loop ;repeat from light loop
delayl proc ;'long' delay subroutine
mov a,0fh ;;load counters
mov count1,a ;;
mov count2,a ;;
mov count3,a ;;
d1:
sdz count3 ;;count down count3
jmp d1
sdz count2 ;;count down count2
jmp d1
sdz count1 ;;count down count1
jmp d1
ret
delayl endp
delaym proc ;'medium' delay subroutine
mov a,07h ;;load counters
mov count1,a ;;
mov a,0ffh ;;
mov count2,a ;;
mov count3,a ;;
d2:
sdz count3 ;;count down count3
jmp d2
sdz count2 ;;count down count2
jmp d2
sdz count1 ;;count down count1
jmp d2
ret
delaym endp
delays proc ;'little' delay subroutine
mov a,0ffh ;;load counters
mov count1,a ;;
mov count2,a ;;
d3:
sdz count2 ;;count down count2
jmp d3
sdz count1 ;;count down count1
jmp d3
ret
delays endp
org 300h ;TABLE
; RYG RYG
dc 0EBh ;1110 1011 G R
dc 0FBh ;1111 1011 O R
dc 0EBh ;1110 1011 G R
dc 0FBh ;1111 1011 O R
dc 0EBh ;1110 1011 G R
dc 0FBh ;1111 1011 O R
dc 0EBh ;1110 1011 G R
dc 0FBh ;1111 1011 O R
dc 0DBh ;1101 1011 Y R
dc 0BEh ;1011 1110 R G
dc 0BFh ;1011 1111 R O
dc 0BEh ;1011 1110 R G
dc 0BFh ;1011 1111 R O
dc 0BEh ;1011 1110 R G
dc 0BFh ;1011 1111 R O
dc 0BEh ;1011 1110 R G
dc 0BFh ;1011 1111 R O
dc 0BDh ;1011 1101 R Y
end
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -