I currently use the following code to read the temp from a ds1820, I have it displaying the current temp all the time but I have a menu so if a button is pressed it brings up the menu instead of displaying the temp.
The problem is that the read_temp() function has delays so the switch has to be pressed at a certain time, here is the code:
How can I have it so that it will still loop through checking the temp but will goto the menu as soon as the switch is pressed?
Edit: Forgot to mention Im using the pic16f628
The problem is that the read_temp() function has delays so the switch has to be pressed at a certain time, here is the code:
Code:
void read_temp() {
//--- perform temperature reading
Ow_Reset(&PORTB, 5); // Onewire reset signal
Ow_Write(&PORTB, 5, 0xCC); // Issue command SKIP_ROM
Ow_Write(&PORTB, 5, 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(&PORTB, 5);
Ow_Write(&PORTB, 5, 0xCC); // Issue command SKIP_ROM
Ow_Write(&PORTB, 5, 0xBE); // Issue command READ_SCRATCHPAD
// Read Byte 0 from Scratchpad
temp_value = Ow_Read(&PORTB, 5);
// Then read Byte 1 from Scratchpad and shift 8 bit left and add the Byte 0
temp_value = (Ow_Read(&PORTB, 5) << 8) + temp_value;
//--- Format and display result on Lcd
Display_Temperature(temp_value);
}
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_Cmd(_LCD_CLEAR); // Clear display
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 {
if(Button(&PORTA,2, 1, 0)) {
read_sw();
}
read_temp();
} while (1);
}
How can I have it so that it will still loop through checking the temp but will goto the menu as soon as the switch is pressed?
Edit: Forgot to mention Im using the pic16f628
Last edited: