LEDs

Till now we were bothering with the project configuration and the microcontroller initialization. We did a very important work, but we haven't seen any output yet. Now comes the funniest part of our development. We will turn on the onboard LEDs.

 

Let's add the lpc4350_db1.h file to our project. This file contains definitions for LEDs and push buttons present on the LPC4350-DB1 demoboard (and LPC4357-DB1). As always we open the Add Files dialog box using the [Project | Add Files...] menu. Navigate to the lpc43xx\Boards folder and open the  lpc4350_db1.h file. 

We also need to add the lpc43xx\Drivers\include\lpc43xx_gpio.h  and lpc43xx\Drivers\source\lpc43xx_gpio.c files. These files contain functions for General Purpose Input Output (GPIO) interface.

Don't forget to include the lpc4350_db1.h  and lpc43xx_gpio.h files in our main.c file.

Let's turn on the D2 LED - the red LED near to USB connector. We need to use the following constants from the lpc4350_db1.h file:

/*******************************************************************************
 *                 LEDs
 ******************************************************************************/
#define D2_SCU_PIN 6
#define D2_SCU_PORT 6
#define D2_GPIO_PIN 5
#define D2_GPIO_PORT 0
#define D2_GPIO_MASK (1 << D2_GPIO_PIN)

 

 

Below is the content ouf our main.c file at current stage:

#include "LPC43xx.h"
#include "lpc4350_db1.h"
#include "lpc43xx_cgu.h"
#include "lpc43xx_scu.h"
#include "lpc43xx_gpio.h"

int main()
{
  SystemInit();
  CGU_Init();

  scu_pinmux(D2_SCU_PORT, D2_SCU_PIN, MD_BUK, FUNC0);
  GPIO_SetDir(D2_GPIO_PORT, D2_GPIO_MASK, 1);
  GPIO_SetValue(D2_GPIO_PORT, D2_GPIO_MASK);
  
  return 0;
}