User manual
LPCXpresso Experiment Kit - User’s Guide
Page 49
Copyright 2013 © Embedded Artists AB
7.5 Print Messages
So far the microcontroller has had limited possibilities to communicate with the user. Technically it
would have been possible to communicate information via the Morse code experiments (via a LED or a
buzzer) but it is not a very user friendly method and it would take time to communicate longer
messages.
In this experiment you will learn how to print messages from the program in the LPCXpresso IDE. No
breadboard work is needed for these experiments. The LPCXpresso IDE has support for something
called Semihosting. It is a term from ARM that indicates that part of the functionality is carried out by
the host. The host in this case is the PC, i.e., the LPCXpresso IDE. It is a very useful debug tool for
small systems that do not have a dedicated communication channel for outputting debug information.
It is very easy to enable Semihosting in a project. Figure 21 below indicates the project setting that is
needed to be carried out. Basically it is an instruction to use a special C runtime library. A library that
directs printf()-output to the LPCXpresso IDE.
Figure 21 – Selecting Semihosting C Library
7.5.1 Lab 4a: Semihosting and printf()
In this experiment you will learn how to print messages from the LPC111x microcontroller to the
console window in the LPCXpresso IDE. The code below outlines what is needed in order to use
printf(). Figure 22 below illustrates how the console window looks like when executing this code.
//Include needed libraries
#include<stdio.h>
int main(void)
{
printf(“\nThis is a first test...\n”);
printf(“that semihosting and printf() works - and it does!”);
while(1)
;
return 0;
}
1) Right-click on
project root and select
“Properties”
2) Select “C/C++ Build”
3) Select “Settings”
4) Select “Target”
5) Select “Redlib (semihost)”
6) Confirm selection