SK40C+PIC16F877A+DS18B20 Temp Sensor Tutorial

Programmer, In-Circuit Debugger, PIC Start-Up Kit, Memory Interface...

SK40C+PIC16F877A+DS18B20 Temp Sensor Tutorial

Postby AGPDL » Thu Jan 31, 2013 6:02 pm

Hi All,

This is related to the DS18B20 Temperature Sensor tutorial : http://tutorial.cytron.com.my/2012/11/0 ... ent-112107

I posted my question at the tutorial page but no response, so I thought I'll post it here too.

When I try to “rebuild” the code in MPLAB, the build failed with message :
“Error [712] H:\Arduino\Projects-PIC\DS18B20\Example Code\lcd.c; 295. can’t generate code for this expression”

The same lcd.c file that was used in another tutorial : “GSM modem TC35 with PIC16F877A” is able to build without any problems.

What could be the problem ?

Thank you.
AGPDL
Newbie
 
Posts: 15
Joined: Tue Dec 13, 2011 3:46 pm

Re: SK40C+PIC16F877A+DS18B20 Temp Sensor Tutorial

Postby zhenning » Thu Jan 31, 2013 6:15 pm

Post your code here. It seems you have problem with line 295. can’t generate code for this expression”
zhenning
Enthusiast
 
Posts: 351
Joined: Thu Dec 30, 2010 12:32 am

Re: SK40C+PIC16F877A+DS18B20 Temp Sensor Tutorial

Postby AGPDL » Thu Jan 31, 2013 6:18 pm

zhenning WROTE:Post your code here. It seems you have problem with line 295. can’t generate code for this expression”

Here's the section of the code taken from the tutorial download :

void lcd_bcd(unsigned char uc_digit, unsigned int ui_number)
{
unsigned int ui_decimal[5] ={ 0 }; //< THIS IS LINE 295 >
//extract 5 single digit from ui_number
ui_decimal[4] = ui_number/10000; // obtain the largest single digit, digit4
ui_decimal[3] = ui_number%10000; // obtain the remainder
ui_decimal[2] = ui_decimal[3]%1000;
ui_decimal[3] = ui_decimal[3]/1000; // obtain the 2nd largest single digit, digit3
ui_decimal[1] = ui_decimal[2]%100;
ui_decimal[2] = ui_decimal[2]/100; // obtain the 3rd largest single digit, digit2
ui_decimal[0] = ui_decimal[1]%10; // obtain the smallest single digit, digit0
ui_decimal[1] = ui_decimal[1]/10; // obtain the 4th largest single digit, digit1


lcd_putchar(ui_decimal[4] + 0x30);
lcd_putchar(ui_decimal[3] + 0x30);
lcd_putchar(ui_decimal[2] + 0x30);
lcd_putchar('.');
lcd_putchar(ui_decimal[1] + 0x30);
lcd_putchar(ui_decimal[0] + 0x30);

}
AGPDL
Newbie
 
Posts: 15
Joined: Tue Dec 13, 2011 3:46 pm

Re: SK40C+PIC16F877A+DS18B20 Temp Sensor Tutorial

Postby robosang » Thu Jan 31, 2013 6:57 pm

My guess.... compiler version.

Simple, just replace it with:
unsigned int ui_decimal[5] ={ 0,0,0,0,0 };
robosang
Expert
 
Posts: 1239
Joined: Wed Jun 10, 2009 5:37 pm

Re: SK40C+PIC16F877A+DS18B20 Temp Sensor Tutorial

Postby AGPDL » Fri Feb 01, 2013 10:27 am

robosang WROTE:My guess.... compiler version.

Simple, just replace it with:
unsigned int ui_decimal[5] ={ 0,0,0,0,0 };


Thank you for the tip. Tried it but same problem.

As mentioned, the same lcd.c file that was included in another tutorial on GSM worked fine.
Even tried to replace the lcd.c file from the other tutorial but it does not solve the problem. Suspect it is some other reason or supporting libraries/files ??

Appreciate any help.
AGPDL
Newbie
 
Posts: 15
Joined: Tue Dec 13, 2011 3:46 pm

Re: SK40C+PIC16F877A+DS18B20 Temp Sensor Tutorial

Postby AGPDL » Fri Feb 01, 2013 4:46 pm

Managed to get it to build successfully by not initialising the ui_decimal array.
I changed the line 295 as follows :

unsigned int ui_decimal[5] ={ 0 };
to
unsigned int ui_decimal[5];

Not sure what was the cause but suspect it has something to do with insufficient resources.

Although managed to build but it is not reading the temperature, keeps showing 000.00:Degree C

Have anyone run through this tutorial and get it to work ?
AGPDL
Newbie
 
Posts: 15
Joined: Tue Dec 13, 2011 3:46 pm

Re: SK40C+PIC16F877A+DS18B20 Temp Sensor Tutorial

Postby AGPDL » Tue Feb 05, 2013 10:12 am

I am still not able to get the SK40C to read the temperature.

I would really appreciate if anyone who have managed to use the files in the tutorial and get it to work.
AGPDL
Newbie
 
Posts: 15
Joined: Tue Dec 13, 2011 3:46 pm

Re: SK40C+PIC16F877A+DS18B20 Temp Sensor Tutorial

Postby robosang » Thu Feb 07, 2013 10:32 am

How is the hardware setup look like? Can show a photo?
robosang
Expert
 
Posts: 1239
Joined: Wed Jun 10, 2009 5:37 pm

Re: SK40C+PIC16F877A+DS18B20 Temp Sensor Tutorial

Postby shahrul » Thu Feb 07, 2013 9:04 pm

This video from MyTech Invention.
User avatar
shahrul
Professional
 
Posts: 812
Joined: Sat May 16, 2009 9:54 pm
Location: Selangor

Re: SK40C+PIC16F877A+DS18B20 Temp Sensor Tutorial

Postby AGPDL » Wed Feb 13, 2013 11:01 am

robosang WROTE:How is the hardware setup look like? Can show a photo?

Here's the photo :
SK40C+18B20-1s.JPG


Finally I managed to get it to work. The problem was that it was using RB0 for the data line of the temperature sensor. On the SK40C, RB0 is also connected to SW1 and when I check the schematics, it has a 0.1uF capacitor connected to GND. This effectively shorts the uS signals/pulses to GND.

Now I use RB2 instead. I actually need to connect 2 temperature sensors and wanted a quick solution (and I am just a novice in C programming), so I used RB3 for the 2nd sensor instead of figuring how to use addressing method and multidrop the sensors. Would be great if someone can share the code for this.

The next phase for this project is to add the GSM module, then I will have a Temperature Monitoring System that sends sms every few hours and immediately when a limit is reached.
AGPDL
Newbie
 
Posts: 15
Joined: Tue Dec 13, 2011 3:46 pm

Next

Return to PIC Development Tool

Who is online

Users browsing this forum: No registered users and 7 guests

cron