Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

Convert ADC Value to Ascii to display on LCD

Status
Not open for further replies.

ark55800

Newbie level 2
Joined
Apr 26, 2012
Messages
2
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,281
Activity points
1,311
Hi, I am working on a project to display the temperature from a thermistor on a LCD display. Here is a list of components I am using.
HD44780
PIC18F4520
LM35cz

I am working in assembly language and my question is how to take the 10 bit ADC result my PIC gives me in the ADRES register and display it in Fahrenheit on the LCD. I am pretty much stuck as far as coding goes. Not sure what steps I need to take. Can anyone help me out? Here is my code


Code ASM - [expand]
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
Main
        #DEFINE enable  PORTC,2
        #DEFINE RW              PORTC,1
        #DEFINE RS              PORTC,0
 
        movlw   0x00
        movwf   TRISC
        movwf   TRISD
        movlw   0xFF
        movwf   TRISA
        
Initialize_LCD
        BCF     RW      ; clear RW
        BCF     RS      ; clear so you can put in instructions
        movlw   0x38    ; setting up LCD for 8 bit interface, 2 lines
        movwf   PORTD   ; send to PORTD
        call    toggle  ; calls toggle which sets enable then delays, then clears enable.. (writes commands)
        movlw   0x38    ; must send a total of three times to the LCD 
        movwf   PORTD
        call    toggle
        movlw   0x38    ; last time to send to PORTD
        movwf   PORTD
        call    toggle
        movlw   0x0F    ; command for LCD display on cursor blinking
        movwf   PORTD
        call    toggle
        movlw   0x14    ; move cursor right by one character
        movwf   PORTD
        call    toggle
        movlw   0x01    ; clear LCD display and DDRAM
        movwf   PORTD
        call    toggle
 
FirstMessage
        BSF     RS      ; setting RS will enable the LCD to accept data inputs
        movlw   'T'     ; writing a L to the LCD
        movwf   PORTD
        call    toggle
        movlw   'E'     ; writing an E to the LCD
        movwf   PORTD
        call    toggle
        movlw   'M'
        movwf   PORTD
        call    toggle
        movlw   'P'     ; making a space on the LCD
        movwf   PORTD
        call    toggle
        movlw   ':'
        movwf   PORTD
        call    toggle
 
SetupRegisters
        movlw   b'10001010'
        movwf   ADCON2 ; setup ADCON2 to 2Tad and 32 Prescaler TOSC (3.2us acquistion time)
 
        movlw   0x00
        movwf   ADCON0 ; select channel 0
 
ADCModule
        BSF     ADCON0,0 ; turn on the ADC module
        BSF     ADCON0,1 ; start the conversion
Conversion      
        btfsc   ADCON0,1 ; check conversion
        goto    Conversion
        BCF     ADCON0,0 ; turn off the ADC module
        movlw   ADRESH ; read and move the result
        movwf   0x00
        movlw   ADRESL ; read and move the result
        movwf   0x01    
 
 
        BCF     RS
        movlw   0xC0
        movwf   PORTD
        call    toggle
 
Insert Code for displaying conversion
 
 
        goto    ADCModule
 
 
toggle                          ;       toggle commands into LCD
        BSF     enable          ;       Make enable high
        call delay2             ;       call delay 
        BCF     enable          ;       clear enable
        return                  ;       return to code
 
delay2
        movlw   0x9F
        movwf   count1
        movwf   count2
indelay2
        decfsz  count1,1
        goto    indelay2
        decfsz  count2,1
        goto    indelay2
        return
 
delay                   ; delay for 1s
        movlw   0xFF
        movwf   count1
        movwf   count2
indelay
        decfsz  count1,1
        goto    indelay
        decfsz  count2,1
        goto    indelay
        return
;       *** main code goes here ***
 
 
;******************************************************************************
;End of program
stop
                END

 
Last edited by a moderator:

Hi, I don't know much of assembly but after you have th final temp in a numerical variable, you can convert this way:

HD44780 number chars are ASCII code

1.divide the number by 10
the remainder will be the 1st digit of the number

2. divide the result of division(not remainder) by 10
the remainder is the 2nd digit of the number

3. Continue until you have a situation where result < 10
that is you last digit

i.e.:

1234

1234/10 = 123 remain 4
123/10 = 12 remain 3
12/10 = 1 remain 2

1 is less than 10 so this is your last digit.

Now just add 0x30 to each "remainder" digit and you got the ASCII code of that digit
then order them correctly or read them backwards, because they will stored backwards...
 

Im not sure I can do that. I dont know of a division command in the PIC18 instruction set.
 

I've been goggling ..

Check this lib (i'm not sure if works on your PIC):
**broken link removed**

You will probably want to check the folder =)
**broken link removed**
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top