This tutorial is intended to give a brief picture of programming the Philips lpc210x ARM7 microcontroller. The material presented here is solely for the purpose of documentation. Nevertheless, the codes provided here are freely available. Again, the contents are not proved to be correct, use at your own risks!
The Philips ARM7 Microcontroller LPC210x series is a high-performance while low-cost embedded processor. It includes several useful modules, like I2C, RTC, PWM, UART etc. It is quite convenient for embedded system designer to use it as an all-in-one solution. I decide to use it in performing certain experiements on ARM architecture. I will also make it as my upcoming Robot platform. OK, introduction is enough, lets' getting started!
First of ALL, we have to get a development board!! Right?
There is a complete list of development boards on Philips Website. Check it out yourself! After walking through the lists, I decide to use the OLIMEX LPC-MT. It includes LCD module, Relay, buzzer, RS232 interface circuits etc. It is quite handy for me because it is quite difficult and expensive to get the electronic parts in Hong Kong. For details, please check the OLIMEX website: -- OLIMEX --
Let's have some pictures on IT!!
So far so good, I spent US$80 + US$1X(airmail) dollars to have my fully tested ARM7 development board!
Let's start with the software part. If you buy other developemnt tools listed out in Philips website, some may include the software development tools like compiler, IDE, Jtag tools etc. The LPC-MT1 doesn't come with any software developement tools, software related documentations and sample codes. Luckily, ARM processor has been well-known in GNU world! We can get all the tools freely avaliable on the internet! Before going to the programming parts, Let's list out some useful websites:
To get the first experience of the programming of microcontroller, the first step for me is programming the LED. It is the easiest and fastest way to get started! Moreover, it is easier for me to check the result without a multimeter on hand!
The GNU tools are portable; you can use Linux system or Windows system with Cygwin. I love the fancy Philips ISP tool, so I choose to use Windows as developement platform. For Linux users, you can easily prepare your GNU toolchain for ARM, please read the tutorial by Bill Gatliff.
LED programming in Assembly
After browsing FreeWing's web, he is so nice to present many ARM assembly codes on LPC210x. Before going to touch the GNU C compiler, let's play around with assembly. We just need to have assember,linker and objcopy-er to generate binary file from our assembly codes. FreeWing have packed the cygwin.dll, arm-elf-as,arm-elf-objcopy,arm-elf-ld for us to ease our job. He also provides a linker script and some programming examples.
I used FreeWings' Nokia LCD codes as my reference. I cleaned up a bit and make my own blinking LED example for OLIMEX-LPC-MT board. Please download FreeWings' package to assemble and link your assembly program.
The steps for driving GPIO in LPC210X:
@; REGISTER ADDRESS DECLARATION PINSEL0 = 0xE002C000 PINSEL1 = 0xE002C004 IOPIN = 0xE0028000 IODIR = 0xE0028008 IOSET = 0xE0028004 IOCLR = 0xE002800C .................................. ldr r1,=PINSEL0 @; PINSEL0 controls pin 0-15, @; PINSEL1 controls pin 16-31 ldr r2,=0x00000000 @;default GPIO function 00 @; GPIO-12 LED (check OLIMEX's schematic) str r2, [r1]
ldr r1,=IODIR ldr r2,=0x00001000 @; 0-INPUT 1-OUTPUT 0:31 (12 -LED) str r2, [r1]
@; ON LED (GPIO-12) (GPIO LOW-ON) ldr r0,=IOCLR ldr r1,=0x00001000 @; CLR 12 str r1, [r0,#0x00] @; OFF LED (GPIO-12) (GPIO HIGH-OFF) ldr r0,=IOSET ldr r1,=0x00001000 @; SET 12 str r1, [r0,#0x00]
Isn't it easy? You can download my code here: LED.S or binary here: led.hex. Download the led.hex to your lpc210x by ISP tool. You will see the blinking LED!
LED programming in C
Sometimes, it is difficult and inefficient for programming in Assembly. We may want to use C/C++ for fast prototyping. Firstly, we have to prepare the GNU toolchain for ARM (compiler,assembler,linker ..etc). You can build your own or just download the toolchains from GNUARM website. For me, I downloaded GNU toolchain for Cygwin Binary setup packages to ease the installation on Windows.
After the installation complete, we have to prepare the linker script and C runtime ( or crt0.s) startup file. In order to use C languages, we have to initialize the stack pointers, memories before running our codes. Luckly, you can find them on the internet, you can download it here: lpc2106_gcc.zip(I downloaded it in yahoo lpc group. Based on the License Agreement inside, I can distribute it freely. If you are not happy with it, please send me an email and I will remove it as soon as possible.) The package includes a LED testing program already, or you can download my simplified version: led.c and test it on your LPC-MT board.
We have the C programming environment ready now. You can write your codes in C/C++ and you can leave this page if you just want to get started. Now, I am going to program the LCD bundle in the LPC-MT board.
The LCD is 16x2 character based LCD. To save I/Os, only 4 data pins are used in this design. This kind LCD is well-known and widely used. There are many programming information on the web, I just followed these two links: 8-bit mode: LCD tutorial #1 4-bit mode: LCD tutorial #2
You can download my lcd routines here: lcd.c and lcd.h
It is a prelimiary program; I haven't tested and finished it completely. You may modify it if you wish to.
If your development board is using different I/O pins connecting to the LCD, just modify the IOMask defined
in header file should be fine. If you want to port in to other platforms, then you may also need
to modify lcd_init() function.
I added some codes for handling the buttons on LPC-MT and released here as a demo program. It should work fine on your LPC-MT, too. When you pressed the button, the button number will be displayed on LCD. You can of course modify the button function to trigger the buzzer, LED etc.
Thanks for Martin Thomas, I can program my LPC-MT easily on Windows now using WinARM. Here is the quick start guide : go go
This is the music box demo that modified from the example in WinARM called blinky_switch_irq, It uses Timer0 to measure accurate wait time, I changed a bit to make it output specific waveform to the buzzer on LPC-MT. The Music box can play five different tones:
Button 1 - "C" Button 2 - "D" Button 3 - "E" Button 4 - "F" Button 5 - "G" When you press the button 1 on the LPC-MT, it generates a "C" tone. Enjoy!! demo video (mpeg2)
I will write more about UART/PWM/RTC when I have time. Thanks for your patience. You can also visit my Embedded Processor Collections
Sometimes, I received email questions from developers around the world. I think may be it is a good idea to write a FAQ here. Please send email to me if you have any question, I will try my best to answer you.