Issue
145 August 2002
Driving
the NKK Smartswitch
Part
2: Graphics and Text
by
Aubrey Kagan
Whether
your message is one of workplace safety or world peace,
the long nights of brooding over ways to tell the
world are over. Now that you’re comfortable with the
interface to drive the Smartswitch, Aubrey will show
you how to display your ideas as text and graphics.
Start
Graphic Generation Switch
Input
Sources
& PDF
In
Part 1, I described the basic interface to drive the
Smartswitch. In this article, I will add the bells and
whistles to allow both text and messages to be placed
anywhere on the screen.
GENERATING
AN IMAGE
The
software I described last month merely converts the
bits stored in the memory array cMatrix[][] to pixels
on the LCD. Now, I will show you how to generate an
image on the display that enables a level of abstraction.
I’ve
tried to create an interface that enables the mixing
and matching of graphics and text. As I mentioned before,
the LCD output is maintained in RAM, so writing an object
to RAM affects only specific pixels. Everything else
is left untouched.
Interface
to these functions is through up to 12 bytes of RAM
(cCMDs[12]). The application software that uses this
interface writes these desired bytes and then waits
for a completed signal. Bit 0 of cCMDs[0], when set
by the application software, indicates that there is
a valid set of command and data bytes in this array.
The
Display Interface Handler processes this array and when
it’s complete it clears bit 0 of cCMDs[0]. The application
software polls the RAM location cCMDs[0] and waits for
bit 0 to go to zero. After it does, the software updates
registers cCMDs[1] to cCMDs[11] as needed and then sets
bit 0 of cCMDs[0] to one.
The
command set implements all the functions necessary to
control the display. The commands include clearing and
turning on a pixel block, writing text, placing graphics,
reverse video, and changing the backlight. You can download
the command set from the Circuit Cellar web site.
CHARACTER
GENERATION
In
order to represent a character in dot matrix format,
the symbol must be reduced to a series of pixel patterns.
These patterns are held in a look-up table where the
character code (normally ASCII) and row number access
the specific pattern. This is called a character generator.
Five
columns by seven rows is a common format for small displays,
but I felt a second, slightly larger format, 7 × 9,
also would be beneficial because the Smartswitch is
a small device. A 5 × 7 format accommodates a maximum
of six characters per line, while a 7 × 9 only allows
for four characters per line. I implemented only two
character sets in order to economize on program memory
space.
Creating
a character set can be tedious, so I was delighted when
I discovered that I could use Excel to expedite the
process. This brilliant idea from Alberto Bitti was
published as a design idea in another magazine in September
2001. [1] I was motivated enough to create some macros
to speed up the generation process. This implementation
was published in April 2002. [2] You may download the
associated Excel file from the Circuit Cellar web site.
In
summary, you have to enter the desired matrix pattern
for each character and the Excel worksheet generates
the bit pattern as a number for every row. This is then
saved to a file, which can be edited and read into the
application (see the cCharSet1 and cCharSet2 arrays
in the C module LCDmem.c).
In
order to ensure that previous entities are cleared,
and to allow spacing between characters, I have added
a column of blank pixels to the right of each character
and a row of blank pixels underneath each character.
If the most significant bit of a character in RAM is
set, that character is underlined in the row underneath
the character. A standard ASCII character set goes from
0x20 to 0x7F. I have allowed for an additional 32 characters,
from 0 to 0x1F, to permit customized characters.