Documente Academic
Documente Profesional
Documente Cultură
In this experiment, we are going to build a digital temperature meter using DS1820 connected to
our PIC16F628A development board. The temperature value will be displayed on the LCD
display. I have modified the sample program that comes with the compiler according to our PIC
board requirements. Also I have elaborated comments in the program so that every step will be
more clear to the readers.
Experimental Setup:
The experimental setup is very straight-forward. Place DS1820 device on the three-pin female
header that we recently added to our board. And also connect the data pin of DS1820 to RB.0 pin
of PIC16F628A using a jumper wire.
Circuit Diagram
Software:
Here is the program written in microC that reads temperature values from DS1820 device using
OneWire Library.
/* Project name:
One Wire Communication Test between PIC16F628A and DS1820
* Copyright:
(c) Rajendra Bhatt, 2009.
* Description:
This code demonstrates how to use One Wire Communication Protocol
between PIC16F628A and a 1-wire peripheral device. The peripheral
device used here is DS1820, digital temperature sensor.
MCU: PIC16F628A
Oscillator: XT, 4.0 MHz
*/
// LCD connections definitions
sbit LCD_RS at RA0_bit;
sbit LCD_EN at RA1_bit;
sbit LCD_D4 at RB4_bit;
sbit LCD_D5 at RB5_bit;
sbit LCD_D6 at RB6_bit;
sbit LCD_D7 at RB7_bit;
sbit LCD_RS_Direction at TRISA0_bit;
sbit LCD_EN_Direction at TRISA1_bit;
sbit LCD_D4_Direction at TRISB4_bit;
sbit LCD_D5_Direction at TRISB5_bit;
sbit LCD_D6_Direction at TRISB6_bit;
sbit LCD_D7_Direction at TRISB7_bit;
// End LCD connections definitions
void main() {
CMCON |= 7; // Disable Comparators
Lcd_Init(); // Initialize LCD
Lcd_Cmd(_LCD_CLEAR); // Clear LCD
Lcd_Cmd(_LCD_CURSOR_OFF); // Turn cursor off
Lcd_Out(1, 3, "Temperature: ");
// Print degree character, 'C' for Centigrades
Lcd_Chr(2,11,223);
// different LCD displays have different char code for degree
// if you see greek alpha letter try typing 178 instead of 223
Lcd_Chr(2,12,'C');
Ow_Reset(&PORTB, 0);
Ow_Write(&PORTB, 0, 0xCC); // Issue command SKIP_ROM
Ow_Write(&PORTB, 0, 0xBE); // Issue command READ_SCRATCHPAD
} while (1);
}
Experimental Output:
The temperature reading will be displayed on the LCD screen and will be updated every 600ms.
Look at some snapshots below showing output.
Posted by Raj at 7:09 PM
12 comments:
Fabio said...
ducu said...
Hello Mr. Raj i have been testes both version of temperature sensor (DS1820 and
DS18B20) and i found a little bug, in both version cannot display symbol "-" when read a
negative temperature.
Do you have any idea how to solve this problem?
I try to solve the problem by myself, with no results.
By the way you did a great gob with this site.
Regards,
ducu
Raj said...
My code should work to display negative temperature too. Negative temperature are in
2's complement form, see my code
// check if temperature is negative
if (temp2write & 0x8000) {
temp[0] = '-';
// Negative temp values are stored in 2's complement form
temp2write = ~temp2write + 1;
}
Raj said...
Fabio,
Here is my experiment with Seven segment Displays.
http://pic16f628a.blogspot.com/2009/10/experiment-no-5-multiplexed-seven.html
Nimal2006 said...
Dear Sir,
I used DS18S20. it did not works it shows 'Temperature:
000.00 C
no temperature detects. I use same code. whats wrong?
Nimal
Raj said...
Ow_Write(&PORTB, 0, 0x44);
Delay_ms(800);
// If this delay is less than 500ms, you will see the first reading on
Nimal2006 said...
Nimal2006 said...
If LCD is 10 meters away from DS18S20 what kind of cable I have to used?
Krishna said...
Raj said...
Krishna,
I have posted the circuit diagram. Enjoy!
kuzmin said...
Raj said...
Kuzmin,
Here it is
http://embedded-lab.com/uploads/HexFiles/PIC16F628A/PIC16F628A_DS1820.zip
Post a Comment
Newer Post Older Post Home