Global Sources
EE Times-Asia
Stay in touch with EE Times Asia
?
EE Times-Asia > Processors/DSPs
?
?
Processors/DSPs??

Basics of ARM design on mbed IDE (Part 2)

Posted: 13 Nov 2013 ?? ?Print Version ?Bookmark and Share

Keywords:mbed? software tools? compiler? ARM? API?

Flowcharts allow us to visualise the order of operations of code and to make judgements on which sections of a program may require the most attention or take the most effort to develop. They also help with communicating a potential design with non-engineers, which may hold the key to designing a system that meets a very detailed specification.

Pseudocode
Pseudocode consists of short, English phrases used to explain specific tasks within a program. Ideally, pseudocode should not include keywords in any specific computer language. Pseudocode should be written as a list of consecutive phrases; we can even draw arrows to show looping processes. Indentation can be used to show the logical program flow in pseudocode.

Writing pseudocode saves time later during the coding and testing stage of a program's development and also helps communication among designers, coders and project managers. Some projects may use pseudocode for design, others may use flowcharts, and some a combination of both.

The software design shown by the flowchart in figure 4 could also be described in pseudocode as shown in figure 5.

Note that the functions SegConvert( ) and Delay( ) are defined elsewhere, for example in a separate 'utilities' file, authored by a different engineer. Function SegConvert( ) could implement a simple look-up table or number of if statements that assigns the suitable value to B.

Figure 5: Example pseudocode for seven-segment display counter.

Working with Functions on the mbed
Implementing a Seven-Segment Display Counter. Program Example 1 below shows a program which implements the designs described by the flowchart in figure 4 and the pseudocode shown in figure 5.

It applies some of the techniques first used in Program Example 3.5 in Part 1, but goes beyond these. The main design requirement is that a seven-segment display is used to count continuously from 0 to 9 and loop back to 0. Declarations for the BusOut object and the A and B variables, as well as the SegConvert( ) function prototype, appear early in the program. It can be seen that the main( ) program function is followed by the SegConvert( ) function, which is called regularly from within the main code. Notice in the line

B=SegConvert(A); // Call function to return B

that B can immediately take on the return value of the SegConvert( ) function.

Notice the SegConvert( ) function the final line immediately below, which applies the return keyword:

return SegByte;

This line causes program execution to return to the point from which the function was called, carrying the value SegByte as its return value. It is an important technique to use once you start writing functions that provide return values. Notice that SegByte has been declared as part of the function prototype early in the program listing.

Connect a seven-segment display to the mbed and implement Program Example 1. The wiring diagram for a seven-segment LED display was shown previously in figure 3.10 in Part 1. Verify that the display output continuously counts from 0 to 9 and then resets back to 0. Ensure that you understand how the program works by cross-referencing with the flowchart and pseudocode designs shown previously.

Program Example 1: Seven-segment display counter.

Function reuse
Now that we have a function to convert a decimal value to a seven-segment display byte, we can build projects using multiple seven-segment displays with little extra effort. For example, we can implement a second seven-segment display (figure 6) by simply defining its mbed BusOut declaration and calling the same SegConvert( ) function as before.

Figure 6: Two seven-segment display control with the mbed.


?First Page?Previous Page 1???2???3???4?Next Page?Last Page



Article Comments - Basics of ARM design on mbed IDE (Pa...
Comments:??
*? You can enter [0] more charecters.
*Verify code:
?
?
Webinars

Seminars

Visit Asia Webinars to learn about the latest in technology and get practical design tips.

?
?
Back to Top