Push Button Interfacing with LPC1768

///Push Button Interfacing with LPC1768

Push Button Interfacing with LPC1768

Introduction

Interfacing a push button with the LPC1768 is another simple application like the LED blinking that makes use of the GPIO functionality of the LPC1768. An introduction to the basic functionalities and the GPIO register configuration in the LPC1768 were provided in the tutorial for LED Blinking along with useful tables. Click To Learn More. In this tutorial, we will read a pulse generated by a push button and we will shift and switch ON an LED. For each pulse generated a different LED will be turned ON. This chapter deals with the firmware details of interfacing a push button with LPC1768 microcontroller device.

Working

Our aim here is to read a pulse from a push button interfaced with the GPIO pin – PIN1.24, of the LPC1768 ARM controller. The output generated will be reflected across 7 different LEDs. In the OpenLab™ platform, PORTD (PIN1.24 to PIN1.31), will be used for this tutorial as the GPIO port. A pulse from the input pin – PIN1.24, which is also the LSB of PORTD will be used to determine the states of the remaining LEDs of PORTD. Each pulse turns on a single LED. On the next pulse, the next LED will be turned ON and the previous LED is turned OFF. This operation continues creating a continuous round shifting sequence. The input pin is pulled up by the software when it is configured as an input pin. When the button is pushed, this PIN is driven LOW and when it is released, the PIN goes back to its default state, thereby making the response of the PIN as ACTIVE-LOW.

Push Button LED Interfacing LPC1768

Image for Illustrative Purpose Only

Firmware

  • The following definitions will be used in the code for this tutorial.

  • The first line of code should be to set every pin to its appropriate functionality, using the PINSEL register. In our code, the only operation that we perform with our interfaced pins are GPIO operations, By default, these pins are selected for GPIO function and therefore, it is ok to skip this step.
  • Next, we must set the direction of PIN1.24 as input and PIN1.n as outputs, where n = 25 to 31.

  • Now, we must continuously check for a pulse from the switch connected to the pin – PIN1.24. Once a pulse is detected, the system encounters an infinite while loop that is used to prevent a common hardware error. This error is caused when the software or the hardware detects multiple pulses upon a single opening or closing event in the circuit. The workaround for this problem is commonly referred to as debouncing. Upon the initial change from the default state (HIGH to LOW in our case), the software detects this change and then waits continuously in a while loop till the hardware goes back to its default state.
    Once the necessary input PIN returns to its default state, we will clear all the previous states from the output PINS and then turn ON the first LED. Initially, the random variable i is given the value of the first pin – PIN_D2. For every successive pulse, the same process continues and the next LED will glow.

  • Once the final LED is turned on, we must ensure that the next pulse would cause the first LED to glow again. The following line performs this operation.

Summary

We have learned a simple program to interface a push button with the LPC1768 to turn ON/OFF, multiple LEDs
The sample code for this tutorial will be available in the Code Library under the section ARM.

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