OUTBIT   equ 0e101h  ; 位控制口
        CLK164   equ 0e102h  ; 段控制口(接164时钟位)
        DAT164   equ 0e102h  ; 段控制口(接164数据位)
        IN       equ 0e103h  ; 键盘读入口
        LEDBuf   equ   40h   ; 显示缓冲
        org 0000h
	    mov sp,#60h
	    mov dptr,#0e100h     ;8155初始化
	    mov a,#03h
        movx @dptr,a
	    mov 40h,#10h         ;显示缓冲器初始化
	    mov 41h,#11h
	    mov 42h,#11h
	    mov 43h,#11h
        mov 44h,#00h
        mov 45h,#00h
LOOP1:  mov  r4,#2 
vip:    lcall DISPLAY
        djnz r4,vip
	     mov a,#00h
	     mov dptr,#0a000h     ;0809AD的通道开始转换吗?
	     movx @dptr,a
	     mov r7,#02h
loop2:	 djnz r7,loop2
	     movx a,@dptr
         mov r0,#45h           ;拆字
	     lcall ptds
	     sjmp loop1
ptds:	 mov r1,a
	    lcall ptds1
	    mov a,r1
	    swap a
ptds1:  anl a,#0fh
	    mov @r0,a
	    dec r0
	    ret
Delay:  mov   r7, #0          ; 延时子程序
DelayLoop:
           djnz  r7, DelayLoop
           djnz  r6, DelayLoop
           ret
DISPLAY:  setb 0d3h
          mov   r0, #LEDBuf
          mov   r1, #6          ; 共6个八段管
          mov   r2, #00100000b  ; 从左边开始显示
Loop:
        mov   dptr, #OUTBIT
        mov   a, #00h
        movx  @dptr, a        ; 关所有八段管
        mov   a, @r0
        mov dptr,#LEDmap
        movc a,@a+dptr
        mov   B, #8           ; 送164
DLP:
        rlc   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, #1
        call  Delay
        mov   a, r2           ; 显示下一位
        rr    a
        mov   r2, a
        inc   r0
        djnz  r1, Loop
        mov   dptr, #OUTBIT
        mov   a, #0
        movx  @dptr, a
        clr 0d3h        ; 关所有八段管
        ret
LEDMAP:                       ; 八段管显示码
        db    3fh, 06h, 5bh, 4fh, 66h, 6dh, 7dh, 07h
        db    7fh, 6fh, 77h, 7ch, 39h, 5eh, 79h, 71h
        db    0f6H,40H
	    end
