Before I can read data from a PICmicro input port I must set it to be an input. This is controlled by the TRISA and TRISB registers. If a given bit is set in either of these registers it means that the port is configured as an input. To use a port as an output we must clear the appropriate bit.
When the PICmicro starts up all the ports are configured as inputs. This is to stop the PICmicro from providing signals when it isn't supposed to.
The CPIC will indicate the input/output status of a pin by using an arrowhead underneath each port bit.
If the arrow points down towards the register display this indicates that the port is configured as an input. When the button is pressed for that port bit a 1 is sent to the appropriate bit in the port. The status indicator will turn red to indicate that 1 is being supplied and the value in the port will change accordingly.
The way that buttons work is not quite the same as the real PICmicro development board. In order to allow you to set more than one input at once (which would be impossible as you only have one mouse!) we have made our buttons toggle switches. Press the button once to set the input, and again to clear it. The indicator will allow you to keep track of what is going on.
If the arrow points up towards the status indicator this indicates that the pin is set as an output. The status indicator will turn red when the program sets the appropriate bit in the port. Note that when a port is configured as an output you are unable to change its state using the button.
If you step through the program you will see that the arrow for PORTA bit 0 will change to pointing up when the bottom bit of TRISA is clear. We clear the bit by loading a value into TRISA which has the bottom bit clear, in this case hex 0x1E (decimal 30).
To find out how the if condition works, click here