Hi all,
I am trying to set up a simple "if button is pressed, turn on led1 and turn off led2" and vice versa circuit. But for the life of me I can't get it to work properly.
I am using a pic16f690 chip with the lpc board and the pickit2.
What happens is RC0 led is lit unless I push the button(RA3). RA1 led stays off. I must be doing the if else statement wrong, but everything looks good.
My code looks like this:
#include <pic.h>
void init(void)
{
TRISA=0x8; // set RA3 as input
TRISC=0x00; // set PORTC as outputs
ANSEL=0; // set ports to digital
PORTC=0; // turn off all leds
}
void main(void)
{
init(); // initialize I/O ports
while(1) // loop forever
{
if(RA3==0) // if button is pressed
{RC0=1; // turn on led 0
RC1=0;} // turn off led 1
else // if button is not pressed
{RC1=1; // turn on led 1
RC0=0;} // turn off led 0
}
}
Thanks in advance
I am trying to set up a simple "if button is pressed, turn on led1 and turn off led2" and vice versa circuit. But for the life of me I can't get it to work properly.
I am using a pic16f690 chip with the lpc board and the pickit2.
What happens is RC0 led is lit unless I push the button(RA3). RA1 led stays off. I must be doing the if else statement wrong, but everything looks good.
My code looks like this:
#include <pic.h>
void init(void)
{
TRISA=0x8; // set RA3 as input
TRISC=0x00; // set PORTC as outputs
ANSEL=0; // set ports to digital
PORTC=0; // turn off all leds
}
void main(void)
{
init(); // initialize I/O ports
while(1) // loop forever
{
if(RA3==0) // if button is pressed
{RC0=1; // turn on led 0
RC1=0;} // turn off led 1
else // if button is not pressed
{RC1=1; // turn on led 1
RC0=0;} // turn off led 0
}
}
Thanks in advance