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 / Could you please share

Could you please share

|

Microcontroller › PIC › 3 INPUT sensor PIC Programming › Could you please share

May 3, 2012 at 5:52 pm #7582
AJISH ALFRED
Participant

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

RSS Recent Posts

  • Some opamp advice please April 12, 2026
  • isolating S-params in of PCB board without connectors April 11, 2026
  • want help with microprocessor April 11, 2026
  • Voltage comparator circuit verification April 11, 2026
  • Integrating 0–5V ECU Signals into a Double-DIN Setup – Module vs Custom Head Unit? April 11, 2026

Stay Up To Date

Newsletter Signup
EngineersGarage

Copyright © 2026 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