Position: Index > Led Circuit >

Driving LEDs with LPC2148 microcontroller

2014-12-07 18:44  
Declaration:We aim to transmit more information by carrying articles . We will delete it soon, if we are involved in the problems of article content ,copyright or other problems.

Couple years ago I have purchased LPC2148 development board called BlueBoard form ngxtexhnologes. It is quite powerful board with ATM7TDMI series microcontroller which is considered an old guy comparing to Cortex ones. But still these are widely used and are powerful.

Development board has some handy features installed. 12MHz crustal allowing to run processor at full 60Mhz speed. Couple RS232 ports, VGA connector, PS/2 connector for keyboard or mouse, 20-pin JTAG, SD/MMC slot, USB B-type, 8 LEDs driven with serial-in parallel-out shift register, 2×16 LCD, buzzer, audio jack with amplifier, two programmable buttons and 256Kb of I2C interfaced EEPROM. Microcontroller itself has 512KB of internal flash and 32 8KB of RAM. All ports are accessible and any external hardware can be disconnected with jumpers. This is great board for prototyping and end application.

I decided to put up a simple project. And yes, you guessed – LEDs again. Blueboard website provides with code examples. Most of drivers are already written this makes our life much easier. Only minor modifications will be needed as their code is based on (or related to TNKernel real-time kernel). For now I just want to get rid of RTOS based code and make simple application.

Our project will be based on same tools as we used for STM32F103ZET6 development board. So no additional preparation is needed – just open Eclipse (CodeSourcery must be installed too). The only thing you will need is different firmware flasher as LPC2148 is NXP product. For this there is great program called Flash magic that uploads compiled code by using build in bootloader.

Project setup is nothing more than collection of files collected from different sources. These include linker scripts, start-up codes, makefile. You can find board drivers on NGX website within example code.

[You can download project package here that strobes all 8 LEDs here:LPC2148LED]

Lets see how these LEDs are controlled. As we mentioned above, LEDs are connected through serial to parallel shift register which is controlled via SPI interface:

For this we are going to need drive SPI peripheral of microcontroller and also drive register itself so we could access individual LEDs. For this we must include spi.h library that was already in example package. Originally there were separate source files for 74HC595N register and led. But this seems unnecessary while register and leds comes along, so I simply merged those libraries in to led.h and made a little cleanup to get rid of few rtos based functions.

After preparation we can write simple application that gives strobe effect on LEDs:

#include "type.h"
#include "hardware.h"
S32 main(void)
  return 1;

Here you can a HardwareInit() function from hardware.c, which simply takes care of setting up a PLL multiplier where 12MHz crystal frequency are multiplied to 60MHz that clocks MCU core. SPI peripheral is initialized here too.

Hope you find this information useful.

Reprinted Url Of This Article: