📄 main.asm
字号:
disnum0 equ 20h ;数码管第一位
disnum1 equ 21h ;数码管第二位
disnum2 equ 22h ;数码管第三位
disnum3 equ 23h ;数码管第四位
disnum4 equ 24h ;数码管第五位
disnum5 equ 25h ;数码管第六位
disnum6 equ 26h ;数码管第七位
disnum7 equ 27h ;数码管第八位
diswords equ 29h ;数码管正在显示的位
lednum equ 2ah ;流水灯正在显示的模式
shanshuo equ 2bh ;数码管闪烁位
shannum0 equ 2ch ;数码管闪烁等待次数
shannum1 equ 2dh
shannum2 equ 2eh ;数码管闪烁位应显示的数
lsdnum equ 2fh ;流水灯控制字传送位
wen0du equ 30h
wendu equ 31h
wendua equ 33h
wendub equ 34h
org 0000h
jmp start
org 000bh
jmp intn0
org 001bh
jmp intn1
org 0100h
start:
mov sp,#60h
call rep_8255
call rep_disled
call rep_main
mov disnum0,#01h
mov disnum1,#0bh
mov disnum2,#0bh
mov shanshuo,#00h
main:
jb p1.2,p14
jnb p1.2,$
call delay ;消除抖动
jnb p1.2,$
clr tr1
;inc disnum0
;mov a,disnum0
;cjne a,#05h,p14
;mov disnum0,#01h
call changenum1
setb tr1
p14:
jb p3.2,p35
jnb p3.2,$
call delay ;消除抖动
jnb p3.2,$
clr tr1
;dec disnum0
;mov a,disnum0
;cjne a,#00h,p35
;mov disnum0,#04
call changenum2
setb tr1
p35:
jb p3.5,main
jnb p3.5,$
call delay ;消除抖动
jnb p3.5,$
clr tr1
inc shanshuo
mov a,shanshuo
cjne a,#08h,p350
mov shanshuo,#00h
mov a,disnum0
p350:
mov a,disnum0
cjne a,#01h,p351
;jmp lsd
setb tr1
jmp main
p351:
mov a,disnum0
cjne a,#02h,p352
;jmp singing
setb tr1
jmp main
p352:
mov a,disnum0
cjne a,#03h,p353
setb tr1
mov shanshuo,#08h
jmp cewen
p353:
setb tr1
jmp main
;jmp settime
changenum1:
mov a,shanshuo
add a,#20h
mov r1,a
inc @r1
mov a,@r1
cjne a,#12h,changenum3
mov @r1,#00h
ret
changenum2:
mov a,shanshuo
add a,#20h
mov r1,a
dec @r1
mov a,@r1
cjne a,#0FFh,changenum3
mov @r1,#11h
ret
changenum3:
ret
delay:
mov r7,#0ffh
mov r6,#0ffh
dely:
djnz r7,dely
mov r7,#0ffh
djnz r6,dely
ret
;---------------------------------------------------------------------
rep_8255:
mov dptr,#0bfffh ;8255控制字为#80h
mov a,#80h ;8255A口地址为8fffh
movx @dptr,a ;8255B口地址为9fffh
mov dptr,#8fffh ;8255C口地址为0afffh
mov a,#0ffh
movx @dptr,a
mov dptr,#9fffh
movx @dptr,a
mov dptr,#0afffh
movx @dptr,a
setb p1.4
setb p1.5
setb p1.6
setb p1.7
ret
rep_disled:
mov disnum0,#0bh ;初始显示HELLO
mov disnum1,#0bh
mov disnum2,#0bh
mov disnum3,#00h
mov disnum4,#11h
mov disnum5,#11h
mov disnum6,#0eh
mov disnum7,#10h
mov shanshuo,#08h
mov shannum0,#00h
mov shannum1,#00h
mov shannum2,#00h
mov lsdnum,#00h
ret
rep_main: ;定时器1,计数器0初始化
mov tmod,#16h
mov th0,#0ah ;有待更正
mov tl0,#0ah ;有待更正
mov th1,#0f7h ;有待更正
mov tl1,#00h ;有待更正
mov a,#0e0h
orl a,tcon
mov tcon,a
setb ea
setb et1
setb et0
setb tr1 ;开定时器1
clr tr0 ;关计数器0
ret
;-------------------------------------------------------------------------
intn0:
reti
intn1: ;数码管显示
clr tr1
push acc
clr c ;清除标致位,不然算的数不对
mov a,diswords
subb a,shanshuo
cjne a,#00h,intn12 ;到没到要闪烁的位
mov a,shannum0
cjne a,#015h,intn11 ;不显示次数到没到
inc shannum1
mov a,shannum1
cjne a,#015h,intn12 ;显示次数到没到
mov shannum0,#00h
mov shannum1,#00h
intn11:
inc shannum0
mov dptr,#9fffh
mov a,#00h
movx @dptr,a
jmp intn13
intn12:
call disled
intn13:
inc diswords
mov a,diswords
cjne a,#08h,intn14
mov diswords,#00h
;cpl p1.3
intn14:
pop acc
mov th1,#0f7h
mov tl1,#00h
setb tr1
reti
disled: ;取控制字并显示
mov dptr,#9fffh
mov a,#00h
movx @dptr,a
mov a,diswords
add a,#20h
mov r1,a
mov dptr,#tab_discoun
mov a,@r1
movc a,@a+dptr
mov dptr,#8fffh
movx @dptr,a
mov dptr,#tab_diswords
mov a,diswords
movc a,@a+dptr
mov dptr,#9fffh
movx @dptr,a
ret
tab_discoun:
db 3fh,06h,5bh,4fh,66h,6dh,7dh,07h,7fh,6fh,77h,00h,50h,5ch,79h,73h,76h,38h
; 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, a, , o, r, E, p, H, L
tab_diswords:
db 80h,40h,20h,10h,08h,04h,02h,01h
end
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -