A_Nis
Newbie level 5
- Joined
- Oct 1, 2013
- Messages
- 9
- Helped
- 0
- Reputation
- 0
- Reaction score
- 0
- Trophy points
- 1
- Activity points
- 102
Hi
i'm new with pic programming but i have a project to develop a temperature measuring and alerting system
The thing is i have the program for DS18S20 sensor but not for DS18B20
so wanna know the changes which i have to make in my program according to the change of the sensor
though i have try to identify it my self its bit difficult
display 2x16 LCD.
PIC16f877A is the microcontroller.
Thanks
Avani 8-O
Here is the program for DS18S20 with PIC16f877A
// LCD connections definitions
sbit LCD_RS at RB2_bit;
sbit LCD_EN at RB3_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 TRISB2_bit;
sbit LCD_EN_Direction at TRISB3_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
// String array to store temperature value to display
char *temp = "000.00";
// Temperature Resolution : No. of bits in temp value = 9
const unsigned short TEMP_RES = 9;
// Variable to store temperature register value
unsigned temp_value;
void Display_Temperature(unsigned int temp2write) {
const unsigned short RES_SHIFT = TEMP_RES - 8;
// Variable to store Integer value of temperature
char temp_whole;
// Variable to store Fraction value of temperature
unsigned int temp_fraction;
unsigned short isNegative = 0x00;
// check if temperature is negative
if (temp2write & 0x8000) {
temp[0];
// Negative temp values are stored in 2's complement form
temp2write = ~temp2write + 1;
isNegative = 1; // Temp is -ive
}
// Get temp_whole by dividing by 2 (DS1820 9-bit resolution with
// 0.5 Centigrade step )
temp_whole = temp2write >> RES_SHIFT ;
// convert temp_whole to characters
if (!isNegative) {
if (temp_whole/100)
// 48 is the decimal character code value for displaying 0 on LCD
temp[0] = temp_whole/100 + 48;
else
temp[0] = '0';
}
temp[1] = (temp_whole/10)%10 + 48; // Extract tens digit
temp[2] = temp_whole%10 + 48; // Extract ones digit
// extract temp_fraction and convert it to unsigned int
temp_fraction = temp2write << (4-RES_SHIFT);
temp_fraction &= 0x000F;
temp_fraction *= 625;
// convert temp_fraction to characters
temp[4] = temp_fraction/1000 + 48; // Extract tens digit
temp[5] = (temp_fraction/100)%10 + 48; // Extract ones digit
// print temperature on LCD
Lcd_Out(2, 5, temp);
}
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');
//--- main loop
do {
//--- perform temperature reading
Ow_Reset(&PORTE, 0); // Onewire reset signal
Ow_Write(&PORTE, 0, 0xCC); // Issue command SKIP_ROM
Ow_Write(&PORTE, 0, 0x44); // Issue command CONVERT_T
Delay_ms(600);
// If this delay is less than 500ms, you will see the first reading on LCD
//85C which is (if you remember from my article on DS1820)
//a power-on-reset value.
Ow_Reset(&PORTE, 0);
Ow_Write(&PORTE, 0, 0xCC); // Issue command SKIP_ROM
Ow_Write(&PORTE, 0, 0xBE); // Issue command READ_SCRATCHPAD
// Read Byte 0 from Scratchpad
temp_value = Ow_Read(&PORTB, 0);
// Then read Byte 1 from Scratchpad and shift 8 bit left and add the Byte 0
temp_value = (Ow_Read(&PORTB, 0) << 8) + temp_value;
//--- Format and display result on Lcd
Display_Temperature(temp_value);
//EDITED
/*if(temp_value>0){
}*/
//EDITED
} while (1);
}
please see the attached circuit diagram
i'm new with pic programming but i have a project to develop a temperature measuring and alerting system
The thing is i have the program for DS18S20 sensor but not for DS18B20
so wanna know the changes which i have to make in my program according to the change of the sensor
though i have try to identify it my self its bit difficult
display 2x16 LCD.
PIC16f877A is the microcontroller.
Thanks
Avani 8-O
Here is the program for DS18S20 with PIC16f877A
// LCD connections definitions
sbit LCD_RS at RB2_bit;
sbit LCD_EN at RB3_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 TRISB2_bit;
sbit LCD_EN_Direction at TRISB3_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
// String array to store temperature value to display
char *temp = "000.00";
// Temperature Resolution : No. of bits in temp value = 9
const unsigned short TEMP_RES = 9;
// Variable to store temperature register value
unsigned temp_value;
void Display_Temperature(unsigned int temp2write) {
const unsigned short RES_SHIFT = TEMP_RES - 8;
// Variable to store Integer value of temperature
char temp_whole;
// Variable to store Fraction value of temperature
unsigned int temp_fraction;
unsigned short isNegative = 0x00;
// check if temperature is negative
if (temp2write & 0x8000) {
temp[0];
// Negative temp values are stored in 2's complement form
temp2write = ~temp2write + 1;
isNegative = 1; // Temp is -ive
}
// Get temp_whole by dividing by 2 (DS1820 9-bit resolution with
// 0.5 Centigrade step )
temp_whole = temp2write >> RES_SHIFT ;
// convert temp_whole to characters
if (!isNegative) {
if (temp_whole/100)
// 48 is the decimal character code value for displaying 0 on LCD
temp[0] = temp_whole/100 + 48;
else
temp[0] = '0';
}
temp[1] = (temp_whole/10)%10 + 48; // Extract tens digit
temp[2] = temp_whole%10 + 48; // Extract ones digit
// extract temp_fraction and convert it to unsigned int
temp_fraction = temp2write << (4-RES_SHIFT);
temp_fraction &= 0x000F;
temp_fraction *= 625;
// convert temp_fraction to characters
temp[4] = temp_fraction/1000 + 48; // Extract tens digit
temp[5] = (temp_fraction/100)%10 + 48; // Extract ones digit
// print temperature on LCD
Lcd_Out(2, 5, temp);
}
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');
//--- main loop
do {
//--- perform temperature reading
Ow_Reset(&PORTE, 0); // Onewire reset signal
Ow_Write(&PORTE, 0, 0xCC); // Issue command SKIP_ROM
Ow_Write(&PORTE, 0, 0x44); // Issue command CONVERT_T
Delay_ms(600);
// If this delay is less than 500ms, you will see the first reading on LCD
//85C which is (if you remember from my article on DS1820)
//a power-on-reset value.
Ow_Reset(&PORTE, 0);
Ow_Write(&PORTE, 0, 0xCC); // Issue command SKIP_ROM
Ow_Write(&PORTE, 0, 0xBE); // Issue command READ_SCRATCHPAD
// Read Byte 0 from Scratchpad
temp_value = Ow_Read(&PORTB, 0);
// Then read Byte 1 from Scratchpad and shift 8 bit left and add the Byte 0
temp_value = (Ow_Read(&PORTB, 0) << 8) + temp_value;
//--- Format and display result on Lcd
Display_Temperature(temp_value);
//EDITED
/*if(temp_value>0){
}*/
//EDITED
} while (1);
}
please see the attached circuit diagram