electronics forum

Rules | Recent posts | topic RSS | Search | Register  | Log in

Pic interfacing with LCD problem?


Post new topic  Reply to topic    EDAboard.com Forum Index -> Microcontrollers -> Pic interfacing with LCD problem?
Author Message
engr.waqas



Joined: 21 Jul 2009
Posts: 22
Location: karachi


Post04 Aug 2009 7:39   

pic lcd problem


I have taken data into PIc controller from LM35 temp sensor.Now i want to display the reading of temp sensor to LCD.
Should i convert that value to ASCII before sending to LCD or it is already in ASCII.
If i have to convert to ASCII then how to do that in C in MPLAB.
Back to top
arthur0



Joined: 28 Nov 2003
Posts: 73
Helped: 9
Location: Stockholm, Sweden


Post04 Aug 2009 8:59   

pic lcd problems


Hi,
Not only do you need to convert your “data” to ASCII, but you also need to convert that “data” to degrees, because the data you talk about is just a numeric representation (provided you did use PIC’s ADC) of the voltage at the output of your temperature sensor.
Since you didn’t say much about what you’re doing, I will assume that you do actually sample this voltage regularly and quantify the samples (express them numerically) using an ADC. This gives you an indication of how big this voltage is as compared with the ADC’s reference voltage (whatever you chose that to be).
Having figured the absolute value of this voltage, you then cross-reference it with the datasheet that will give you a numerical value representing a temperature in degrees Celsius. (I think the datasheet mentions 10mV/°C, so, if your voltage is, say 230mV, the temperature is 230/10 = 23°C.)
This is now just a number, no text or ASCII or whatever.
To convert it to text, you either use
Code:
sprintf(receiving_text_buffer, "%d", numeric_temp)
or you do a custom algorithm that splices your number into its component digits (by using a combination of repetitive division and modulus with/of 10, for instance) and then adding the ASCII value of character ‘0’ to each of them to get their equivalent ASCII values.
I hope this makes sense to you...

Arthur
Back to top
engr.waqas



Joined: 21 Jul 2009
Posts: 22
Location: karachi


Post04 Aug 2009 9:59   

1 to 5 digit numbers ascii


Thanks a lot dear
Actually i have done that "degree conversion option" u said but now the prob is that i am getting right value on LCD for temp 0 to9 but as i set temp in sensor to 10 or other 2 digit i get
: for 10
; for 11,
< for 12
= for 13
> for 14
? for 15
and again
0 for 16
1 for 17 and so on
i.e not getting corrrect indication on LCD for 2 digit values.
MY C coding in MPLAB is
#include <P18f452.h>
#define idata PORTD
#define rs PORTBbits.RB0
#define rw PORTBbits.RB1
#define en PORTBbits.RB2
void lcdcmd(unsigned char);
void MSDelay(unsigned int);
void main (void)
{
int lbyte,hbyte,bin;
unsigned char x,y,z;

//A to D

TRISD=0;
TRISAbits.TRISA0=1;
TRISAbits.TRISA2=1;
ADCON0=0x81; //fosc/64,channel 0,A\D is on
ADCON1=0xC5; //right justified,fosc/64,AN0=analog,AN3=vref+
while(1)
{
MSDelay(1); // give A to D time to sample
ADCON0bits.GO=1;//start converting
while(ADCON0bits.DONE==1); //wait for EOC
lbyte=ADRESL; // save low byte
hbyte=ADRESH; // save high byte
lbyte>>=2;
lbyte&=0x3F;
hbyte<<=6;
hbyte&=0xC0;
bin=lbyte|hbyte;

//display on LCD
TRISD=0;
TRISB=0;
en=0;
MSDelay(1);
lcdcmd(0x38);
MSDelay(1);
lcdcmd(0x0E);
MSDelay(1);
lcdcmd(0x01);
MSDelay(1);
lcdcmd(0x06);
MSDelay(1);
lcdcmd(0x86);
MSDelay(1);
//now display
x=bin & 0x0F;// mask upper 4 bits
y=x|0x30; //make it ASCII
PORTD=y;
rs=1;
rw=0;
en=1;
MSDelay(1);
en=0;
y=bin & 0xF0; // mask lower 4 bits
y=y>>4; //shift it to lower 4 bits
MSDelay(50);
PORTD=y|0x30;//make it ascii

}
}
void lcdcmd(unsigned char value)
{
idata=value;
rs=0;
rw=0;
en=1;
MSDelay(1);
en=0;
}

void MSDelay(unsigned int itime)
{
unsigned int i;unsigned char j;
for(i=0;i<itime;i++)
for(j=0;j<135;j++);
}
Back to top
arthur0



Joined: 28 Nov 2003
Posts: 73
Helped: 9
Location: Stockholm, Sweden


Post04 Aug 2009 10:24   

pic lcd display int to ascii c


