Page 113 - ARM Based Microcontroller Projects Using MBED
P. 113
7.8 PROJECT 5—BINARY COUNTING LEDs 99
BEGIN
Group PORT C lower byte
Set CNT = 1
DO FOREVER
Send CNT to PORT C
Wait 1 second
Increment CNT
IF CNT > 255 THEN
CNT = 0
ENDIF
ENDDO
END
FIG. 7.33 PDL of the program.
/******************************************************************
BINARY UP COUNTER WITH LEDs
===========================
In thsi project 8 LEDs are conencted to PORT C. The LEDs count up
in binary every second.
Author: Dogan Ibrahim
Date : August 2018
File : Counter
*******************************************************************/
#include "mbed.h"
BusOut LEDS(PC_0,PC_1,PC_2,PC_3,PC_4,PC_5,PC_6,PC_7);
int main()
{
int CNT = 0; // CNT = 0
while(1) // Endless loop
{
LEDS = CNT; // Turn ON LED
wait(1.0); // Wait 1 second
CNT++; // Incfement CNT
if(CNT > 255)CNT = 0; // CNT back to 0
}
}
FIG. 7.34 Program listing.
7.8.6 Program Listing
The program listing is shown in Fig. 7.34 (program: Counter). At the beginning of the pro-
gram BusOut statement is used to group the PORT C lower byte into a variable called LEDS,
and variable CNT is initialized to 0. The main program is executed in an endless loop using a