i'm programing sensors on PIC16F15323-I/P so far i added two sensors ( water level sensor, voltage sensor) the problem is when i add the second sensor it swapped between the inputs the water level sensor takes the output for the voltage sensor and the voltage sensor takes the output of the water level sensor i removed one sensor from the code at the time the output is good for both of them but togather is not. i don't understand what is the problem of my code if anyone can help me please
this is the code
#include "Config.h"
int result=0;
int result1=0;
void pins ()
{
TRISC2 = 1;// set RC as voltage sesnor input
TRISC5 = 0;// Green LED
TRISA0 = 0;//relay output
TRISC1 = 0;// water level sensor led
TRISA1 = 1;//water level sensor input
}
void voltage_sensor ()
{
int result1=0;
// Select convertion clock 16Mhz = 101
ADCON1bits.ADCS0=1;
ADCON1bits.ADCS1=0;
ADCON1bits.ADCS2=1;
// to store data ( analog channel)
ADCON0bits.CHS0=0; // store the address for analog pin RC2 voltage sensor
ADCON0bits.CHS1=1;
ADCON0bits.CHS2=0;
ADCON0bits.CHS3=0;
ADCON0bits.CHS4=1;
ADCON0bits.CHS5=0;
// result of input
ADCON1bits.ADFM=1;
//port configuration
ADCON1bits.ADPREF0=0;
ADCON1bits.ADPREF1=0;
//set statues bit
ADCON0bits.GOnDONE=1;//start the conversion
//switch on ADC
ADCON0bits.ADON =1;// turn on the ADC
ADCON0bits.GOnDONE==1;// start the conversion
result1=((ADRESH<<8)+ADRESL);// to turn on all the 10 ADC
if (result1<800)
{
PORTC = 0b100000; // PORTC1 green light
PORTA = 0b000000;//PORTA0 relay
}
else
{__delay_ms(10000);
PORTC = 0b000000;
PORTA = 0b000001;
}
}
void watersensor ()
{
int result=0;
// Select convertion clock 16Mhz = 101
ADCON1bits.ADCS0=1;
ADCON1bits.ADCS1=0;
ADCON1bits.ADCS2=1;
// to store data ( analog channel)
ADCON0bits.CHS0=1;
ADCON0bits.CHS1=0;
ADCON0bits.CHS2=0;
ADCON0bits.CHS3=0;
ADCON0bits.CHS4=0;
ADCON0bits.CHS5=0; // store the address for analog pin RA1
// result of input
ADCON1bits.ADFM=1;
//port configuration
ADCON1bits.ADPREF0=0;
ADCON1bits.ADPREF1=0;
//set statues bit
ADCON0bits.GOnDONE=1;//start the conversion
//switch on ADC
ADCON0bits.ADON =1;// turn on the ADC
ADCON0bits.GOnDONE==1;// start the conversion
result=((ADRESH<<8)+ADRESL);// to turn on all the 10 ADC
if (result>550)
{
PORTC = 0b000010; // PORTC1
}
else
{
PORTC = 0b000000;
}
}
void main()
{
pins();
while(1)
{
__delay_ms(1);
{
voltage_sensor(result1);
result1=0;
}
__delay_ms(1);
{
watersensor(result);
result=0;
}
}
}