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 Recent Posts

  • Getting into an LED bulb April 21, 2026
  • understanding of resonance in time domain April 21, 2026
  • Beginner Questions About CNC Machines – G-code, Control Systems & Accuracy April 21, 2026
  • A Must-Watch Video Showing Dangerous Construction of Cheap Lithium-Ion Cells April 21, 2026
  • S1MJ ? April 20, 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