if (temp2 >35 && temp2<40 div="">
{
//go 100% fan speed mode
_RB14=1;
} else if (temp2>39){
// alarm triggled (all at secondary loop 2)...
_RB14=1;
key1=0;// stop this loop and jump to secondary loop 2
key2=1;// enable key to secondary loop 2
T1CON=0x0000; //timer off and no more interrupt allowed
}
}
}
if(count==6)//at sixth time entering interrupt togger x
{
x=~x;
}else
if(count==2)//at second time entering interrupt togger y
{
y=~y;
}else
if(count==10)// togger both pins at tenth times entering interupt
{
x=~x;
y=~y;
count=0;
}
//-------------------------------------------------------------------------------------------------------------
_T1IF=0;
}
void initADC( )
{
AD1CON1 = 0x00E0; // auto convert after end of sampling
AD1CSSL = 0; // no scanning required
AD1CON3 = 0x1F02; // max sample time = 31Tad, Tad = 2 x Tcy = 500ns >75ns
AD1CON2 = 0x0000;// use MUXA, Vss and Vdd are used as Vref+/-
AD1CON1bits.ADON = 1; // turn on the ADC
}
int readADC( int tsensor)
{
AD1CHS =0x0000; // input at AN0
AD1CON1bits.SAMP = 1; // start sampling, auto-conversion will follow
while (!AD1CON1bits.DONE); // wait to complete the conversion
return ADC1BUF0; // read the conversion result
}
int read_averageADC()
{
int temp,j;
initADC();
temp = 0;
T3CON = 0x8030;
for ( j= 16; j >0; j--)
{
TMR3 = 0;
temp += readADC( SENSOR);
}
temp >>= 4; //get the average of 16 readings
temp = temp*330/1024; //temp*330/1024
return temp;
}
//function used to get reminder and store in array
void convert(int no, char base)
{int i;
for(i=1;no!=0;i++) {
di[i]=no%base;
no=no/base;
}
}
//switching method use for convert the character stored in array
void display(char number)
{
switch(number){
case 0:{lcd_string("0");break;}
case 1:{lcd_string("1");break;}
case 2:{lcd_string("2");break;}
case 3:{lcd_string("3");break;}
case 4:{lcd_string("4");break;}
case 5:{lcd_string("5");break;}
case 6:{lcd_string("6");break;}
case 7:{lcd_string("7");break;}
case 8:{lcd_string("8");break;}
case 9:{lcd_string("9");break;}
case 10:{lcd_string("A");break;}
case 11:{lcd_string("B");break;}
case 12:{lcd_string("C");break;}
case 13:{lcd_string("D");break;}
case 14:{lcd_string("E");break;}
case 15:{lcd_string("F");break;}
default:{lcd_string("?");break;}
}}
//functiom below is main function for converting analogue signal from temperature sensor
//and display on LCD
void converter(){
AD1PCFG = 0x1FFE; //Set all pins to analogue input
TRISB &= 0x0000; //Port B set to output for D4,D5,D6 and D7
TRISA = 0x0001; //Port A set to output for RS and E and input for AN0
temperature[0]=read_averageADC(); //10mV per Celsius
temperature[1]=(int)(1.8*temperature[0]+32); //Celsius to Fahrenheit 320
temperature[2]=(int)(temperature[0]+273); //Celsius to Kelvin 2731.5
lcd_line(0,0);
lcd_string("Temp:");
lcd_line(5,0);
lcd_string("=");
lcd_line(6,0);
convert(temperature[count2],10);
for(i=3;i>=1;i--) // display the converted value in array [reminder 3,reminder 3,reminder 3]
{
display(di[i]);
}
for(i=1;i<4 div="" i="">
{
di[i]=0;
}
if(count2==0){
lcd_char(0xdf);
lcd_string("C");
lcd_line(0,1);
}else
if(count2==1){
lcd_char(0xdf);
lcd_string("F");
}else if (count2==2)
{
lcd_char(0xdf);
lcd_string ("K");
}
//temperature condition display
lcd_line(0,1);
if(temperature[0]<27 div="">
lcd_string("Good ");
}
else
if(temperature[0]>26 &&temperature[0]<35 div="">
lcd_string("Moderate ");
}
else
if(temperature[0]>34 && temperature[0]<40 div="">
lcd_string("Hot ");
}
else
if(temperature[0]>39){
lcd_string("Caution ");
}
}
40>
35>
27>
4>
40>