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

Truncated match.
PICList Thread
'help ... 3 digit ascii from 8 bit binary'
1997\05\04@191757 by Dave Birchall

flavicon
picon face
I have an 8 bit binary value in a register and would like to turn this in
to three digits of ascii for output on a LED display.

I am using a 16c74.

I have found one possible soulution on a PIC FAQ but do not  understand
the command 'BNC'

Here is the code.

-----------------------------------------------------------------------
  LIST    R=DEC

         ASCIIO  EQU     ....    ;A FILE REGISTER.
         ASCIIT  EQU     ....    ;ANOTHER FILE REGISTER.
         ASCIIH  EQU     ....    ;ANOTHER FILE REGISTER.

    ; ENTER WITH ORIGINAL 8-BIT VALUE IN "ASCIIO".  EXITS WITH ASCII
    ; REPRESENTATION OF ONES' DIGIT IN "ASCIIO", TENS' DIGIT IN
"ASCIIT",
    ; AND HUNDREDS' DIGIT IN "ASCIIH".

    CONVRT  MOVLW   '0'
            MOVWF   ASCIIH
            MOVWF   ASCIIT

    DO100S  MOVLW   100
            SUBWF   ASCIIO,W
            BNC     DO10S

            MOVWF   ASCIIO
            INCF    ASCIIH
            GOTO    DO100S

    DO10S   MOVLW   10
            SUBWF   ASCIIO,W
            BNC     ADJUST

            MOVWF   ASCIIO
            INCF    ASCIIT
            GOTO    DO10S

    ADJUST  MOVLW   '0'
            ADDWF   ASCIIO

------------------------------------------------------------------------
If this code is incorrect please let me know.
If you know how to solve my problem your help would be much appreciated.

Thanks
Dave Birchall
Student at Loughborough University, England.
E-Mail spam_OUTd.birchall-94TakeThisOuTspamstudent.lboro.ac.uk

1997\05\05@011923 by Mike Smith

flavicon
face
----------
> From: Dave Birchall <.....D.Birchall-94KILLspamspam@spam@student.lut.AC.UK>
> To: PICLISTspamKILLspamMITVMA.MIT.EDU
> Subject: help ... 3 digit ascii from 8 bit binary
> Date: Monday, 5 May 1997 16:34
>
> I have an 8 bit binary value in a register and would like to turn this in
> to three digits of ascii for output on a LED display.
>
> I am using a 16c74.
>
> I have found one possible soulution on a PIC FAQ but do not  understand
> the command 'BNC'
>
Um, stab in the dark, but its probably a macro that means branch no carry,
which gets defined in some assemblers.  You could use the BTFSC/BTFSS
instruction on the carry bit of the status register, instead, if your asm
doesn't support it.  One of the PICLIST members put the list of these
pseudo-op/macro type instructions up about a month ago, so you could
probably retrieve it from the WWW site theat contains the piclist(?)

MikeS
<.....mikesmith_ozKILLspamspam.....relaymail.net>

1997\05\05@052450 by Mike Ghormley

flavicon
face
Dave Birchall wrote:

> I have found one possible soulution on a PIC FAQ but do not understand
> the command 'BNC'

<snip code>

I have waited but no one seemed to be answering this question or I missed it,
so here goes.

BNC is a pseudo-op which stands for Branch on Not Carry.
It will branch the code to a LABEL if the Carry Flag is NOT set.

It is used:
       BNC     LABEL

If you are counting cycles or if your assembler doesn't support it,
it compiles to:
       BTFSS   3,0     ; Test if bit 0 of Register 3 (STATUS) is set.
                       ; If set, then the next instruction is skipped.
       GOTO    LABEL   ; Thus, if the carry bit is NOT set, then this
                       ; instruction will be executed and the flow will
                       ; branch to LABEL

IMHO the code that you posted doesn't work.  It would loop forever.

I have added code that I believe will do the job.  I have denoted my code
additions it by placing "@@@" in the expanded comments.  Also be aware that some
assemblers don't like blank lines, so you might need to take them out.


;@@@ equates for the destination register for operations so that we
;@@@ can use code such as:
;@@@    SUBWF   REGISTER,w
;@@@ or
;@@@    ADDWF   REGISTER,f
       w       EQU     0       ;@@@ destination is the working register
       f       EQU     1       ;@@@ destination is the file register

; =====  START OF OLD CODE HERE  =====
; ASCIIO will hold the working number and, later, the ONEs ASCII value
       ASCIIO  EQU     xxx     ; xxx = A FILE REGISTER OF YOUR CHOOSING.
