void main(){
unsigned short rd,kp;
unsigned int Temp_Ref;
float Ref_Temp,rd1;
unsigned char TxT[4],TxT1,InTemp;
ADCON1=0b11000000;
TRISA0_bit=1;
TRISC0_bit=0;
TRISC1_bit=0;
ADC_Init();
LCD_Init();
Keypad_Init();
Lcd_Cmd(_LCD_CLEAR);
Lcd_Cmd(_LCD_CURSOR_OFF);
Lcd_Out(1,4,"AUTOMATIC");
delay_ms(1000);
Lcd_Out(2,1,"TEMPERATURE CONTROL");
Lcd_Cmd(_LCD_SHIFT_LEFT);
delay_ms(2000);
START:
Lcd_Cmd(_LCD_CLEAR);
PORTC.RC0=0;
PORTC.RC1=0;
Lcd_Cmd(_LCD_CLEAR);
Lcd_Out(1,1,"Enter Temp. Ref");
Temp_Ref=0;
Lcd_Out(2,1,"Temp. Ref:");
while(1){
do
kp=Keypad_Key_Click();
while(!kp);
if(kp==15)
break;
if(kp>3 && kp<12)
kp=kp-2;
if(kp==14)
kp=0;
if(kp==13)
goto START; //Eeek, you can't do this
Lcd_Chr_Cp(kp+'0');
Temp_Ref=(10*Temp_Ref)+kp;
}
Lcd_Cmd(_LCD_CLEAR);
Lcd_Out(1,1,"Temp. Ref:");
IntToStr(Temp_Ref,TxT1);
InTemp=Ltrim(TxT1);
Lcd_Out_Cp(InTemp);
Lcd_Out(2,1,"Press # to cont.");
kp=0;
while(kp!=15){
do
kp=Keypad_Key_Click();
while(!kp);
goto START_PGM;
}
while(1){
Lcd_Cmd(_LCD_CLEAR);
rd=ADC_Read(0);
rd1=(rd*5000.0)/1024.0;
Ref_Temp=rd1/10.0;
FloatToStr(Ref_Temp,TxT);
Lcd_Out(2,1,"TEMP. READ: ");
Lcd_Out(1,13,TxT);
Lcd_Out(1,15,'C');
if(Ref_Temp>Temp_Ref){
PORTC.RC0=0,
PORTC.RC1=1;
}
if(Ref_Temp<Temp_Ref){
PORTC.RC0=1,
PORTC.RC1=0;
}
if(Ref_Temp==Temp_Ref){
PORTC.RC0=0,
PORTC.RC1=0;
}
}
}