EngineersGarage

  • Engineers Garage Main Site
  • Visit our active EE Forums
    • EDABoard.com
    • Electro-Tech-Online
  • Projects & Tutorials
    • Circuits
    • Electronic Projects
    • Tutorials
    • Components
  • Digi-Key Store
    • Cables, Wires
    • Connectors, Interconnect
    • Discrete
    • Electromechanical
    • Embedded Computers
    • Enclosures, Hardware, Office
    • Integrated Circuits (ICs)
    • Isolators
    • LED/Optoelectronics
    • Passive
    • Power, Circuit Protection
    • Programmers
    • RF, Wireless
    • Semiconductors
    • Sensors, Transducers
    • Test Products
    • Tools
  • Advertise
You are here: Home / Replies / Try This & let me know the

Try This & let me know the

|

Microcontroller › PIC › 3 INPUT sensor PIC Programming › Try This & let me know the

May 10, 2012 at 5:19 am #7715
Amrith
Participant

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
        }
    }
}

RSS Recent Posts

  • The Analog Gods Hate Me July 14, 2025
  • Impact of Tariffs on PCB Fab July 14, 2025
  • More fun with ws2812 this time XC8 and CLC July 14, 2025
  • I Wanna build a robot July 14, 2025
  • Wierd makita battery July 14, 2025

Stay Up To Date

Newsletter Signup
EngineersGarage

Copyright © 2025 WTWH Media LLC. All Rights Reserved. The material on this site may not be reproduced, distributed, transmitted, cached or otherwise used, except with the prior written permission of WTWH Media
Privacy Policy | Advertising | About Us

Search Engineers Garage

  • Engineers Garage Main Site
  • Visit our active EE Forums
    • EDABoard.com
    • Electro-Tech-Online
  • Projects & Tutorials
    • Circuits
    • Electronic Projects
    • Tutorials
    • Components
  • Digi-Key Store
    • Cables, Wires
    • Connectors, Interconnect
    • Discrete
    • Electromechanical
    • Embedded Computers
    • Enclosures, Hardware, Office
    • Integrated Circuits (ICs)
    • Isolators
    • LED/Optoelectronics
    • Passive
    • Power, Circuit Protection
    • Programmers
    • RF, Wireless
    • Semiconductors
    • Sensors, Transducers
    • Test Products
    • Tools
  • Advertise