At 08:04 PM 3/14/98 -0600, you wrote: >Does anybody have an easy routine to convert a word of 8 or more bits to >ascii digits? This is what I use. It's in the format of the HiTech assembly which comes with HiTech PICC. It could be linked right into your C program. After it is the C routine which calls it. ; Command Line: ; ; ASPIC -V bin2bcd.as ; global ?_Bin2BCD global ?a_Bin2BCD global _Bin2BCD signat _Bin2BCD,4216 FNSIZE _Bin2BCD,2,2 global _Decimal global clear_bank0 processor 16C74A psect text0,local,class=CODE,delta=2 psect text1,local,class=CODE,delta=2 psect rbss_0,global,class=BANK0,space=1 INDF equ 0 INDIRECT equ 0 TMR0 equ 1 PCL equ 2 STATUS equ 3 FSR equ 4 _C equ 0 _DC equ 1 _Z equ 2 _PD equ 3 _TO equ 4 _RP0 equ 5 _RP1 equ 6 _IRP equ 7 psect text0 file "BIN2BCD.AS" _Bin2BCD ; _bitcntr assigned to ?a_Bin2BCD+0 ; _work assigned to ?a_Bin2BCD+1 ;BIN2BCD.C: 8: unsigned char bitcntr, ;BIN2BCD.C: 9: work; bcf STATUS,_RP0 clrf (?a_Bin2BCD+1) ; BIN2BCD.C: 11: work = 0; movlw 16 ; BIN2BCD.C: 12: bitcntr = 16; movwf ?a_Bin2BCD clrf (_Decimal+0) ; BIN2BCD.C: 13: Decimal[0] = 0; clrf (_Decimal+1) ; BIN2BCD.C: 14: Decimal[1] = 0; clrf (_Decimal+2) ; BIN2BCD.C: 15: Decimal[2] = 0; clrf (_Decimal+3) ; BIN2BCD.C: 16: Decimal[3] = 0; clrf (_Decimal+4) ; BIN2BCD.C: 17: Decimal[4] = 0; clrf (_Decimal+5) ; BIN2BCD.C: 18: Decimal[5] = 0; ;LSB movwf ?_Bin2BCD ;BIN2BCD.C: 20: Binary = 0x1234; ;MSB movwf (?_Bin2BCD+1) bcf STATUS,_C ; clear carry bit first loop16: rlf ?_Bin2BCD,F rlf (?_Bin2BCD+1),F rlf (_Decimal+5),F rlf (_Decimal+4),F rlf (_Decimal+3),F decfsz ?a_Bin2BCD,F goto AdjustDEC movf (_Decimal+3),W ; Unpack BCD andlw 0x0f iorlw '0' movwf (_Decimal+0) swapf (_Decimal+4),W andlw 0x0f iorlw '0' movwf (_Decimal+1) movf (_Decimal+4),W andlw 0x0f iorlw '0' movwf (_Decimal+2) swapf (_Decimal+5),W andlw 0x0f iorlw '0' movwf (_Decimal+3) movf (_Decimal+5),W andlw 0x0f iorlw '0' movwf (_Decimal+4) clrf (_Decimal+5) ; Marks end of C string return ; Return to original caller AdjustDEC: movlw (_Decimal+5) movwf FSR ; Save in FSR call AdjustBCD movlw (_Decimal+4) movwf FSR call AdjustBCD movlw (_Decimal+3) movwf FSR call AdjustBCD goto loop16 AdjustBCD: movlw 3 ; enter with FSR pointing addwf INDIRECT,W ; to the BCD digit being shifted movwf (?a_Bin2BCD+1) btfsc (?a_Bin2BCD+1),3 movwf INDIRECT ; save in INDIRECT movlw 0x30 addwf INDIRECT,W movwf (?a_Bin2BCD+1) btfsc (?a_Bin2BCD+1),7 movwf INDIRECT return psect text1 psect rbss_0 _Decimal ds 6 // From the C file: extern char // Defined in BIN2BCD.AS Decimal[6]; extern void Bin2BCD (int value); // Defined in BIN2BCD.AS void Blank_Leading_Zeros (void) // Removes leading zeros from Decimal[] { static bit work; byte i; work = TRUE; i = 0; while (work) { if (Decimal[i] == '0') Decimal[i++] = ' '; else work = FALSE; if (i == 4) work = FALSE; if (PowerFailing) work = FALSE; } } void SayDecimal (int value) // Equivalent function to printf ("%d",v alue); { Bin2BCD (value); Blank_Leading_Zeros (); printf (Decimal); } ================================================================== Andy Kunz - Montana Design Go fast, turn right, and keep the wet side down! ==================================================================