; ASCIIT will hold the TENs ASCII value
       ASCIIT  EQU     yyy     ; yyy = ANOTHER FILE REGISTER.
; ASCIIH will hold the HUNDREDs ASCII value
       ASCIIH  EQU     zzz     ; zzz = ANOTHER FILE REGISTER.

; ENTER WITH ORIGINAL 8-BIT VALUE IN "ASCIIO".
; EXITS WITH ASCII REPRESENTATION OF ONES' DIGIT IN "ASCIIO",
; TENS' DIGIT IN "ASCIIT", AND HUNDREDS' DIGIT IN "ASCIIH".


; Initialize the registers that will hold the ASCII values.  NOTE that we
; should not initialize the ASCIIO register as it holds the number.
CONVRT  MOVLW   '0'             ; this places the number 48 (decimal)
                               ; into the working register.  48 is the ASCII
                               ; representation of the character '0' (zero).
       MOVWF   ASCIIH          ; copy it into the HUNDREDs register
       MOVWF   ASCIIT          ; copy it into the TENs register

; Check if the number is greater than 99
; NOTE that the result of the subtraction is not used.  The subtraction is
; being used solely to set the Carry Flag
DO100S  MOVLW   d'100'          ; place the value 100 (decimal) into the w regis
ter
       SUBWF   ASCIIO,w        ; subtract 100 from the original number (held
                               ; in the ONEs register) and place the result
                               ; back in the working register.  If the number
                               ; less than 100, the carry flag will NOT be set.
       BNC     DO10S           ; If the carry flag is NOT set, then the
                               ; number is less than 100.  This means that
                               ; the ASCII '0' that is already there is the
                               ; correct number for the HUNDREDs digit.  The
                               ; BNC will branch past the next piece of code
                               ; to handle the TENs next.
; If the code gets here then the original number is greater than 99.
; We will increment the ASCII value in the HUNDREDs register and subtract
; 100 from the working number held in ASCIIO.
       INCF    ASCIIH,f        ; increment the number in the HUNDREDs reg.
                               ; ASCII 48 = '0', ASCII 49 = '1', etc.
       MOVLW   d'100'          ;@@@ put 100 back into the working register
       SUBWF   ASCIIO,f        ;@@@ subtract 100 from the original number but
                               ; this time place the result back into the ONEs
                               ; register. This will be the new working number.
       GOTO    DO100S          ; jump back up and repeat the 100's test.
                               ; NOTE:  Since the highest number that it is
                               ; possible to place in an 8-bit register is 255,
                               ; you needn't worry about incrementing above
                               ; the legal ASCII numeric characters.

; Here we will essentially do the same thing to the TENs register that we did
; with the HUNDREDs above.
DO10S   MOVLW   d'10'           ; place the value 10 (decimal) into the w regist
er.
       SUBWF   ASCIIO,w        ; subtract 10 from the working number (held
                               ; in the ONEs register) and place the result
                               ; back in the working register.  If the number
                               ; less than 10, the carry flag will NOT be set.
       BNC     DO1S            ; If the carry flag is NOT set, then the
                               ; number is less than 10.  This means that
                               ; the ASCII '0' (48 decimal) is the correct
                               ; number for the TENs digit.  The BNC will
                               ; branch past the next piece of code to handle
                               ; the ONEs next.
; If the code gets here, the tens digit isn't zero
       INCF    ASCIIT,f        ; Increment the number in the TENs register.
                               ; ASCII 48 = '0', ASCII 49 = '1', etc.
       MOVLW   d'10'           ;@@@ put 10 back into the working register.
       SUBWF   ASCIIO,f        ;@@@ subtract 10 from the working number but
                               ; this time place the result back into the ONEs
                               ; register as the new working number.
       GOTO    DO10S           ; Jump back up and repeat the 10's test.  Each
                               ; time through we will add 1 to the ASCII value
                               ; in the TENs register, thus incrementing the
                               ; ASCII number.

; Here we can have only 0-9 in the ASCIIO register.  If we add it to an ASCII
'0'
; it should produce the last digit for us.
DO1S    MOVLW   '0'             ; move the ASCII value for zero (48 decimal) int
o
                               ; the working register.
       ADDWF   ASCIIO,f        ; add the number to get the ASCII value for it.


I hope I have not made any obvious errors, and that it will help you.

Michael

When the way of the Tao is forgotten, kindness and ethics must be taught.
Men must learn to pretend to be wise and good.  --  Lao Tzu

1997\05\05@081705 by Andrew Warren

