Searching \ for 'Binary to ASCII conversion?' in subject line. ()
Make payments with PayPal - it's fast, free and secure! Help us get a faster server
FAQ page: piclist.com/techref/index.htm?key=binary+ascii+conversion
Search entire site for: 'Binary to ASCII conversion?'.

Truncated match.
PICList Thread
'Binary to ASCII conversion?'
1998\03\14@210745 by Calvin

flavicon
face
Does anybody have an easy routine to convert a word of 8 or more bits to
ascii digits?

TIA

Calvin

1998\03\14@211526 by Richard Nowak

picon face
Use a lookup table.

Rich

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?
>
>TIA
>
>Calvin
>
>

=========================================
= Abolish the Income Tax! Fire the IRS! =
= http://www.nrst.org/                  =
=========================================

1998\03\15@082233 by Andy Kunz

flavicon
face
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!
==================================================================

1998\03\15@160358 by Calvin

flavicon
face
Would you be able to provide a sample of this?

Calvin

-----Original Message-----
From: Richard Nowak <spam_OUTnowakTakeThisOuTspamEARTHLINK.NET>
To: .....PICLISTKILLspamspam@spam@MITVMA.MIT.EDU <PICLISTspamKILLspamMITVMA.MIT.EDU>
Date: S‡bado 14 de Marzo de 1998 8:09 PM
Subject: Re: Binary to ASCII conversion?


{Quote hidden}

1998\03\16@065005 by Ron Kreymborg

flavicon
face
Calvin,

You might like to look at

http://www.shm.monash.edu.au/~r.kreymorg/pic/micro.html

It shows a signed, 16-bit binary to ascii converter that I use a lot. It's
not elegant and at 65 bytes, not short, but it works.

Ron

On Sat, 14 Mar 1998, Calvin wrote:

> Does anybody have an easy routine to convert a word of 8 or more bits to
> ascii digits?
>
> TIA
>
> Calvin
>

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Ron Kreymborg                   Computer Systems Manager
Monash University               CRC for Southern Hemisphere Meteorology
Wellington Road
Clayton, VIC 3168               Phone     : 061-3-9905-9671
Australia                       Fax       : 061-3-9905-9689
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

1998\03\16@065018 by Richard Nowak

picon face
oops! I was hoping to slide on this one -- up late etc.
I misread your request to mean convert binary to HEX which I'm sure you know
how to do.
First converting to BCD then to ascii as in HI-TECH's solution posted by
Andy is probably the most straight forward way of doing it.

Rich

BTW: Thanks to the list for not beating me up over my post.

At 03:04 PM 3/15/98 -0600, you wrote:
>Would you be able to provide a sample of this?
>
>Calvin
>
>{Original Message removed}

1998\03\16@072150 by Mark Lezama

flavicon
face
part 0 478 bytes content-type:text/x-vcard; charset=us-ascii; name="vcard.vcf" (decoded 7bit)

Mark Lezama

Calvin escribis:

> Does anybody have an easy routine to convert a word of 8 or more bits to
> ascii digits?
>
> TIA
>
> Calvin



Content-Type: text/x-vcard; charset=us-ascii; name="vcard.vcf"
Content-Transfer-Encoding: 7bit
Content-Description: Tarjeta de Mark  Lezama
Content-Disposition: attachment; filename="vcard.vcf"

Attachment converted: wonderland:vcard.vcf (TEXT/CSOm) (0001507B)

1998\03\16@183129 by Ron Kreymborg

flavicon
face
Oops! that should be:

http://www.shm.monash.edu.au/~r.kreymborg/pic/micro.html

Can't even spell my own name!

Ron

On Mon, 16 Mar 1998, Calvin wrote:

> This URL does not exist, is it correct?
>
> Calvin
> {Original Message removed}

More... (looser matching)
- Last day of these posts
- In 1998 , 1999 only
- Today
- New search...