Microcontroller › PIC › 3 INPUT sensor PIC Programming › Try This & let me know the
Try This & let me know 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 |= 0b00001000; //Buzzer ON
delay_ms(400); //time delay wait for 0.4s
}
else
{
PORTB &= 0b11110111; //Buzzer OFF
delay_ms(50); //time delay wait for 0.05s
}
if(PORTA.F3==1) //Water sensor
{
PORTB |=0b00000100; //Vibrator ON
delay_ms(400); //time delay wait for 0.4s
}
else
{
PORTB &= 0b11111011; //Vibrator OFF
delay_ms(50); //time delay wait for 0.05s
}
if(PORTA.F0==0) //Dark sensor
{
PORTB |= 0b00010000; //Blue LED ON
PORTB &= 0b11011111; //RED LED OFF
PORTB &= 0b10111111; //WHITE LED OFF
delay_ms(200); // time delay wait for 0.2s
PORTB &= 0b11101111; //Blue LED OFF
PORTB |= 0b00100000; //RED LED ON
PORTB &= 0b10111111; //WHITE LED OFF
delay_ms(200);
PORTB &= 0b11101111; //Blue LED OF
PORTB &= 0b11011111; //RED LED OFF
PORTB |= 0b01000000; //WHITE LED ON
delay_ms(200);
}
else
{
PORTB &= 0b00000000;
delay_ms(50); //time delay wait for 0.05s
}
}
}