Dark Equ 10
;================================ Hardware =================================
DisMode Equ 0000H ;Display Char Port
DisCS Equ 2000H ;Display CS Port
AD0809 Equ 4000H ;AD0809
;=============================== Bit Segment ===============================
SysBits0 Data 20h
GetAD0809 Bit 03H ;1o First Calc
;=============================== Byte Segment ==============================
;*byte define start*
;00H..07H : Reg Group 0
;08H..1FH : System Stack
;20H..20H : System Bit Units
;---------------------------------------------------------------------------
;21H..6EH
DisBuf Equ 70h ;..75h ;显示缓冲区
DeciP Data 76H ;Bit=1isplay Decimal Point
ADValue Data 77H ;Calc Result, Origen Code
;===========================================================================
Org 0000h
AJmp Main
;============================= Subroutines =================================
Display: Mov R0,#DisBuf ;R0->DisBuf
Mov R1,#00000001B ;R1=Dis CS
DisplayLp: Mov a,R1 ;Send CS first, Proteus ask to do so
Mov dptr,#DisCS ;Send CS to DisCS Port
Movx @Dptr,a
Mov B,#11111111b
Anl A,DeciP
Jz DisplayNxt
Mov B,#01111111B
DisplayNxt:Mov a,R1 ;Send CS first, Proteus ask to do so
Rl A ;Next CS
Mov R1,A
Mov A,@r0 ;Get Dis Char
Inc R0 ;Next Buf
Mov Dptr,#DisTab ;Change to Dis Mode
Movc A,@A+Dptr
Anl A,B
Mov Dptr,#DisMode ;Send DisMode to DisMode Port
Movx @Dptr,a
ACall Delay
Cjne R0,#DisBuf+6,DisPlayLp
; Mov a,#0 ;Send CS first, Proteus ask to do so
; Mov dptr,#DisCS ;Send CS to DisCS Port
; Movx @Dptr,a
Ret
;---------------------------------------------------------------------------
DisTab: DB 0c0H ; 0
DB 0F9H ; 1
DB 0A4H ; 2
DB 0B0H ; 3
DB 099H ; 4
DB 092H ; 5
DB 082H ; 6
DB 0F8H ; 7
DB 080H ; 8
DB 090H ; 9
DB 0FFH ; A
;--------------------------------------------------------------------------
ClrDis: Mov A,#Dark
AToDis: Mov r0,#DisBuf
AToR06: Mov R1,#6
AToRoLp: Mov @r0,A ;A->@R0,Num=R1
Inc r0
Djnz R1,AToRoLp
Ret
;--------------------------------------------------------------------------
InitDis: ACall ClrDis
Mov DisBuf+0,#0
Mov DeciP,#00000000b
Ret
;--------------------------------------------------------------------------
Delay: Mov r6,#4 ;8*256*2*T(1us)=8*512=4000us=2ms
Delay1: Mov r7,#0
Djnz r7,$ ;2
Djnz r6,Delay1
Ret
;--------------------------------------------------------------------------
;Change A into Decimal BCD Code
AHexToBCD: Mov B,#10
Div AB
Mov @R0,B
Inc r0
Mov B,#10
Div AB
Mov @r0,B
Inc r0
Mov @r0,A
Inc r0
Ret
;--------------------------------------------------------------------------
InitAD0809:Clr GetAD0809
Ret
;--------------------------------------------------------------------------
GetAD: Mov Dptr,#AD0809+0
Movx @Dptr,A ;Start AD, Chennel=0
; ACall Display ;Delay
ACall Delay
ACall Delay
Mov Dptr,#AD0809+0
Movx A,@Dptr
Mov ADValue,A
Setb GetAD0809
Ret
;================================= Main ====================================
Main: Mov Sp,#07h ;init Stack
ACall InitDis
ACall InitAD0809
MainLoop: ACall Display
ACall GetAD
JBC GetAD0809,ShowAD
AJmp MainLoop
;--------------------------------------------------------------------------
ShowAD: Mov A,ADValue
Mov R0,#DisBuf
ACall AHexToBCD
AJmp MainLoop
;==========================================================================
end