Page 188 - ARM Based Microcontroller Projects Using MBED
P. 188
174 8. INTERMEDIATE LEVEL PROJECTS
BEGIN
DO FOREVER
Generate two random numbers between 1 and 100
Display the product of these numbers without the result
Wait 20 seconds
Display the result
Wait 5 seconds
ENDDO
END
FIG. 8.34 Program PDL.
8.12.4 Program Listing
Fig. 8.35 shows the program listing (program: Multiply). At the beginning of the program,
the functions to clear the screen and home the cursor are defined. The program then generates
two random numbers between 1 and 100 and stores in variables Number1 and Number2. The
multiplication of these numbers is then shown without the result to give the user to calculate
the result. The result is displayed after 20s so that the user can check with his/her own cal-
culation. The process is repeated after 5s delay.
Fig. 8.36 shows the output from the program.
8.13 PROJECT 10—LOOP EXECUTION TIMES
8.13.1 Description
We sometimes need to know the execution times of loops in our programs. In this project, a
number of for loops are created with different iteration numbers and the loop execution times
are calculated and displayed on the PC screen.
8.13.2 Aim
The aim of this project is to show how the Timer function can be used to calculate the ex-
ecution times of loops in a program.
8.13.3 The PDL
The PDL of the program is shown in Fig. 8.37.
Using a Timer
A Timer can be created, started, stopped, and its current value read. It is also permissible to
create and use more than one Timer in a program. Timers can be useful to measure the
elapsed time in a program.