As the question above, my project want to replace ultrasonic port with gas sensor(tgs2600) .So i put PR15 program into PR23 programming PIC16F877A.
if (!sw2) // if button SW2is pressed
{
while(!sw2); // wait until button is released
switch(m) // check what is the current mode, execute the mode
{
case 0 : line_follow(); // mode 1 : line follow
break;
case 1 : wireless_xbee(); // mode 2 : wireless xbee mode
break;
case 2 : analog_sen(); // mode 3 : analog sensor mode
break;
case 3 : gas_sensor(); // mode 4 : gas sensor mode
break;
case 4 : SKPS_PScon(); // mode 5 : PS2 Controller Mode
break;
default : ;
void gas_sensor()
{
unsigned char temp; //declare a temporary variable for reading ADC
lcd_clr();
lcd_goto(0); //set lcd cursor to location 0
send_string("Gas Sensor "); //display "Gas Sensor"
temp=read_ad(0); //read AN0 (Gas Sensor)
lcd_goto(20); //set lcd cursor to location 20
send_num(temp); //display the analog value of the gas sensor
}
unsigned char read_ad(unsigned char channel) //fucntion read analog input according to the given channel
{
unsigned char result; //declare a variable call result
ADGO=1; //start ADC convertion
while(ADGO); //wait for ADC convertion to complete
result=ADRESH; //read the result
return result; //return the result
}
But when i load these code..the gas sensor does not update the value even i put smokes on the sensor...what should i do with the coding.Please help.