Searching \ for '[PIC] fixed point to ASCII on 16F87x?' 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/microchip/devices.htm?key=16F
Search entire site for: 'fixed point to ASCII on 16F87x?'.

Exact match. Not showing close matches.
PICList Thread
'[PIC] fixed point to ASCII on 16F87x?'
2002\12\31@155916 by Matt Parker

flavicon
face
Is there a routine available which will convert an integer (8- or 16-bit)
value to a series of ASCII values for the PIC16F87x?  There doesn't appear
to be a Microchip Application Note on it.

The best I've been able to do so far is convert it to a float (with the
floating point library) and then use AN670 to convert the float to ASCII.
Surely there's a better way?


matt

--
http://www.piclist.com#nomail Going offline? Don't AutoReply us!
email spam_OUTlistservTakeThisOuTspammitvma.mit.edu with SET PICList DIGEST in the body

2002\12\31@160912 by Spehro Pefhany

picon face
At 03:57 PM 12/31/02 -0500, you wrote:
>Is there a routine available which will convert an integer (8- or 16-bit)
>value to a series of ASCII values for the PIC16F87x?  There doesn't appear
>to be a Microchip Application Note on it.
>
>The best I've been able to do so far is convert it to a float (with the
>floating point library) and then use AN670 to convert the float to ASCII.
>Surely there's a better way?

Convert it to BCD and then the conversion to ASCII is trivial-
add '0' - the ASCII character for zero- to each BCD digit.

Best regards,

Spehro Pefhany --"it's the network..."            "The Journey is the reward"
.....speffKILLspamspam@spam@interlog.com             Info for manufacturers: http://www.trexon.com
Embedded software/hardware/analog  Info for designers:  http://www.speff.com

--
http://www.piclist.com#nomail Going offline? Don't AutoReply us!
email listservspamKILLspammitvma.mit.edu with SET PICList DIGEST in the body


'[PIC] fixed point to ASCII on 16F87x?'
2003\01\01@101131 by robert lang
flavicon
face
I've been using this assembler code to convert 8 bits integers to ascii for LCD
; LOOKUP DATA TABLES
DECIMAL_TO_ASCII ADDWF   PCL, F   ; THESE ARE THE 10 DECIMAL DIGITS                        RETLW   '0'
           RETLW   '1'
           RETLW   '2'
           RETLW   '3'
           RETLW   '4'
           RETLW   '5'
           RETLW   '6'
           RETLW   '7'
           RETLW   '8'
           RETLW   '9' ; --------------------------------------------------
;THIS ROUTINE COVERTS A HEXADECIMAL NUMBER 0-FF
;TO AN ASCII STRING "000" TO "255"
; --------------------------------------------------
WRITE_DECIMAL   MOVF  ARG1,W      ; MOVE ARG1 TO W
               MOVWF TEMP2        ; MOVE W TO TEMP2 REG ; DO HUNDREDS
               CLRF     HUNDREDS  ; CLEAR THE HUNDREDS
               MOVLW    D'100'    ; STORE 100 IN W
LOOP100         SUBWF    TEMP2,F   ; BEGIN LOOP TO DETERMINE HUNDREDS
               SKPC  ; IF W IS NEGATIVE OR ZERO THEN HUNDRED IS CALCULATED
               GOTO TOOFAR100
               SKPNZ
               GOTO INCR100
               INCF     HUNDREDS,F   ; OTHERWISE INCREASE HUNDRED COUNT
               GOTO LOOP100
INCR100     INCF     HUNDREDS,F   ; IF TEMP2 IS 100 THEN WE SHOULD ADD ONE HUNDRED
               GOTO DISPLAY_HUNDREDS
TOOFAR100       MOVLW D'100'
               ADDWF TEMP2,F  DISPLAY_HUNDREDS  MOVF HUNDREDS,W       ;  OFFSET TO DIGIT OFHUNDRED
               CALL DECIMAL_TO_ASCII   ; GO THERE AND RETURN WITH W CONTAINING                                     ; ASCII EQUIVALENT OF HUNDRED NUMBER
               MOVWF ARG1          ; PUT IN ARG1
               CALL SENDLCDDATA    ; AND DISPLAY HUNDRED NUMBER
; DO TENS                 CLRF     TENS  ; CLEAR THE TENS
               MOVLW    D'10'    ; STORE 10 IN W
LOOP10          SUBWF    TEMP2,F   ; BEGIN LOOP TO DETERMINE TENS
               SKPC  ; IF W IS NEGATIVE OR ZERO THEN 10 IS CALCULATED
               GOTO TOOFAR10
               SKPNZ
               GOTO INCR10
               INCF     TENS,F   ; OTHERWISE INCREASE HUNDRED COUNT
               GOTO LOOP10
INCR10          INCF     TENS,F   ; IF TEMP2 IS 100 THEN WE SHOULD ADD ONE HUNDRED
               GOTO DISPLAY_TENS
TOOFAR10        MOVLW D'10'
               ADDWF TEMP2,F  DISPLAY_TENS    MOVF TENS,W       ;  OFFSET TO DIGIT OF TENS
               CALL DECIMAL_TO_ASCII   ; GO THERE AND RETURN WITH W CONTAINING                                     ; ASCII EQUIVALENT OF TEN NUMBER
               MOVWF ARG1          ; PUT IN ARG1
               CALL SENDLCDDATA    ; AND DISPLAY TEN NUMBER
; DO UNITS
               MOVF TEMP2,W     ; LOAD TEMP2 OFFSET (UNITS)
               CALL DECIMAL_TO_ASCII ; GO THERE AND RETURN WITH W CONTAINING                                   ; ASCII EQUIVALENT OF TEMP2
               MOVWF ARG1          ; PUT IN ARG1
               CALL SENDLCDDATA    ; AND DISPLAY 0-9
              RETURN


{Original Message removed}

2003\01\01@104804 by Bob Ammerman

picon face
; Here is a simplified version of the code.

; (untested and unoptimized)


; Subroutine to convert the 8 bit value 0..FF in W and display it on the LCD
;  On entry:
;        W is value to output

write_decimal:
                   movwf    temp2            ;save value to be output
                   movlw    100
                   call         dodigit
                   movlw    10
                   call         dodigit
                   movf      temp2,w
                   movwf    arg1
;                   call          sendlcddata    (note: we can replace a
call followed by
;                   return                             a return with a goto)
                   goto        sendlcddata

; Subroutine to generate one digit of the result and send it to the LCD:
;   On entry:
;    TEMP2 is the remaining value to output.
;    W is value of current digit, will be 100 or 10.

dodigit:
                  movwf    temp3
                  movlw    '0'                  ; init resulting digit to
'0'
                  movwf    arg1
loopdigit:
                  movf       temp3,w       ; get the 10 or 100
                  subwf      temp2,w        ; do the subtract, result in W
                  skpnc                           ; did the subtract work?
                  goto         sendlcddata  ; no, display the digit and
return
                  incf          arg1,f            ; increase the digit
value
                  movwf     temp2           ; store updated value in TEMP2
                  goto         loopdigit

Bob Ammerman
RAm Systems

--
http://www.piclist.com hint: To leave the PICList
.....piclist-unsubscribe-requestKILLspamspam.....mitvma.mit.edu>

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