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.
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.
#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
DATA_DIR = (0xFE << PIN_D0);
if(!((DATA_PIN >> PIN_D0)&0x01)) { while(!((DATA_PIN >> PIN_D0)&0x01)); // Prevent Debouncing DATA_CLR = (0xFE << PIN_D0); DATA_SET = (1 << i); i++; }
if(i > PIN_D7) i = PIN_D1;
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.