2 GPIO Read/Write Example
This example describes a basic configuration of an input pin (connected to a button and an output pin) used to turn an LED on and off. To implement this example, one PORT pin is configured as a digital input and another pin is configured as an output.
The input pin is connected to a button and the output pin is connected to an LED. The value of the input pin is read continuously through polling.
There are two possibilities:
- The read value is logic
‘
1
’ (the input pin is pulled high), meaning the button is released. The microcontroller drives the output high, therefore the LED is off. - The read value is logic
‘
0
’ (the input pin is pulled low), meaning the button is pressed. The microcontroller drives the output low and the LED is on.
For this example, the RE2 pin is configured as input and connected to a button while the RE0 pin is configured as output and connected to an LED.
- System clock initialization
- Port initialization