face
flavicon
face
Dave Birchall posted a hex-to-ASCII routine that I wrote and
asked about my use of the BNC pseudo-op.

Mike Ghormley <EraseMEPICLISTspam_OUTspamTakeThisOuTMITVMA.MIT.EDU> replied:

> BNC is a pseudo-op which stands for Branch on Not Carry. It will
> branch the code to a LABEL if the Carry Flag is NOT set.

   Correct.

> IMHO the code that you posted doesn't work.  It would loop forever.

   Incorrect.

{Quote hidden}

   This is unnecessary; any assembler that understands the "BNC"
   pseudo-op also understands the "w" and "f" destination-specifiers
   without any need for them to be explicitly defined.

   Furthermore, the "improvements" you made to my code do nothing
   but make the code slower and larger.  For the sake of
   readability and brevity, I'll show just one portion of your
   version without the lengthy comments, rather than quoting the
   whole thing verbatim:

   Michael's version:
   ------------------

>   DO100S  MOVLW   d'100'
>           SUBWF   ASCIIO,w
>           BNC     DO10S
>
>           INCF    ASCIIH,f
>
>           MOVLW   d'100'
>           SUBWF   ASCIIO,f
>           GOTO    DO100S

   My original code:
   -----------------

   DO100S  MOVLW   100
           SUBWF   ASCIIO,W
           BNC     DO10S

           MOVWF   ASCIIO
           INCF    ASCIIH
           GOTO    DO100S

   Ok... If you look closely at my code, you'll see that after the
   BNC instruction, the W register ALREADY contains ASCII0-100;
   there's NO NEED to load W with 100 and do the subtraction again.

   That is, contrary to the comments you wrote for my code, the
   result of the subtraction IS used.

   -Andy

=== Andrew Warren - fastfwdspamspam_OUTix.netcom.com
=== Fast Forward Engineering, Vista, California
=== http://www.geocities.com/SiliconValley/2499

1997\05\05@103040 by n/a

flavicon
face
Dave Birchall wrote:

> I have an 8 bit binary value in a register and would like to turn
> this in
> to three digits of ascii for output on a LED display.
>
> I am using a 16c74.
>
> I have found one possible soulution on a PIC FAQ but do not
> understand
> the command 'BNC'

Dave if you could assemble this code and show the listing of the related

code we'll be able to determine if it's being compiled correctly. As a
quess I'd say that bnc might be a macro. BNC = Branch when not clear.
The
closest thing I can find is a BTFSS or BTFSC Bit Test, skip if
Set/Clear.
This will require a bunch more code to go along with it. I understand
that you want to branch to DO10S if it ASCIIO equals 0. I could not find

bnc in the Microchip Data book. So I would concure that the bnc will not

work as you asking it too. I don't know about the Parallex assembler.

--
Neil Cherry

If you need to contact me via email please use this email address to
respond:  ncherry worldnet att net
(replace spaces with '@' '.' & '.' ) Blame this one on firms like
@spam@rootKILLspamspamcyberpromo.com KILLspamwebmasterKILLspamspamcyberpromo.com RemoveMErootTakeThisOuTspamispam.net
spamBeGonegimkespamBeGonespamplasube.com TakeThisOuTsubscribeEraseMEspamspam_OUTcyberpromo.com

1997\05\06@052805 by Mike Ghormley

flavicon
face
Andrew Warren wrote:

<snip>

>    That is, contrary to the comments you wrote for my code, the
>    result of the subtraction IS used.

I stand corrected.  Your code from the FAQ would NOT loop forever.  And
it DOES appear to work as advertised.  I somehow missed the point that
the remainder is being stuffed back into ASCIIO on a carry.

My apologies,

Michael

When the way of the Tao is forgotten, kindness and ethics must be taught.
Men must learn to pretend to be wise and good.  --  Lao Tzu

1997\05\06@064914 by Andrew Warren

face
flavicon
face
Mike Ghormley <RemoveMEPICLISTspamTakeThisOuTMITVMA.MIT.EDU> wrote:

> I stand corrected.  Your code from the FAQ would NOT loop forever.
> And it DOES appear to work as advertised.  I somehow missed the
> point that the remainder is being stuffed back into ASCIIO on a
> carry.
>
> My apologies

   Thanks, Michael, but there's really no need to apologize... I
   should've put some comments in the original code.

   -Andy

=== Andrew Warren - fastfwdEraseMEspam.....ix.netcom.com
=== Fast Forward Engineering, Vista, California
=== http://www.geocities.com/SiliconValley/2499

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