Download as doc, pdf, or txt
Download as doc, pdf, or txt
You are on page 1of 3

Maximum-Minimum Thermometer. CCS PCWHD 4.

114 code:

Maximum-Minimum Thermometer. CCS PCWHD 4.114 code: #include <16F876A.h> #device ADC=10 #device *= 16 #fuses HS, PUT, BROWNOUT, CPD, PROTECT #fuses NOWDT, NODEBUG, NOLVP, NOWRT #use delay(CLOCK=10MHz) #include "lcd420.c"

float t_avg = 0; float t_min = 0; float t_max = 0; int1 st = 0; static void setup_mcu(); unsigned long adc_avg(); void show_temperature();

void main() { setup_mcu(); while(TRUE) { show_temperature(); } }

static void setup_mcu() { disable_interrupts(GLOBAL); setup_ADC(ADC_clock_div_64); setup_adc_ports(AN0);

set_ADC_channel(0); lcd_init(); lcd_putc("\f"); lcd_putc("The Ultimate\nThermometer!"); delay_ms(499); lcd_putc("\f"); st=0; }

unsigned long adc_avg() { unsigned long temp=0; unsigned int8 s = 0; for(s=0;s<128;++s) { read_ADC(ADC_start_only); while(adc_done() == 0) temp += read_ADC(ADC_read_only); } temp >>= 7; return temp; }

void show_temperature() { t_avg = ((adc_avg())*0.48828125); if(st==0) { t_min=t_avg; t_max=t_avg; st=1; } if(t_avg>t_max) { t_max = t_avg; } if(t_avg<t_min) { t_min = t_avg; } lcd_gotoxy(3,1); lcd_putc("Temperature Data");

lcd_gotoxy(2,2); printf(lcd_putc,"Maximum = %02.2f'C ",t_max); lcd_gotoxy(2,3); printf(lcd_putc,"Current = %02.2f'C ",t_avg); lcd_gotoxy(2,4); printf(lcd_putc,"Minimum = %02.2f'C ",t_min); delay_ms(1000); }

You might also like