#define _XTAL_FREQ 8000000
#include <xc.h>
#include <stdio.h>
#include "LCD_4bit_config.h"
#include "DS18B20_config.h"
#include "delay.h"
OneWire_init()
{
int i;
char buf1[10];
char buf2[10];
LCD_setCursor(1,1);
LCD_writeString("Presence:");
i = OneWire_reset();
sprintf(buf1,"%d",i);
LCD_setCursor(2,1);
LCD_writeString(buf1);
delay_ms(3000);
LCD_clr();
OneWire_reset();
LCD_setCursor(1,1);
LCD_writeString("Device family:");
OneWire_writeByte(Read_deviceFamily);
i = OneWire_readByte();
sprintf(buf2,"%d",i);
LCD_setCursor(2,1);
LCD_writeString(buf2);
delay_ms(3000);
LCD_clr();
OneWire_reset();
}
void main()
{
char temp_lsb,temp_msb,temp;
char buf3[10];
char getBit[10];
int k;
OSCCON = 0b11110010; // Set PIC18F4550 internal oscillator at 8MHz
ADCON1 = 0x0F; // Set all pins as digital I/O
CMCON = 0x07; // Set all comparators as digital I/O
LATD = 0; // Clear port D
TRISD = 0b00000000; // Set all port D pins as digital outputs
LATB = 0;
TRISB = 0x00;
LCD_init(); // Initialize LCD
OneWire_init();
while(1)
{
if (!OneWire_reset())
{
LCD_setCursor(1,1);
LCD_writeString("Temperature:");
OneWire_writeByte(Skip_ROM);
OneWire_writeByte(Convert_temperature);
OneWire_reset();
delay_ms(750);
OneWire_writeByte(Skip_ROM);
OneWire_writeByte(Read_scratchpad);
for (k=0;k<9;k++)
{
getBit[k] = OneWire_readByte();
}
temp_msb = getBit[1];
temp_lsb = getBit[0];
temp = (temp_msb << 8) + temp_lsb;
temp = temp >> 4;
sprintf(buf3,"%d",temp);
LCD_setCursor(2,1);
LCD_writeString(buf3);
delay_ms(1000);
}
}
}