Academic Program

Digital Inputs

Digital Inputs

Making a Pin a Digital Input Pin

To configure a pin as a digital input, '1's need to placed in the corresponding TRISxregister bits.

 

Reading a Digital Pin

The value for each input pin can be observed by reading the corresponding PORTxregister. If the voltage level on a particular pin is above the input threshold the bit in the PORTx register associated with the pin will contain a '1'. Voltages below the threshold will contain a '0'.

Writing to a LATx register bit of a pin configured as an input will not affect the pin value.

 

Example code:

This sample program sets up RA3 (PORTA bit 3) as a digital input pin. The program then continually monitors the value of RA3. When RA3 goes high program control is transferred to an exception routine.