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.

how to code ADC voltage to LCD display?

Status
Not open for further replies.

caramelz

Junior Member level 2
Junior Member level 2
Joined
Jul 19, 2012
Messages
22
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,281
Visit site
Activity points
1,464
hi i'm using mcc18 compiler. I need to display the voltage on my lcd (tc1602A) using microcontroller (PIC18f4520). I'm stuck after while(ADCON0bits.DONE), and i dunno how to display the value on LCD.
Please help!

Code:
#include <p18f4520.h>
#include <delays.h>
#include <stdlib.h> 

	ADCON0=0b00000001;
	ADCON1=0b00000111;
	ADCON2=0b10000010;

Delay10TCYx(5);
ADCON0bits.GO = 1;		// Start ADC 
while(ADCON0bits.DONE);	// ADC completed?
 

Where is LCD Code? You have to get the values in ADRESH and ADRESL into a float or int variable and convert that float ot int value to string and display the sting on LCD.

Post full code in syntax tags.
 

I need a range from 0 to 5V in 2decimals place on the LCD
I dont get
Code:
#include <p18f4520.h>
#include <delays.h>
#include <stdlib.h> 

void Init_LCD(void);   
void W_ctr_8bit(char);  
void W_data_8bit(char);

#define LCD_DATA PORTD
#define LCD_RS PORTBbits.RB1
#define LCD_E PORTBbits.RB2
void main()
{       int result;
        char MESS[i]="Voltage:"
	ADCON0=0b00000001;
	ADCON1=0b00000111;
	ADCON2=0b10000110;

Delay10TCYx(5);
ADCON0bits.GO = 1;		// Start ADC 
while(ADCON0bits.DONE);	// ADC completed?		
result = ADRESH;;
result>>=4;
PORTB=result;
for(i=0;i<8;i++)
W_data_8bit(Mess[i]);  // is to print text to LCD
}
 
Last edited:

Check this link. I have written a code there. My previous account was internetuser2k11 and 12.

https://www.edaboard.com/threads/254723/



https://www.edaboard.com/threads/253183/

Use that code. There is a small mistake in floattosting() function. I have fixed it here.


Code C - [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
//Function Prototypes
void floattostring(double FP_NUM);
 
//Sub Function
void floattostring(double FP_NUM) {
        double fpnumber;
        long int befdec, aftdec;
 
        fpnumber = FP_NUM;
 
        befdec = fpnumber;                      // Fractional part is truncated
                                                // 12.163456 becomes 12
        aftdec = fpnumber * 100;            // 12.163456 becomes 1216
        aftdec = aftdec - (befdec * 100);   // 1216 - 1200 = 16
 
 
        if (fpnumber < 1) {
                string[0] = '0';
                string[1] = '.';
                string[2] = (aftdec/10) + 48;
                string[3] = (aftdec/1)%10 + 48;
                string[4] = '\0';
                
 
        }
 
        else if ((fpnumber >= 1) && (fpnumber < 10)) {
                string[0] = (befdec/1)%10 + 48;
                string[1] = '.';
                string[2] = (aftdec/10) + 48;
                string[3] = (aftdec/1)%10 + 48;
                string[4] = '\0';
                
 
        }
 
        else if ((fpnumber >= 10) && (fpnumber < 100)) {
                string[0] = (befdec/10) + 48;
                string[1] = (befdec/1)%10 + 48;
                string[2] = '.';
                string[3] = (aftdec/10) + 48;
                string[4] = (aftdec/1)%10 + 48;
                string[5] = '\0';
                
 
        }
 
        else if ((fpnumber >= 100) && (fpnumber < 1000)) {
                string[0] = (befdec/100) + 48;
                string[1] = (befdec/10)%10 + 48;
                string[2] = (befdec/1)%10 + 48;
                string[3] = '.';
                string[4] = (aftdec/10) + 48;
                string[5] = '\0';
                
 
        }
        
        else if ((fpnumber >= 1000) && (fpnumber < 10000)) {
                string[0] = (befdec/1000) + 48;
                string[1] = (befdec/100)%10 + 48;
                string[2] = (befdec/10)%10 + 48;
                string[3] = (befdec/1)%10 + 48;
                string[4] = '.';
                string[5] = (aftdec/10) + 48;
                string[6] = '\0';
                
 
        }
 
        else if ((fpnumber >= 10000) && (fpnumber < 100000)) {
                string[0] = (befdec/10000) + 48;
                string[1] = (befdec/1000)%10 + 48;
                string[2] = (befdec/100)%10 + 48;
                string[3] = (befdec/10)%10 + 48;
                string[4] = (befdec/1)%10 + 48;
                string[5] = '.';
                string[6] = (aftdec/10) + 48;
                string[7] = '\0';
 
        }
        
 
}

 

Check this link. I have written a code there. My previous account was internetuser2k11 and 12.

https://www.edaboard.com/threads/254723/



https://www.edaboard.com/threads/253183/

Use that code. There is a small mistake in floattosting() function. I have fixed it here.


Code C - [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
//Function Prototypes
void floattostring(double FP_NUM);
 
//Sub Function
void floattostring(double FP_NUM) {
        double fpnumber;
        long int befdec, aftdec;
 
        fpnumber = FP_NUM;
 
        befdec = fpnumber;                      // Fractional part is truncated
                                                // 12.163456 becomes 12
        aftdec = fpnumber * 100;            // 12.163456 becomes 1216
        aftdec = aftdec - (befdec * 100);   // 1216 - 1200 = 16
 
 
        if (fpnumber < 1) {
                string[0] = '0';
                string[1] = '.';
                string[2] = (aftdec/10) + 48;
                string[3] = (aftdec/1)%10 + 48;
                string[4] = '\0';
                
 
        }
 
        else if ((fpnumber >= 1) && (fpnumber < 10)) {
                string[0] = (befdec/1)%10 + 48;
                string[1] = '.';
                string[2] = (aftdec/10) + 48;
                string[3] = (aftdec/1)%10 + 48;
                string[4] = '\0';
                
 
        }
 
        else if ((fpnumber >= 10) && (fpnumber < 100)) {
                string[0] = (befdec/10) + 48;
                string[1] = (befdec/1)%10 + 48;
                string[2] = '.';
                string[3] = (aftdec/10) + 48;
                string[4] = (aftdec/1)%10 + 48;
                string[5] = '\0';
                
 
        }
 
        else if ((fpnumber >= 100) && (fpnumber < 1000)) {
                string[0] = (befdec/100) + 48;
                string[1] = (befdec/10)%10 + 48;
                string[2] = (befdec/1)%10 + 48;
                string[3] = '.';
                string[4] = (aftdec/10) + 48;
                string[5] = '\0';
                
 
        }
        
        else if ((fpnumber >= 1000) && (fpnumber < 10000)) {
                string[0] = (befdec/1000) + 48;
                string[1] = (befdec/100)%10 + 48;
                string[2] = (befdec/10)%10 + 48;
                string[3] = (befdec/1)%10 + 48;
                string[4] = '.';
                string[5] = (aftdec/10) + 48;
                string[6] = '\0';
                
 
        }
 
        else if ((fpnumber >= 10000) && (fpnumber < 100000)) {
                string[0] = (befdec/10000) + 48;
                string[1] = (befdec/1000)%10 + 48;
                string[2] = (befdec/100)%10 + 48;
                string[3] = (befdec/10)%10 + 48;
                string[4] = (befdec/1)%10 + 48;
                string[5] = '.';
                string[6] = (aftdec/10) + 48;
                string[7] = '\0';
 
        }
        
 
}

Thanks i will try it asap. but how do i display in the LCD? or string is the one that display?
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top