Professional Documents
Culture Documents
GPIO in Cortex-M3 LPC1768 Microcontroller is the most basic peripheral. GPIO, General Purpose Input Output is what let’s your microcontroller be something more
than a weak auxiliary processor. With it you can interact with physical world, connecting up other devices and turning your microcontroller into something useful.
GPIO has two fundamental operating modes, input and output. Input let’s you read the voltage on a pin, to see whether it’s held low(0V) or high(3V) and deal with that
information programatically. Output let’s you set the voltage on a pin, again either high or low.
Every pin on LPC1768 can be used as GPIO pin and can be independently set to act as input or output. In next tutorial we’ll get you into how to achieve these goal. I
mean reading the status of switch and making LED blink. But for now we only have to look at basics, which is very important to understand before we go and build
application. Depending on LPC17xx version the pinout maybe different. Here we’ll focus on 100 pin LPC1768 as an example. Please keep LPC1768 User Manual with
you [Chapter: 9, Page No:129]. pins on LPC1768 are divided into 5 groups (PORTs) starting from 0 to 4. Pin naming convention: P0.0 (group 0, pin 0) or (port 0, pin 0).
Each pin has 4 operating modes: GPIO(default), 1st alternate function, 2nd alternate function, 3rd alternate function. Almost all GPIO pins are powered automatically
so we don’t need to turn them on always. Let’s have a look at details about configuration of these GPIO port pins.
…….
……..
……..
………
……..
NOTE: some register bits are reserved and are not used to control a pin for example,
00 GPIO Function
01 1st alternate function
Example:
To set pin 0.3 as ADC channel 0.6 (2nd alternate function, set corresponding bit to 10)
Register LPC_GPIOn –> FIODIR [31:0] control the pin input/output, where ‘n’ stands for pin group (0-4). To set a pin as output, set the corresponding bit to ‘1’. To set a
pin as input, set the corresponding bit to ‘0’, by default, all pins are set as input (all bits are 0).
Example:
LPC_GPIOn –> FIOSET is used to turn a pin to HIGH. Register LPC_GPIOn –> FIOCLR is used to turn a pin to low. To turn a pin to digital ‘1’ (high), set the corresponding
bit of LPC_GPIOn –> FIOSET to 1. To turn a pin to digital ‘0’ (low), set the corresponding bit of LPC_GPIOn –> FIOCLR to 1.
Example
Register LPC_GPIOn –> FIOPIN stores the current pin state. The corresponding bit is ‘1’ indicates that the
Example
Note: write 1/0 to corresponding bit in LPC_GPIOn –> FIOPIN can change the output of the pin to 1/0 but
it is not recommended. We should use LPC_GPIOn –> FIOSET and GPIOn –> FIOCLR instead.
…..
Please see LPC_PINCON –> PINSELn for the full list [Page No: 114].
01 Repeater Mode
Example:
By default all pins which are set as input has internal pull-up on (00).
Pages: 1 2