Page 1 of 2

SK40C+PIC16F877A+DS18B20 Temp Sensor Tutorial

PostPosted: Thu Jan 31, 2013 6:02 pm
by AGPDL
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.

Re: SK40C+PIC16F877A+DS18B20 Temp Sensor Tutorial

PostPosted: Thu Jan 31, 2013 6:15 pm
by zhenning
Post your code here. It seems you have problem with line 295. can’t generate code for this expression”

Re: SK40C+PIC16F877A+DS18B20 Temp Sensor Tutorial

PostPosted: Thu Jan 31, 2013 6:18 pm
by AGPDL
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);

}

Re: SK40C+PIC16F877A+DS18B20 Temp Sensor Tutorial

PostPosted: Thu Jan 31, 2013 6:57 pm
by robosang
My guess.... compiler version.

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

Re: SK40C+PIC16F877A+DS18B20 Temp Sensor Tutorial

PostPosted: Fri Feb 01, 2013 10:27 am
by AGPDL
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.

Re: SK40C+PIC16F877A+DS18B20 Temp Sensor Tutorial

PostPosted: Fri Feb 01, 2013 4:46 pm
by AGPDL
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 ?

Re: SK40C+PIC16F877A+DS18B20 Temp Sensor Tutorial

PostPosted: Tue Feb 05, 2013 10:12 am
by AGPDL
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.

Re: SK40C+PIC16F877A+DS18B20 Temp Sensor Tutorial

PostPosted: Thu Feb 07, 2013 10:32 am
by robosang
How is the hardware setup look like? Can show a photo?

Re: SK40C+PIC16F877A+DS18B20 Temp Sensor Tutorial

PostPosted: Thu Feb 07, 2013 9:04 pm
by shahrul
This video from MyTech Invention.

Re: SK40C+PIC16F877A+DS18B20 Temp Sensor Tutorial

PostPosted: Wed Feb 13, 2013 11:01 am
by AGPDL
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.