chevymn1964
Full Member level 2
- Joined
- Apr 1, 2006
- Messages
- 120
- Helped
- 2
- Reputation
- 4
- Reaction score
- 0
- Trophy points
- 1,296
- Location
- Santa Rosa, Ca.
- Activity points
- 2,551
10 bit binary to 16 bit bcd
Hey Everyone! I found a routine on the web that converts 10 bit binary to 4 digit BCD But I think there is a typo because there is a goto b2d2 and the b2d2 isnt listed on the code...... Anyone have an idea where the b2d2 should go???? Any other 10bit to 4 digit bcd routines???? I'm trying to display voltage on an lcd with a pic 16f676
;======= Bin2Dec10G.asm ============= Sep 04 =========
; Test of 10b binary to 4 digit conversion as
; based on division by powers of 10.
;
; E. A., Grens
;
; For most PICs - here for 16F628 with 4 MHz
; internal oscillator.
;
; Average processor cycles for execution of
; subroutine over the input range 0x000 to 0x3FF
; is 88. No variables required except the
; input blh, blo and the out BCD digits.
; Subroutine length 38.
;======================================================
list p=16f628
radix dec
#include
__config 0x3D30
;-------Set Up RAM Variables---------------------------
blo equ 0x20 ;lsbyte of 10b binary
bhi equ 0x21 ;msb
d4 equ 0x23 ;msdigit
d3 equ 0x24
d2 equ 0x25
d1 equ 0x26 ;lsd
;-------Program Code--------------------------------
org 0x00 ;Effective Reset Vector
;
nop
goto Start ;Jump by interrupt
;
Start
movlw 0x07
movwf CMCON ;Digital I/O
movlw 0x03 ;Test input
movwf bhi
movlw 0xFF
movwf blo
movlw 0x04
call Bin2decg
Hold
goto Hold ;Finished
Bin2decg ;10b binaey to BCD
clrf d1
clrf d2
clrf d3
clrf d4
clrc
rrf bhi,f ;N = 4*Q + R
rrf blo,f ;blo = Q
rrf d1,f ;d1 = R as temp, R25
goto B2d2 ;repeat
B2d3
addwf blo,f ;get remainder
; after /100, C = 0
rlf d1,f ;*4 and add R back in
rlf blo,f
rlf d1,f
rlf blo,f ;4*blo + R = N -
; 1000*d4 - 100*d3
movlw 10
B2d4
subwf blo,f ;blo = N - 1000*d4 -
; 100*d3 - 10*d2
skpc
goto B2d5 ;blo10
goto B2d4
B2d5
addwf blo,f ;put last 10 back, C=0
movf blo,w
movwf d1
return
end
Hey Everyone! I found a routine on the web that converts 10 bit binary to 4 digit BCD But I think there is a typo because there is a goto b2d2 and the b2d2 isnt listed on the code...... Anyone have an idea where the b2d2 should go???? Any other 10bit to 4 digit bcd routines???? I'm trying to display voltage on an lcd with a pic 16f676
;======= Bin2Dec10G.asm ============= Sep 04 =========
; Test of 10b binary to 4 digit conversion as
; based on division by powers of 10.
;
; E. A., Grens
;
; For most PICs - here for 16F628 with 4 MHz
; internal oscillator.
;
; Average processor cycles for execution of
; subroutine over the input range 0x000 to 0x3FF
; is 88. No variables required except the
; input blh, blo and the out BCD digits.
; Subroutine length 38.
;======================================================
list p=16f628
radix dec
#include
__config 0x3D30
;-------Set Up RAM Variables---------------------------
blo equ 0x20 ;lsbyte of 10b binary
bhi equ 0x21 ;msb
d4 equ 0x23 ;msdigit
d3 equ 0x24
d2 equ 0x25
d1 equ 0x26 ;lsd
;-------Program Code--------------------------------
org 0x00 ;Effective Reset Vector
;
nop
goto Start ;Jump by interrupt
;
Start
movlw 0x07
movwf CMCON ;Digital I/O
movlw 0x03 ;Test input
movwf bhi
movlw 0xFF
movwf blo
movlw 0x04
call Bin2decg
Hold
goto Hold ;Finished
Bin2decg ;10b binaey to BCD
clrf d1
clrf d2
clrf d3
clrf d4
clrc
rrf bhi,f ;N = 4*Q + R
rrf blo,f ;blo = Q
rrf d1,f ;d1 = R as temp, R25
goto B2d2 ;repeat
B2d3
addwf blo,f ;get remainder
; after /100, C = 0
rlf d1,f ;*4 and add R back in
rlf blo,f
rlf d1,f
rlf blo,f ;4*blo + R = N -
; 1000*d4 - 100*d3
movlw 10
B2d4
subwf blo,f ;blo = N - 1000*d4 -
; 100*d3 - 10*d2
skpc
goto B2d5 ;blo10
goto B2d4
B2d5
addwf blo,f ;put last 10 back, C=0
movf blo,w
movwf d1
return
end