You didn't pay attention to what I wrote above: you need to split your numbers into their component digits!
For instance, the number 15 you'll want as 1, 5.
For 2 digit numbers, you can do that like this:
Code:
digit0 = number % 10;   /* step 1: digit0 = 5 */
digit1 = number / 10;   /* step 2: digit1 = 1 */


If you have more digits, you replace *step 2* with
Quote:
number = number / 10
and repeat *step 1* of the code above as neccessary.
(Note that you get the digits in reverse order!)
Hope it's clearer now.

Arthur
Back to top
Google
AdSense
Google Adsense




Post04 Aug 2009 10:24   

Ads




Back to top
engr.waqas



Joined: 21 Jul 2009
Posts: 22
Location: karachi


Post04 Aug 2009 10:47   

converting to ascii value in lcd


I think the spliting part and converting part is going in this part of coding
The bin contains data from temp sensor.
x=bin & 0x0F;// mask upper 4 bits
y=x|0x30; //make it ASCII and display
PORTD=y;
rs=1;
rw=0;
en=1;
MSDelay(1);
en=0;
y=bin & 0xF0; // mask lower 4 bits
y=y>>4; //shift it to lower 4 bits
MSDelay(50);
PORTD=y|0x30;//make it ascii and display
Back to top
vipul



Joined: 04 Jul 2008
Posts: 24
Helped: 1
Location: Ahemdabad,India


Post04 Aug 2009 11:40   

convertir entero a caracter lcd pic


As Arthur wrote previously you have to convert result of ADC in "Degree" form then print to the LCD...

In above program u are directly printing 'bin' variable which is merge result of lower and higher bits of ADC registers...

-Vipul
Back to top
arthur0



Joined: 28 Nov 2003
Posts: 73
Helped: 9
Location: Stockholm, Sweden


Post04 Aug 2009 12:40   

pic adc on lcd


Quote:
I think the spliting part and converting part is going in this part of coding

No! What you do in that part of the code is just a bit masking in which you isolate a symbol in the hexadecimal numeration system (0h - Fh, equivalent to 0 - 15 in the decimal system). A digit is, per definition, a number from 0 to 9 in the decimal numeration system.

I was afraid this would boil down to a discussion involving the words “binary”, “hex”, “decimal”, “number”, “ASCII” etc., because their meanings are best explained in school and understood via [hard] work. There’s no good substitution for that.
I can easily write your code for you, but we’ll both lose: me valuable time, and you the point with all of it!
So let me show it to you one more time instead (for a maximum of 3-digit number, say 137):
Code:
char d0, d1, d2;
d2 = bin % 10;                  /* d2 <-- 7 */
d1 = (bin / 10) % 10;           /* d1 <-- 3 */
d0 = ((bin / 10) / 10) % 10;    /* d0 <-- 1 */
/* continue like this for even more digits */

/* convert digit (numbers) to ASCII (text characters) */
d0 += ‘0’;   /* same as d0 = d0 + ‘0’ same as d0 = d0 | 0x30 */
d1 += ‘0’;
d2 += ‘0’;

/* send ASCII chars to port */
/* ... */

You could do this nicer, you could do it a little more efficiently, but for you to understand I wanted to show all the little steps that you’ve missed and also to suggest how the digits can be extracted recursively, but that’s your homework.

So this will do the conversion for you, but I’m sill not convinced that what you’ll see is temperature since there’s nothing in your program that resemble a “volt to degree” conversion, unless you’ve chosen such a voltage reference that your ADC will actually do it for you.

Arthur
Back to top
Arabic versionBulgarian versionCatalan versionCzech versionDanish versionGerman versionGreek versionEnglish versionSpanish versionFinnish versionFrench versionHindi versionCroatian versionIndonesian versionItalian versionHebrew versionJapanese versionKorean versionLithuanian versionLatvian versionDutch versionNorwegian versionPolish versionPortuguese versionRomanian versionRussian versionSlovak versionSlovenian versionSerbian versionSwedish versionTagalog versionUkrainian versionVietnamese versionChinese version
Post new topic  Reply to topic    EDAboard.com Forum Index -> Microcontrollers -> Pic interfacing with LCD problem?
Page 1 of 1 All times are GMT + 1 Hour
Similar topics:
lcd interfacing to pic 16f877a problem (9)
LCD interfacing with a PIC - TUTORIAL - (3)
interfacing lcd with pic 18f452 (1)
Interfacing HD44780 LCD with PIC 16F877 (7)
128x64 Graphic LCD Interfacing with PIC (2)
T610 LCD Pinout for interfacing with PIC Controller (17)
Interfacing Hitachi HD44780 2x16 LCD with PIC 16F877 (9)
INTERFACING TFT LCD MODULE WITH TOUCH PANEL TO PIC (2)
LCD interfacing? problem with displaing larger numbers (2)
problem with controlling LCD 16x2 with PIC 16f877 (6)


Abuse || Administrator || Moderators || Support us || sitemap
topic RSS