PIC18f ASCII

Discussion in 'Programmer's Corner' started by Dritech, Jan 25, 2012.

  1. Dritech

    Thread Starter Well-Known Member

    Sep 21, 2011
    756
    5
    Hi all,

    I am using an ADC to display temperature on an LCD.(using assembly).

    Can someone help me in separating a two character number and convert each character to ASCII ??

    For example if the temperature is 25°C, separate 2 from 5 and convert them to ASCII (i.e. 00110010, 00110101)

    Thanks.
     
  2. t06afre

    AAC Fanatic!

    May 11, 2009
    5,939
    1,222
    What is your data material before conversion. Is it just a raw number from the ADC? That first need to be scaled and then converted to ASCII
     
  3. Markd77

    Senior Member

    Sep 7, 2009
    2,803
    594
  4. Dritech

    Thread Starter Well-Known Member

    Sep 21, 2011
    756
    5
    Hi.
    Thanks for the replies.

    The input of the ADC will be from a PT1000 which is connected to an OP-AMP. The ADC is set to increment 1 bit for every degree (i.e. 1 degree = 00000001... 2 degree= 00000010 etc). Now i need to convert the mentioned output binary to ASCII. From 1 to 9 degree its no problem since all i have to do is add 48 to it, but when the value is with two digits (ex. 25degree) i have to separate 2 and add 48 to it and the same with 5.

    I will read the tutorials which Markd77 gave and see if i manage to make it work.

    Thanks.
     
  5. Dritech

    Thread Starter Well-Known Member

    Sep 21, 2011
    756
    5
    Hi, thanks again Markd77. I managed to make it work with the help from the link you gave me.

    The only problem is that i cannot understand how the binary is being converted to ASCII. Can someone explain the conversion routine (coding below) with comments please? I would appreciate it a lot.

    Thanks in advance.

    Code ( (Unknown Language)):
    1. BIN2BCD
    2.  
    3. ;---------------------
    4.  
    5.  
    6. ;in: BIN
    7. ;out huns. tens, ones
    8.  
    9. ;uses ADD-3 algoerthm
    10.  
    11. movlw 8
    12. movwf count
    13. clrf huns
    14. clrf tens
    15. clrf ones
    16.  
    17. BCDADD3
    18.  
    19. movlw 5
    20. subwf huns, 0
    21. btfsc STATUS, C
    22. CALL ADD3HUNS
    23.  
    24. movlw 5
    25. subwf tens, 0
    26. btfsc STATUS, C
    27. CALL ADD3TENS
    28.  
    29. movlw 5
    30. subwf ones, 0
    31. btfsc STATUS, C
    32. CALL ADD3ONES
    33.  
    34. decf count, 1
    35. bcf STATUS, C
    36. rlf BIN, 1
    37. rlf ones, 1
    38. btfsc ones,4 ;
    39. CALL CARRYONES
    40. rlf tens, 1
    41.  
    42. btfsc tens,4 ;
    43. CALL CARRYTENS
    44. rlf huns,1
    45. bcf STATUS, C
    46.  
    47. movf count, 0
    48. btfss STATUS, Z
    49. GOTO BCDADD3
    50.  
    51.  
    52. movf huns, 0 ; add ASCII Offset
    53. addlw h'30'
    54. movwf huns
    55.  
    56. movf tens, 0 ; add ASCII Offset
    57. addlw h'30'
    58. movwf tens
    59.  
    60. movf ones, 0 ; add ASCII Offset
    61. addlw h'30'
    62. movwf ones
    63.  
    64. RETURN
    65.  
    66. ADD3HUNS
    67.  
    68. movlw 3
    69. addwf huns,1
    70.  
    71. RETURN
    72.  
    73. ADD3TENS
    74.  
    75. movlw 3
    76. addwf tens,1
    77.  
    78. RETURN
    79.  
    80. ADD3ONES
    81.  
    82. movlw 3
    83. addwf ones,1
    84.  
    85. RETURN
    86.  
    87. CARRYONES
    88. bcf ones, 4
    89. bsf STATUS, C
    90. RETURN
    91.  
    92. CARRYTENS
    93. bcf tens, 4
    94. bsf STATUS, C
    95. RETURN
    96.  
     
  6. t06afre

    AAC Fanatic!

    May 11, 2009
    5,939
    1,222
Loading...