Microcontroller › PIC › 3 INPUT sensor PIC Programming › Could you please share
Could you please share exactly what kind of abnormality you have in the output?
I’ve tried to modify your code. Please try this also and update the result.
void main()
{
TRISA=0b01101; // Configure RA0,RA2,and RA3 as input sensor.
PORTA=0b00000;
TRISB=0b00000000; //Configure ALL PORTB as output
PORTB=0b00000000;
while(1) //Loop forever
{
if(PORTA.F2==1) //Analogue Distance Sensor
{
PORTB.F3=1; //Buzzer ON
delay_ms(400); //time delay wait for 0.4s
}
else
{
PORTB.F2=0; //Buzzer OFF
delay_ms(50); //time delay wait for 0.05s
}
if(PORTA.F3==1) //Water sensor
{
PORTB.F2=1; //Vibrator ON
delay_ms(400); //time delay wait for 0.4s
}
else
{
PORTB.F3=0; //Vibrator OFF
delay_ms(50); //time delay wait for 0.05s
}
if(PORTA.F0==0) //Dark sensor
{
PORTB.F4=1; //Blue LED ON
PORTB.F5=0; //RED LED OFF
PORTB.F6=0; //WHITE LED OFF
delay_ms(200); // time delay wait for 0.2s
PORTB.F4=0; //Blue LED OFF
PORTB.F5=1; //RED LED ON
PORTB.F6=0; //WHITE LED OFF
delay_ms(200);
PORTB.F4=0; //Blue LED OF
PORTB.F5=0; //RED LED OFF
PORTB.F6=1; //WHITE LED ON
delay_ms(200);
}
else
{
PORTB.F4=0; //Blue LED OFF
PORTB.F5=0; //RED LED OFF
PORTB.F6=0; //WHITE LED OFF
delay_ms(50); //time delay wait for 0.05s
}
}
}