#include <htc.h>
void main (void)
{
while (1){
if (RA0 == 1 && RA1 ==0) // if input pin 0 is high and pin 1 low then
{ // turn pin 2 on delay for 5 ms and turn off agin
RA2 = 1;
_delay.ms(5);
RA2 = 0;
}
else if (RA0 == 0 && RA1 == 1) // if input pin 1 is high and pin 0 low then
{ // turn on pin 2 for 5 ms and off for 500 ms
RA2 = 1; // loop until pin 1 is low
_delay_ms(5);
RA2 = 0;
_delay_ms(500);
}
else
{
RA2 = 0;
}
}
}
I might not have been good at doing this at all but I think I need some sort of port declaration, I mean I have to say witch pin is input and output, and set the states as all low or something.
Like I said in the top Im starting back up with C programming Its been almost tow years since I last entered a compiler so I want to get back in there again.
Just noticed a few errors in your code. So, here is a version that compiles,
Code:
#include <htc.h>
__CONFIG (UNPROTECT & MCLRDIS & PWRTDIS & WDTDIS & INTIO & BOREN);
#define _XTAL_FREQ 4000000
void main (void)
{
GPIO = 0x00;
CMCON = 0x07;
TRISIO = 0b11111011; // GP2 is output
while (1){
if (GPIO0 == 1 && GPIO1 ==0) // if input pin 0 is high and pin 1 low then
{ // turn pin 2 on delay for 5 ms and turn off agin
GPIO2 = 1;
__delay_ms(5);
GPIO2 = 0;
}
else if (GPIO0 == 0 && GPIO1 == 1) // if input pin 1 is high and pin 0 low then
{ // turn on pin 2 for 5 ms and off for 500 ms
GPIO2 = 1; // loop until pin 1 is low
__delay_ms(5);
GPIO2 = 0;
__delay_ms(125);
__delay_ms(125);
__delay_ms(125);
__delay_ms(125);
}
else
{
GPIO2 = 0;
}
}
}