OUTBIT equ 0e101h
CLK164 equ 0e102h ; 段控制口(接164时钟位)
DAT164 equ 0e102h ; 段控制口(接164数据位)
IN equ 0e103h ; 键盘读入口
LEDBuf equ 60h ; 显示缓冲
Num equ 70h ; 显示的数据
DelayT equ 75h
ljmp Start
LEDMAP: db 3fh, 06h, 5bh, 4fh, 66h, 6dh, 7dh,07h
db 7fh, 6fh, 77h, 7ch, 39h, 5eh, 79h,71h ; 八段管显示码
Delay: mov r7, #0 ; 延时子程序
DelayLoop: djnz r7, DelayLoop
djnz r6, DelayLoop
ret
DisplayLED: mov r0, #LEDBuf
mov r1, #6 ; 共6个八段管
mov r2, #00100000b ; 从左边开始显示
Loop: mov dptr, #OUTBIT
mov a, #00h
movx @dptr, a ; 关所有八段管
mov a, @r0
mov B, #8 ; 送164
DLP: rl a
mov r3, a
;mov acc.0 , c
ANL A, #0FDH
mov dptr, #DAT164
movx @dptr, a
mov dptr, #CLK164
orl a,#02h
movx @dptr, a
anl a,#0fDh
movx @dptr, a
mov a, r3
djnz B, DLP
mov dptr, #OUTBIT
mov a, r2
movx @dptr, a ; 显示一位八段管
mov r6, #9fh
call Delay
mov a, r2 ; 显示下一位
rr a
mov r2, a
inc r0
djnz r1, Loop
mov dptr,#OUTBIT
mov a, #0
movx @dptr, a ; 关所有八段管
ret
Start: mov dptr,#0e100h
mov a,#03h
movx @dptr,a
mov sp, #40h
mov Num, #0
MLoop: inc Num
mov a, Num
mov b, a
mov r0, #LEDBuf
FillBuf: mov a, b
anl a, #0fh
mov dptr, #LEDMap
movc a, @a+dptr ; 数字转换成显示码
mov @r0,a ; 显示在码填入显示缓冲
inc r0
inc b
cjne r0, #LEDBuf+6, FillBuf
mov DelayT,#30
DispAgain: call DisplayLED ; 显示
djnz DelayT,DispAgain
ljmp MLoop
end