Global Sources
EE Times-Asia
Stay in touch with EE Times Asia
EE Times-Asia > 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?

It is possible to implement a counter program that counts from 00 to 99 by simply modifying the main program code to that shown in Program Example 2. Note that the SegConvert( ) function previously defined in Program Example 1 is also required to be copied (reused) in this example. Note also that a slightly different programming approach is used; here we use two for loops to count each of the tens and units values.

Using two seven-segment displays, with pin connections shown in figure 6, implement Program Example 2 and verify that the display output counts continuously from 00 to 99 and then resets back to 0. Review the program design and familiarise yourself with the method used to count the tens and units digits each from 0 to 9.

A more advanced program could also read two numerical values from a host terminal application and display these on two seven-segment displays connected to the mbed. The program can therefore display any integer number between 00 and 99, as required by user key presses.

Program Example 2: Two digit seven-segment display counter.

An example program design uses four functions to implement the host terminal output on seven-segment displays. The four functions are as follows:

???SegInit( ) e to set up and initialise the seven-segment displays
???HostInit( ) e to set up and initialise the host terminal communication
???GetKeyInput( ) e to get keyboard data from the terminal application
???SegConvert( ) e function to convert a decimal integer to a seven-segment display data byte.
We will use the mbed universal serial bus (USB) interface to communicate with the host PC, and two seven-segment displays, as in the previous exercise.

For the first time now we come across a method for communicating keyboard data and display characters, using ASCII codes. The term ASCII refers to the American Standard Code for Information Interchange method for defining alphanumeric characters as 8bit values. Each alphabet character (lower and upper case), number (0e9) and a selection of punctuation characters are all described by a unique identification byte, i.e. the 'ASCII value'. Therefore, for example, when a key is pressed on a computer keyboard, its ASCII byte is communicated to the PC. The same applies when communicating with displays.

The ASCII byte for numerical characters has the higher four bits set to value 0x3 and the lower four bits represent the value of the numerical key which is pressed (0x0 to 0x9). Numbers 0e9 are therefore represented in ASCII as 0x30 to 0x39.

To convert the ASCII byte returned by the keyboard to a regular decimal digit, the higher four bits need to be removed. We do this by logically ANDing the ASCII code with a bitmask, a number with bits set to 1 where we want to keep a bit in the ASCII, and set to 0 where we want to force the bit to 0. In this case, we apply a bitmask of 0x0F. The logical AND applies the operator '&' and appears in the line:

return (c&0x0F); // apply bit mask to convert to decimal, and return

Example functions and program code are shown in Program Example 3.

Program Example 3: Two digit seven-segment display based on host key presses.

Once again, the function SegConvert( ), as shown in Program Example 1, should be added to compile the program.

This article is excerpted from Fast and effective embedded systems design: Applying the ARM mbed by Rob Toulsonand Tim Wilmshurst, used with permission from Newnes, a division of Elsevier. Copyright 201 All rights reserved.

About the authors
Tim Wilmshurst, head of Electronics at the University of Derby, led the Electronics Development Group in the Engineering Department of Cambridge University for a number of years, before moving to Derby. His design career has spanned much of the history of microcontrollers and embedded systems.

Rob Toulson is Research Fellow at Anglia Ruskin University in Cambridge. After completing his PhD, Rob spent a number of years in industry, where he worked on digital signal processing and control systems engineering projects, predominantly in audio and automotive ?elds. He then moved to an academic career, where his main focus is now in developing collaborative research between the technical and creative industries.

To download the PDF version of this article, click here.

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

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


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

Back to Top