32
of 76
TEP , The Engineering Projects , Image

syedzainnasir

TEP , The Engineering Projects , Rating 7.5 7.5 / 10
TEP , The Engineering Projects , Icon Level: Moderator
TEP , The Engineering Projects , Icon Joined: 20 Mar 2022
TEP , The Engineering Projects , Icon Last Active: 2:21 PM
TEP , The Engineering Projects , Icon Location: TEP , The Engineering Projects , Flag
TEP , The ENgineering Projects , Icon TEP , The ENgineering Projects , Icon TEP , The ENgineering Projects , Icon TEP , The ENgineering Projects , Icon
Displaying ADC value in LCD using PIC
TEP , The Engineering Projects , Calender Question: 22-Feb-2017
TEP , The Engineering Projects , Category In: PIC Microcontroller Projects
Hi all,

I am in a situation where I need to read ADC value and display it in LCD. Im using PIC18F4620. I have interfaced the LCD with the PIC and it can display normal strings very well. But I have been caught in a difficult situation when I try to read an analog value and display it in my LCD. This is my simple code:

// LCD module connections
sbit LCD_RS at RB0_bit;
sbit LCD_EN at RB1_bit;
sbit LCD_D4 at RB2_bit;
sbit LCD_D5 at RB3_bit;
sbit LCD_D6 at RB4_bit;
sbit LCD_D7 at RB5_bit;

sbit LCD_RS_Direction at TRISB0_bit;
sbit LCD_EN_Direction at TRISB1_bit;
sbit LCD_D4_Direction at TRISB2_bit;
sbit LCD_D5_Direction at TRISB3_bit;
sbit LCD_D6_Direction at TRISB4_bit;
sbit LCD_D7_Direction at TRISB5_bit;
// End LCD module connections



int temp;


void main() {
TRISB = 0; //PORTB as output
TRISA = 0xFF; //PORTA as input
ADCON1 = 0x7A; // Configure all ports with analog function as digital except RA2
CMCON |= 7; // Disable comparators
Lcd_Init(); //Initialize LCD

while (1){
Lcd_Cmd(_LCD_CLEAR);
Lcd_Cmd(_LCD_CURSOR_OFF);
temp = 5000*ADC_Read(2)/1023;


Lcd_Out(1, 1, temp);
Delay_ms(500);
}
}

There are few problems here. I am not sure what value will the variable 'temp' have. When I use the function LCD_Out, I get a warning that reads: "Implicit conversion of int to ptr" and the LCD would show a string of funny symbols. When I use LCD_Chr, it doesnt give any warning, but I only get to see a single numeric character on the display. Furthermore, I am not sure if I should convert temp from hex to decimal or binary to decimal since I am not sure the nature of the read value. Please help me on this, thanks in advance. Your suggestions/opinions are much much anticipated.
TEP , The Engineering Projects , Icon Answer: 1 TEP , The Engineering Projects , Icon Views: 150 TEP , The Engineering Projects , Icon Followers: 85
Small Bio
TEP , The Engineering Projects , Image

syedzainnasir

TEP , The Engineering Projects , Rating 7.5 7.5 / 10
TEP , The Engineering Projects , Icon Level: Moderator
TEP , The Engineering Projects , Icon Joined: 20 Mar 2022
TEP , The Engineering Projects , Icon Last Active: 2:21 PM
TEP , The Engineering Projects , Icon Location: TEP , The Engineering Projects , Flag
TEP , The ENgineering Projects , Icon TEP , The ENgineering Projects , Icon TEP , The ENgineering Projects , Icon TEP , The ENgineering Projects , Icon

RE:

Displaying ADC value in LCD using PIC
TEP , The Engineering Projects , Calender Comment: 22-Feb-2017
TEP , The Engineering Projects , Category In: PIC Microcontroller Projects
[quote=Peacock post_id=136 time=1487768324 user_id=77] Hi all,

I am in a situation where I need to read ADC value and display it in LCD. Im using PIC18F4620. I have interfaced the LCD with the PIC and it can display normal strings very well. But I have been caught in a difficult situation when I try to read an analog value and display it in my LCD. This is my simple code:

// LCD module connections
sbit LCD_RS at RB0_bit;
sbit LCD_EN at RB1_bit;
sbit LCD_D4 at RB2_bit;
sbit LCD_D5 at RB3_bit;
sbit LCD_D6 at RB4_bit;
sbit LCD_D7 at RB5_bit;

sbit LCD_RS_Direction at TRISB0_bit;
sbit LCD_EN_Direction at TRISB1_bit;
sbit LCD_D4_Direction at TRISB2_bit;
sbit LCD_D5_Direction at TRISB3_bit;
sbit LCD_D6_Direction at TRISB4_bit;
sbit LCD_D7_Direction at TRISB5_bit;
// End LCD module connections



int temp;


void main() {
TRISB = 0; //PORTB as output
TRISA = 0xFF; //PORTA as input
ADCON1 = 0x7A; // Configure all ports with analog function as digital except RA2
CMCON |= 7; // Disable comparators
Lcd_Init(); //Initialize LCD

while (1){
Lcd_Cmd(_LCD_CLEAR);
Lcd_Cmd(_LCD_CURSOR_OFF);
temp = 5000*ADC_Read(2)/1023;


Lcd_Out(1, 1, temp);
Delay_ms(500);
}
}

There are few problems here. I am not sure what value will the variable 'temp' have. When I use the function LCD_Out, I get a warning that reads: "Implicit conversion of int to ptr" and the LCD would show a string of funny symbols. When I use LCD_Chr, it doesnt give any warning, but I only get to see a single numeric character on the display. Furthermore, I am not sure if I should convert temp from hex to decimal or binary to decimal since I am not sure the nature of the read value. Please help me on this, thanks in advance. Your suggestions/opinions are much much anticipated. [/quote]
you need to view this tutorial to solve your problem:
[url=http://www.theengineeringprojects.com/2015/04/display-adc-value-lcd-using-pic-microcontroller-proteus-isis.html]DISPLAY ADC VALUE ON LCD USING PIC[/url]
TEP , The Engineering Projects , Tick Correct Answer
Comment Bio
TEP , The Engineering Projects , Tags
PLC
Robot
STM32
Arduino
AI
ESP32
Ladder Logic
PLC Projects
Programming
Communicates STM32
PLC Projects
Communicates PLC
Font Style
Alignment
Indenting and Lists
Insert Media
Insert Items

Want to leave an answer!

Word Count :0 Draft Saved at 12:42 am.