#include #include "biosdem.h" __CONFIG(0X3539); #define CHAUFFAGE RB3 void main(void) { int cons=20 , hyst = 4, delta = 1; int temp; static bit b=0 ; char unit = 'C' ; TRISB = 0xF1 ; PORTB = 0 ; adc_on(); DelayMs(100); lcd_init(); lcd_clear(); if ( !RA4 ) { unit = 'F' ; cons = 68 ; hyst = 7 ; delta = 2 ; lcd_printf("Using Fahrenheit"); lcd_goto(LCD_LINE_TWO); lcd_printf(" Depress S2 ! "); while ( !RA4 ) ; lcd_clear(); } for ( ; ; ) { temp = -128 + (int) adc_read_8b(0); if ( unit == 'F') { temp = (9.0 * temp)/5.0 + 32 ; } if ( !RA4 && RB0 ) { if (cons < 100 && !b) { cons -= delta ; b=1 ; } } else { if (!RB0 && RA4) { if ( cons > -10 && !b) { cons += delta ; b=1; } } else { if (!RB0 && !RA4 && !b) { cons = (unit=='C') ? 20:68 ; } else { b=0; } } } lcd_goto(LCD_LINE_TWO+0); lcd_printf("Cons : %4d %c ",cons,unit); lcd_goto(LCD_LINE_ONE+0); lcd_printf("Temp : %4d %c ",temp,unit); if ( temp > cons + hyst ) { CHAUFFAGE = 0 ; lcd_goto(LCD_LINE_ONE+15); lcd_putchar('+'); } else { if (temp < cons - hyst ) { CHAUFFAGE = 1 ; lcd_goto(LCD_LINE_ONE+15); lcd_putchar('-'); } else { lcd_goto(LCD_LINE_ONE+15); lcd_putchar('o'); } } } }