LPC1768 is a Cortex-M3 based microcontroller. It features a high level of integration and minimal power consumption. The ARM-based microcontrollers also feature advanced debug features as well as support block integration. The operating frequency of LPC1768 would go up to 100 MHz. They are pin compatible to the 100 pins LPC236x ARM7-based microcontroller series. This chapter deals with the firmware details of interfacing an LED with LPC1768 microcontroller device.
There are five registers in an LPC1768 device that are associated with the GPIO functionality. They are GPIO pins select register, GPIO direction control register, a fast port output set register, fast port output clear register, and fast port pin value register. With the help of these registers, the digital signals are transmitted.
PINSEL is the pin select function register. The GPIO pins have multiple functions; a minimum of one to a maximum of four. The PINSEL register can be configured to choose the required function. Each pin is provided with two bits as there can be up to four functions to choose among. So, at least two PINSEL registers are required to configure the port pins. The first sixteen pin functions of PORT0 can be configured by the 32 bits of PINSEL0 register whereas the other 16 bits are configured using the 32 bits of the PINSEL1 register. The below table shows how to choose the required function for a particular pin using two bits of the PINSEL register.
The table below shows each PINSEL register and its corresponding ports.
FIODIR is the fast GPIO direction control register and it controls the direction of each port pin.
FIOSET is the fast port output set register which controls the state of output pins. While writing 1s produces highs at the corresponding port pins, writing 0s has no particular effects. Reading this register, it is the current contents of the port output register which is being returned, not the physical port value.
FIOCLR is the fast port output clear register and this register controls the state of output pins. While writing 1s produces lows at the corresponding port pins, writing 0s has no particular effect.
FIOPIN is the fast port pin value register and is used for both reading and writing data to and from the port. Writing to this register helps to place corresponding values in all bits of the particular port pins.
This register is used for both reading and writing data from/to the port.
Output: Writing to this register places corresponding values in all bits of the particular PORT pins.
Input: The current state of digital port pins can be read from this register, regardless of pin direction or alternate function selection (as long as pins are not configured as an input to ADC).
#define DATA_DIR LPC_GPIO1->FIODIR #define DATA_SET LPC_GPIO1->FIOSET #define DATA_CLR LPC_GPIO1->FIOCLR #define DATA_PIN LPC_GPIO1->FIOPIN #define PIN_D0 24 #define PIN_D1 25 #define PIN_D2 26 #define PIN_D3 27 #define PIN_D4 28 #define PIN_D5 29 #define PIN_D6 30 #define PIN_D7 31
LPC_PINCON→PINSEL3 = 0 ;
DATA_DIR = (0xFF << PIN_D0);
i = PIN_D0;
DATA_SET = (0x01 << i); delay_ms(250); DATA_CLR = (0x01 << i); i++;
Thus we have learned how to blink 8 LEDs and shift the outputs periodically using the LPC1768 microcontroller. The sample code based on this tutorial is available in the code library section under the ARM. Use the following link: Code Library