Microcontroller › PIC › whats wrong with my coding? › first you need to enable
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
}
}
}