User manual
LPCXpresso Experiment Kit - User’s Guide
Page 37
Copyright 2013 © Embedded Artists AB
/*
* Delay by executing a given number of NOPs.
*/
void
delayNops(uint32_t nops)
{
volatile uint32_t i;
for (i = 0; i < nops; i++)
asm volatile ("nop");
}
About how many NOPs are needed for a 1 second delay? ______________________________
What does this tells you about the execution speed of the LPC111x? ______________________
Note that delay loops like this should never be used in real programs. All processor execution time is
“lost” in the loop and no other useful work is done. Also, the delay can vary depending on what other
parts of the system do (for example how much time is spent in interrupt routines, which will be
introduced later on). Later on we will explore other method of creating exact delay functions, so for
now, the loop method will have to do.
Create a function that delays execution a specified number of milliseconds (as input parameter). Place
the function in a separate file delay.c. After that, create the program that double-flash the LED
according to the specification above.
Now can be a good time to get acquainted a bit more with the debugger, specifically single stepping.
This means that the debugger let the microcontroller execute one statement at a time, and stops after
every line. Note that for this to work the compiler optimization most not be turned on too heavily. –O0
and –O1 is typically what work. More optimization will rearrange the code so there are no clear
boundaries between the source code statements (= rows in the source code).
Instead of pressing the Start/Resume button it is possible to press the Step Over or Step Into
buttons. Both “step” buttons will stop execution after the current statement. The difference is that if the
statement involves a function call, Step Over will not single step through all statements in the function
that is called. Step Into will do just this.
The current experiment exemplified just perfect where the different is. When hitting the delay function it
is best to Step Over, instead of into it. Single stepping through all the loop iterations would take
forever.
Add a loop counter in the forever loop. Set a breakpoint in the forever loop in main() so that execution
halts every loop iteration. Verify that it is possible to get the value of the loop variable by hovering over
the variable. Remove the breakpoint and test single stepping, with both Step Over and Step Into.
Figure 10 – LPCXpresso IDE Step Over/Into Buttons
7.2.4 Lab 1d: Morse Code
Create a function that flashes the LED according to the Morse code alphabet. Check the Wiki for
details: http://en.wikipedia.org/wiki/Morse_code. The function shall take an arbitrary string as input and
send the string by flashing the LED.
Step over
Step into
Pause