I cannot understand why my code won't work. It works when I set the condition PORTA == 0x00
but not when PORTA == 0x01
. How do you check if a bit is high? Below is my code and my schematic (Crystal frequency is 4MHz).
#include<xc.h>
void main(){
int cnt;
int delay_cnt;
TRISA = 1; // PortA as input
TRISB = 0; // PortB as output
PORTB = 0x00; // Initialize LED as off
for(;;){ // Infinite loop
if(PORTA == 0x01){
for(cnt=0;cnt<3;cnt++){
PORTB = 0x01; // Turns on LED
for(delay_cnt=0;delay_cnt<10000;delay_cnt++);
PORTB = 0x00; // Turns off LED
for(delay_cnt=0;delay_cnt<10000;delay_cnt++);
}
}
}
}