LED Blinking Using LPC1768

///LED Blinking Using LPC1768

LED Blinking Using LPC1768

Introduction

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.

Register Configuration

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.

GPIO Functionality LPC1768

GPIO functionalities

The table below shows each PINSEL register and its corresponding ports.

LPC1768 PIN SELECT registers

PINSELECT registers

FIODIR is the fast GPIO direction control register and it controls the direction of each port pin.

LPC1768 PORT Direction set

FIODIR register

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.

LPC1768 PORT SET

FIOSET register

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.

LPC1768 PORT CLEAR

FIOCLR Register

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).

Firmware

  • The following are the definitions that will be used for this program. We will be using one of the 8-bit ports, PORTD of OpenLab™ that contains pins 24 to 31 of PORT 1 of the LPC1768 ARM controller.

  • The next line sets the PINSEL3 register to 0 which results in selecting the primary function which is the GPIO functionality. PINSEL3 corresponds to Port1[31:16] bits. Since we are going to shift and blink LEDs starting from the PIN1.24 to PIN1.31, we are setting that part of the Port1 to GPIO. This step can be skipped because, by default, these pins will be performing the GPIO functionality. But, one must keep in mind that this step is relevant when an alternate functionality must be selected.

  • The next line selects the direction of the PORTD bits of OpenLab™ as output. Since we are giving out values to an LED, port pin direction should be set as output. PIN_D0 is the LSB of PORTD which is PIN1.24. Therefore, we must shift 0xFF, LSB times to the left for this operation to take effect.

  • We will be assigning the definition PIN_D0 to a random variable ‘i’ and increment the value each time.

  • And use it to set and clear the output of the corresponding LEDs in the OpenLab™.

Summary

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

DON’T MISS OUT UPDATES!
Be the first to get latest updates and exclusive content straight to your email inbox.
Stay Updated
Subscribe, it is quick.
We hate spam too. Give it a try, you can unsubscribe anytime.
Spread the love, share this

Leave A Comment

DON’T MISS OUT UPDATES!
Be the first to get latest updates and exclusive content straight to your email inbox.
Stay Updated
Subscribe, it is quick.
We hate spam too. Give it a try, you can unsubscribe anytime.
close-link
25% OFF - OpenLabPro Course
Use Coupon: CRS25UL

 
ARM Microcontroller Primer
Want to learn indepth programming, peripheral interfacing and driver development?
close-link
Launched: IoT online Course - 25% Off when you complete your order today.
Checkout Now
close-image

Subscribe To our Email Newsletter

Be the first to get latest updates and exclusive content straight to your email inbox.
Send me Tutorials and Guides
close-link