piclist 2003\01\01\101131a >
Thread: fixed point to ASCII on 16F87x?
www.piclist.com/techref/microchip/devices.htm?key=16F
flavicon
face BY : robert lang email (remove spam text)



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}
<000a01c2b1a7$11a6e400$7cd194d0@dell> quoted-printable

See also: www.piclist.com/techref/microchip/devices.htm?key=16F
Reply You must be a member of the piclist mailing list (not only a www.piclist.com member) to post to the piclist. This form requires JavaScript and a browser/email client that can handle form mailto: posts.
Subject (change) fixed point to ASCII on 16F87x?

month overview.

new search...