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 / first you need to enable

first you need to enable

|

Microcontroller › PIC › whats wrong with my coding? › first you need to enable

June 22, 2011 at 11:18 am #6370
romel emperado
Participant

first you need to enable PORTA as input by changing the value of CMCON register.. check the datasheet of your device.

 

 

your conditional statement is inside the while(1) loop, so if you release you button the value of the port will change and it will not satisfy your needs.. put also a pull down resistor to your input so that will toggle to 1 when the button is pressed.

 

just make a flag that the button is pressed.. do it like this

 

#include<htc.h>  // you dont need to include pic.h when htc.h is there..

 

// dont forget to set the proper configuration bits.

 

void main()
{
    bit x = 0, y= 0;;
    //your I/0 initiallization here

  // dont forget to set CMCON
    
    while(1)
    {
        if(RA0 == 1)
        x = 1; //set as flag when RA0 is high
       
        if(RA1 == 1)
        y = 1;
       
        if(x == 1)
        {
            //led is on
            //relay is on
            // put your delay here
            x= 0; //clear your flag
        }
       
        if(y == 1)
        {
            //led is off
            //relay is off
            // put your delay here
            y= 0; //clear your flag
        }
       
    }

}

 

 

RSS feed: Recent Posts Recent Posts

  • Will this solenoid actuator work as intended? September 13, 2026
  • NE602/SA602 Bias and Buffer circuit September 13, 2026
  • Rotary encoder with push function September 12, 2026
  • How much does generator frequency stability matter for sensitive electrical equipment? September 12, 2026
  • differential line loss question September 11, 2026

Stay Up To Date

Newsletter Signup
EngineersGarage

Copyright © 2026 Arrowfly 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 Arrowfly
Privacy Policy | Advertising

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