Help using LM35 with 16F877A

Status
Not open for further replies.

Asaeed

New Member
I'm using this code to interface LM35 with 16F877A
sbit LCD_RS at RD0_bit;
sbit LCD_EN at RD1_bit;
sbit LCD_D4 at RD4_bit;
sbit LCD_D5 at RD5_bit;
sbit LCD_D6 at RD6_bit;
sbit LCD_D7 at RD7_bit;
sbit LCD_RS_Direction at TRISD0_bit;
sbit LCD_EN_Direction at TRISD1_bit;
sbit LCD_D4_Direction at TRISD4_bit;
sbit LCD_D5_Direction at TRISD5_bit;
sbit LCD_D6_Direction at TRISD6_bit;
sbit LCD_D7_Direction at TRISD7_bit;
char *tempC = "000.0";
unsigned int tempinC;
unsigned long temp_value;
void Display_Temperature( ) {
if (tempinC/10000)
tempC[0] = tempinC/10000 + 48;
else tempC[0] = ' ';
tempC[1] = (tempinC/1000)%10 + 48;
tempC[2] = (tempinC/100)%10 + 48;
tempC[4] = (tempinC/10)%10 + 48;
Lcd_Out(2, 6, tempC);
}
void main() {
ADCON1 = 0b00000001;
TRISD = 0b00000000;
TRISA = 0b11111111;
Lcd_Init();
Lcd_Cmd(_LCD_CLEAR);
Lcd_Cmd(_LCD_CURSOR_OFF);
Lcd_Out(2,1,"temp=");
Lcd_Chr(2,11,223);
Lcd_out(2,12," C");

while(1) {
temp_value = ADC_Read(0);
temp_value = temp_value*488;
tempinC = temp_value/10;
Display_Temperature();
Delay_ms(1000); // Temperature sampling at 1 sec interval
}
}

it works great on the proteus simulator but it didn't work in the real life the Lcd didn't show anything just turned its light on ..

Please any Help .
 
One of the favourites is the XT vs HS osc settings.... If the OSC is 4mhz < set XT otherwise 4mhz > its HS...... They wont boot if this setting is wrong.

ISIS doesn't use these settings, so it runs in simulation
 
Last edited:
If that be the case.. Check all your connections.... What did you do with MCLR?
 
Asaeed please try to use post titles that indicate what your post is about.

"Help using LM35 with 16F877A " would have been an good title.

I hope you get it worked out.
 
...
...it works great on the proteus simulator but it didn't work in the real life the Lcd didn't show anything just turned its light on ..
Please any Help .

OK, if the LCD does not display you can strip the code down to just initialise the LCD and write a word to the screen.

You seem to be using standard compiler LCD functions, which should work ok. Mains things to check will be;
1. wiring! all the LCD wires need to be correct!
2. power to LCD.
3. CONTRAST pot! This is a common one. It needs to be connected correct and adjusted before text will display.
4. maybe plug in a different LCD, that will tell if the first one is faulty.
 

Thnx For ur suggestions But ,

i'm Already Do A S.C test .. and used a short code just t display my Name "Lcd_out(1, 1, "Ahmed")!!
the Lcd Is Powered correctly I think As It Lights ON All The Digits..
I thought The prob with the Pot First So I Disconnect it .. "Vss=Gnd ,Vdd=Vcc , Vee=Vcc ,Bl-=Gnd ,Hl+=Vcc,RW=Gnd, Rs,E,D4: D7 To the Pic "
 
Last edited:
What happens if you change the 1k for a 10k..... With a 1k it will sometimes not boot.
 
Asaeed said:
...
i'm Already Do A S.C test .. and used a short code just t display my Name "Lcd_out(1, 1, "Ahmed")!!

Did that test work?

Asaeed said:
...
I thought The prob with the Pot First So I Disconnect it .. "Vss=Gnd ,Vdd=Vcc , Vee=Vcc ...
...

OK, if you don't have the pot connected you need to make Vee = 0v (Gnd).

And it is still best to connect the pot, as best display is often when Vee = 0.5v or so.
 
Did that test work?

No :\


OK, if you don't have the pot connected you need to make Vee = 0v (Gnd).

And it is still best to connect the pot, as best display is often when Vee = 0.5v or so.

When i connected it to Gnd the Lcd Turned off !!! And nothing appear at all :|
 
Most LCDs will work fine with Vee = 0v. Some look a bit better with a small voltage on Vee, like 0.5v I mentioned.

I think you should connect the pot up again, chech your wiring, and start posting some photos of your display.
 
Status
Not open for further replies.
Cookies are required to use this site. You must accept them to continue using the site. Learn more…