from Oliver Broad [obroad at TELINCO.CO.UK] Oliver Broad says
The following program is based on the binary to BCD code from the microchip appnote. The method seems odd at first, compared to the more conventional divide-by-10-and-output-the-remainder.
It was originally written to convert data from an AD7714 sigma delta ADC; Looping version of Binary to BCD converter for 24 bit values ; Code is designed for MPSIM testing, so insert stimuli on ports ; B and B and B, and read out R0,R1,R2,R3. ; Code is based on the fact that a bcd number may be multiplied ; by two by a simple bit shift followed by a BCD fixup. The ; fixup is greatly simplified by performing it BEFORE the shift, ; which is why 3 and 30H are used instead of 6 and 60H. LIST P=16C73 INCLUDE P16C73.INC CBLOCK 20H R3,R2,R1,R0 ;MUST START ON BINARY XXXXX000. COUNT, LBYTE, MBYTE, HBYTE ENDC ORG 0 MAIN MOVFW PORTB MOVWF LBYTE MOVFW PORTB MOVWF MBYTE MOVFW PORTB MOVWF HBYTE CALL BIN2BCD GOTO MAIN BIN2BCD MOVLW 18H MOVWF COUNT CLRF R0 CLRF R1 CLRF R2 CLRF R3 BCF STATUS,C GOTO BIN2BC2 BIN2L MOVLW R3 MOVWF FSR BCDADJ MOVLW 03H ADDWF INDF,F BTFSS INDF,3 SUBWF INDF,F MOVLW 30H ADDWF INDF,F BTFSS INDF,7 SUBWF INDF,F INCF FSR,F BTFSS FSR,2 GOTO BCDADJ BIN2BC2 RLF LBYTE,F RLF MBYTE,F RLF HBYTE,F RLF R3,F RLF R2,F RLF R1,F RLF R0,F DECFSZ COUNT,F GOTO BIN2L RETLW 0 END
|file: /Techref/microchip/math/radix/b2bp-24b8d-ob.htm, 2KB, , updated: 2005/1/9 14:17, local time: 2017/11/19 02:17,
|©2017 These pages are served without commercial sponsorship. (No popup ads, etc...).Bandwidth abuse increases hosting cost forcing sponsorship or shutdown. This server aggressively defends against automated copying for any reason including offline viewing, duplication, etc... Please respect this requirement and DO NOT RIP THIS SITE. Questions?|
<A HREF="http://www.piclist.com/techref/microchip/math/radix/b2bp-24b8d-ob.htm"> PIC Microcontoller Radix Math Method </A>
|Did you find what you needed?|
PICList 2017 contributors:
o List host: MIT, Site host massmind.org, Top posters @20171119 RussellMc, Van Horn, David, James Cameron, Sean Breheny, alan.b.pearce, IVP, Neil, David C Brown, Bob Blick, Denny Esterline,
* Page Editors: James Newton, David Cary, and YOU!
* Roman Black of Black Robotics donates from sales of Linistep stepper controller kits.
* Ashley Roll of Digital Nemesis donates from sales of RCL-1 RS232 to TTL converters.
* Monthly Subscribers: Gregg Rew. on-going support is MOST appreciated!
* Contributors: Richard Seriani, Sr.
Welcome to www.piclist.com!