I run this program on the device and expect the LED patterns to change, indicating that a switch was pressed.
When I compile, write and test, PORTB always appears to be 0b00010000. Nothing seems to change weather the switch is on or off. Why? When I debug, the default state of RA0 or PORTA.F0 is 0 not 1 as described in many examples.
It may be that I accidentally powered this PIC device with 12 volts but there was no program written on it at that time.
I am trying to understand if this is hardware or software problem.
Code: Select all
void main()
{
TRISA = 1; // port a as input
TRISB = 0; // port b as output
PORTB = 0; // Turn OFF all LEDs
for(;;) // Endless loop
{
if(PORTA.F0 == 0) // Is switch pressed ?
{
PORTB = 0b00010000; // turns on pins - port B
}
else if (PORTA.F0 == 1)
{
PORTB = 0b10110000; // turns on pins - port B
}
}
}
Thank you.
PS:
My new declaration for this program looks like this:
Code: Select all
INTCON = 0b00000000;
PORTA = 1;
TRISA = 1; // port a as input
CMCON = 0b111;
CMCON = 1;
TRISB = 0;
PORTB = 0; // Turn OFF all LEDs
-------------------------------------------------------------------------------------------------------------------
I am all set.
I am ashamed to tell what was the problem.
It was me copying my program folder to desktop instead of creating a shortcut. Therefore I kept uploading the same malfunctioning .hex into my microcontroller.
Not a language or a hardware issue.
Thank you for your time.