/*******16 bit Binary to 5 decimal place conversion*****************************
**
** Heavily based on Peter Hemsley's High Speed Binary to Decimal For PICs
** article published in EPE magazine September 2004.
** The original ASM code and explanations for this file can be downloaded from
** www.epemag.wimbourne.co.uk.
** From the download page look in Pic Tools folder
**
**Assembler instructions such as rlf have been used as the XCSB equivalent
**optimises the Carry register by automatically clearing it when code such as
** temp = temp << 1 or temp = temp * 2 is used.
** 84 asm (including the ascii conversion) instructions used compared to the
** original 46 asm instructions.
**Code space used 108 words
**Code size 84 instructions
**Ram space 11 bytes
XCSB 1.8.1 Pro
Copyright C D Barnard DATE 9/01/2005
*******************************************************************************/
int number
ubyte splitH
ubyte splitL
ubyte temp
ubyte tthou
ubyte thou
ubyte hund
ubyte tens
ubyte units
ubyte ASCII_flag
proc bin2dec_5(uint number, ubyte flag)
//Break 16 bit number into two byte size chunks
splitH = number >> 8
splitL = number
units = splitH | 0xF0
tens = units
tens = tens + tens + tens
hund = units
asm_start
rlf hund,F
asm_end
splitH = splitH >>4
splitH = splitH | 0xF0
hund = hund + splitH
thou = splitH
thou = thou + splitH
units = units + (splitH + 52)
temp = (splitL >>4)
temp = temp | 0xF0
tens = tens + temp
units = units + temp
asm_start
rlf units,F
comf units,F
rlf units,F
asm_end
units = units + (splitL & 0x0F)
asm_start
rlf Tens,F
asm_end
tthou = 7
asm_start
addlw 3
rlf thou,F
asm_end
/*******************************************************************************
********************************************************************************
**There are two choices of using the code below.
**The assembler version
**Which takes 8 instructions less than the basic version, can be uncommented if
**program space and speed is of paramount importance.
**The basic version generates an extra two "goto's" per test of STATUS
*******************************************************************************/
//Basic version. This is a sort of do...while or do.....until loop
while (1) do
asm_start
LSD //Least Significant Digit
addwf units,F
decf tens,F
asm_end
if (STATUS & (1<