float temp_res=0; float temp; const unsigned short VREF = 4.75; char address; char txt[4]; char FanStatus=0x66; // fals(f)=0x66 void main() { ANSEL = 0x02; //Configure AN1 pin as analog TRISA = 0x02; //Configure AN1 pin as input ANSEL = 0X00; //configure AN0 pin as digital TRISA = 0X00; //configure AN0 pin as an output pin TRISB = 0; //configure POrt B as an output port PORTB=0; ADC_Init(); //Initialize the ADC UART1_Init(9600); //Initialize the UART with 9600Kbps Baud Rate Delay_ms(100); // Wait for UART module to stabilize PORTA.f0 = 0; // FAN initially OFF while(1){ temp_res = ADC_Get_Sample(1); //Get temp readings from ADC module temp = (temp_res * VREF)/10.240; floatToStr(temp, txt); if (UART1_Tx_Idle()==1) // end if idel { UART1_Write_Text("z"); UART1_Write(FanStatus); UART1_Write_Text(txt); UART1_Write_Text("end"); } if (UART1_Data_Ready()==1) //If data is received { address=UART1_Read(); // read the address if(address==(0x7A)) //if the address=z { PORTA.f0 = !PORTA.f0 ; // switch FAN ON/OFF if(PORTA.f0==1) { FanStatus=0x74; //true } else if (PORTA.f0==0) { FanStatus=0x66; //fals } } } // end if ready delay_ms(10000); } // end while } //end main
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)