|
;***********************************************************
org 000h ;定义程序存放区域的起始地址
goto main
org 0004h
bcf pir1,0
bcf t1con,0
movlw tmr1lb
movwf tmr1l
movlw tmr1hb
movwf tmr1h
bsf t1con,0
comf r1
btfsc r1,0
bsf adcon0,2
retfie
main nop
bsf status,5
movlw 0x00
movwf trisd
movlw 0x01
movwf trisa
bsf pie1,0
movlw 0x0e
movwf adcon1
bcf status,5 ;恢复到文件寄存器体0
clrf decimal
clrf hundred
clrf thousand
clrf r0
movlw 0x0
movwf porta
movwf portd
movlw 0x34
movwf t1con
movlw 0xc0
movwf intcon
movlw tmr1lb
movwf tmr1l
movlw tmr1hb
movwf tmr1h
bsf t1con,0
movlw 0x41
movwf adcon0
start nop
call display
call ad_conversion
goto start
;******************************************
;*************ad conversion value*************
ad_conversion
btfsc adcon0,2
goto exit
movf adresh,0
movwf ad_value
clrf decimal
clrf hundred
clrf thousand
clrf r0
clrf r
;*********************************************
movf ad_value,0
sublw ad_4v
btfsc status,0
goto next
movlw 0x04
movwf thousand
movlw ad_4v
subwf ad_value,1
btfsc status,2
goto exit
goto result
;**********************************************
next movf ad_value,0
sublw ad_3v
btfsc status,0
goto next0
movlw 0x03
movwf thousand
movlw ad_3v
subwf ad_value,1
btfsc status,2
goto exit
goto result
;*********************************************
next0 movf ad_value,0
sublw ad_2v
btfsc status,0
goto next1
incf thousand
incf thousand
movlw ad_2v
subwf ad_value,1
btfsc status,2
goto exit
goto result
;*********************************************
next1 movf ad_value,0
sublw ad_1v
btfsc status,0
goto result
incf thousand
movlw ad_1v
subwf ad_value,1
btfsc status,2
goto exit
goto result
;*********************************
result clrf status
result0 movlw 0x02
addwf decimal,1
decfsz ad_value,1
btfsc status,2
goto result0
;*********************************
movf decimal,0
movwf r0
lp_deci movf r0,0
movwf decimal
movlw 0x0a
subwf r0,1
btfsc status,0
goto exit
incf hundred
goto lp_deci
;*****************************************
exit nop
return
;******************************************
; Display
;******************************************
display
movf decimal,0
call numb
movwf portd
movlw 0x08
movwf porta
call delay
;******************************************
movf hundred,0
call numb
movwf portd
movlw 0x10
movwf porta
call delay
;******************************************
movf thousand,0
call numb
movwf portd
movlw 0x20
movwf porta
call delay
return
;******************************************
; Delay
;******************************************
delay
movlw 0xff
movwf 71h
lp1 decfsz 71h,1
goto lp1
return
;******************************************
; Table
;******************************************
numb addwf pcl,1
retlw 0x3f
retlw 0x06
retlw 0x5b
retlw 0x4f
retlw 0x66
retlw 0x6d
retlw 0x7d
retlw 0x07
retlw 0x7f
retlw 0x6f
end
|
|