ASCII and Unicode Graphics Characters
Basic ASCII characters use only seven bits, but extended ASCII uses 8-bits to include 128 new special graphics characters by turning on the high bit and not using it for a parity bit. In C/C++, you can generate one of these characters using char(xxx), where xxx is the digital value of the graphics character. A handy table of these graphics characters is available at http://en.wikipedia.org/wiki/Code_page_437 for IBM PCs. On early Macs, a somewhat different graphic appeared for the new graphics characters, but the basic ASCII characters are the same. If you check a graphics character set for the early Macs at http://en.wikipedia.org/wiki/Mac-Roman_encoding , a different graphics character selection was available. Recent Macs just print a "?" for characters above 128, but they also support Unicode box drawing characters. These graphics characters can be used to draw lines in C/C++ in a terminal application window using printf and putc on mbed. VT100 cursor functions come in handy to save time generating displays. A couple of examples generated by mbed programs are shown below.
Spectrum Analyzer display using ASCII graphics character for bars
Logic Analyzer display using ASCII graphics characters to draw lines
By default, the Mac terminal application program uses Unicode characters (http://www.unicode.org) in UTF-8 format . This means that the ASCII extended graphics characters greater than 128 are invalid (in Unicode) and typically appear as a "?". There are Unicode characters for lines and bars like those used in the PC graphics character set. Here are instructions on a simple way to use them:
Printing Unicode characters in a Mac terminal application using mbed C/C++ code.
1. Using the mouse and keyboard, copy a single Unicode character’s image from a Wikipedia character web page such as: http://en.wikipedia.org/wiki/Box_drawing_characters.
2. In the mbed compiler window, paste the character into a single character string (surrounded by double quotes)
3. In C/C++ code, use something like PC.puts(“paste_character_here”); to send the string from mbed to the Mac over the serial port.
4. The compiler prints out warnings about an illegal multibyte character sequence – but it still seems to work. A Unicode UTF-8 character is actually 1-4 bytes, that is why it was setup as a string and not a standard C 1-byte character.
5. When the code runs, the Unicode character displays in the terminal application window on the Mac.
Please log in to post comments.