User manual
LPCXpresso Experiment Kit - User’s Guide
Page 41
Copyright 2013 © Embedded Artists AB
7.3.2 Lab 2b: GPIO and Bit Masking
As presented in Lab 1b there is hardware support in the GPIO peripheral block for accessing selected
bits, as opposed to accessing all of them. This is described in the LPC111x user’s manual, chapter
12.4.1 – Write/read data operations. In short, the LPC_GPIOx->DATA register can be accessed on
many different addresses. The address used to access the register determines which bit(s) that is/are
accessed.
The function prototype is presented below. Create a version of the function that utilizes the masked
read functionality. Also create a version of the function that utilizes the bit masking we have used in
previous labs.
/*****************************************************************************
** Function name: GPIOGetValue
**
** Descriptions: Read (bit)value in a specific bit position
** in GPIO portX(X is the port number.)
**
** parameters: port num, bit position
** Returned value: 0 if bit is not set, else a non-zero value (if bit is set)
**
*****************************************************************************/
uint8_t GPIOGetValue( uint32_t portNum, uint32_t bitPosi)
{
... //implemented either with “masked read” functionality in the GPIO hardware
... // or via direct bit masking with GPIOxDATA & (1 << bit)
}
Compare which functions is fastest. A simple method is to create a loop and call the function a million
times. Turn on a LED before starting the loop and turn it off after the loop. Manually clock the time the
LED is on. To get the execution time for one call, divide this LED-on-time with one million.
Place the function in file gpio.c.
7.3.3 Lab 2c: Logic between inputs and output
In this experiment we will introduce logic between the input (push-buttons) and the output (a LED and
a buzzer). Let’s begin with connecting two push-buttons, SW2 (which we already have) and SW3.
According to Figure 11 and Figure 12, SW3 is connected to signal GPIO_16-KEY, which in turn is
connected to PIO1_4. Figure 13 below illustrates how the connection can be done on the breadboard.
Create a program that reads the two push-buttons and turn on the LED only when both are pressed
simultaneous. Then change the logic so that the LED is on if only one of the push-buttons is pressed,
but not both.
The program structure will be the same as in Lab 2a and 2b, a forever loop. Read both inputs and then
calculate the output value and output it.