Re: How to convert 10bit ADC data to BCD?




"sommes" <jlj@xxxxxx> wrote in message
news:4444e343$0$16690$5a62ac22@xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
How to convert a 10bit digitial signal to three groups of 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
BCD?

p.s. BCD is needed to display a 7-segment display via "BCD to
7-segment
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

.



Relevant Pages

  • Re: PIC a/d puzzler
    ... rlf binL, F ... movlw tens_and_ones ... movwf FSR ... call adjBCD ...
    (sci.electronics.basics)
  • Pic Eusart behaviour
    ... I know the timer is working by scoping the A1 pin. ... config XINST = OFF ... movwf TRISA ... movlw 0xFF; make PORTB all input ...
    (sci.electronics.basics)
  • Re: KeyPad Lock made from a 16F84A trouble
    ... A key pad combination controlled lock. ... > STATUS equ 03h ... > movlw 01h ... > movwf NUM1 ...
    (sci.electronics.design)
  • PIC18f4331 PWM Problem
    ... observing the output from an oscillator, some pins do not produce the ... MOVLW 0x00 ... MOVWF TRISA ... movwf OVDCONS ...
    (sci.electronics.design)
  • PIC 18F4550 - EUSART does not generate interrupts
    ... movwf TRISC,ACCESS ... movlw low ... bsf PIE1,RCIE,ACCESS ... that PIC doesn't call the interrupt routine. ...
    (comp.arch.embedded)