Re: How to convert 10bit ADC data to BCD?
- From: "Anthony Fremont" <spam@xxxxxxxxxxxx>
- Date: Tue, 18 Apr 2006 14:10:11 GMT
"sommes" <jlj@xxxxxx> wrote in message
news:4444e343$0$16690$5a62ac22@xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
How to convert a 10bit digitial signal to three groups of BCD?BCD?
For example, the value of 10bit digitial is 789 in decimal.
I would like to ask how to take 7, 8, 9 away and convert each digi to
7-segment
p.s. BCD is needed to display a 7-segment display via "BCD to
display converter" 74LS48
I am going to use BASIC with Atmel AT90S8535 to do the task.
Thank you very much
This is for a PIC, but it should be possible to translate it since it's
not that complex. It converts a 16 bit unsigned binary value to 5
packed (two digits per byte) BCD digits. binH and binL contain the 16
bit binary value. count and temp are single byte work areas.
binary_to_bcd
bcf STATUS, 0 ; clear the carry bit
movlw .16
movwf count
clrf tenthousands
clrf thousands_and_hundreds
clrf tens_and_ones
loop16
rlf binL, F
rlf binH, F
rlf tens_and_ones, F
rlf thousands_and_hundreds, F
rlf tenthousands, F
;
decfsz count, F
goto adjDEC
RETLW 0
;
adjDEC
movlw tens_and_ones
movwf FSR
call adjBCD
;
movlw thousands_and_hundreds
movwf FSR
call adjBCD
;
movlw tenthousands
movwf FSR
call adjBCD
;
goto loop16
;
adjBCD
movlw 3
addwf INDF,W
movwf temp
btfsc temp,3 ; test if result > 7
movwf INDF
movlw 0x30
addwf INDF,W
movwf temp
btfsc temp,7 ; test if result > 7
movwf INDF ; save as MSD
RETLW 0
.
- References:
- How to convert 10bit ADC data to BCD?
- From: sommes
- How to convert 10bit ADC data to BCD?
- Prev by Date: Re: Recommended capacitors for AF circuits
- Next by Date: Re: Unregulated frequencies
- Previous by thread: How to convert 10bit ADC data to BCD?
- Next by thread: Re: How to convert 10bit ADC data to BCD?
- Index(es):
Relevant Pages
|