|
Using
a Graphics-Based LCD
Module with C
by Bob Perrin and Tak Auyeung
Start
Software Overview
The Bottom Layer Initializing
the LCD Display Shadow
Display Drawing Dots
and Lines Printing
Text Extensions
Sources and PDF
DRAWING DOTS AND
LINES
Given the arrangement
of pixels on the LCD, drawing dots is boring. Its
simply a matter of computing the page address and
column address, modifying the shadow display data
at the correct bit, and sending the new display
data to the LCD. However, drawing a line is a bit
more complicated.
The most intuitive
method is to use the equation y = mx +
c, in which m is the slope and c is
the intercept. However, this method involves at
least one multiplication for each pixel on the line.
A less intuitive, but more effective method is presented
in pseudo code as follows.
Let (x1, y1) and (x2,
y2) be the end points of the line, furthermore,
x1 <= x2, y1 <= y2. In
addition, let limit = x2 x1
and increment = y2 y1. Let
us assume limit >= increment, then
the following code draws a straight line from (x1,
y1) to (x2, y2):
sum = 0
y =
y1
for
x = x1 to x2
sum
= sum + increment
if (sum
>= limit) then
sum
= sum limit
y =
y + 1
end
if
draw
(x,y)
end
for
Note that there are
no multiplication or division operations in the
above code. Only integer operations are used. The
computation for each pixel involves one increment
(for x), one addition (for sum), one comparison
(for sum), maximum one subtraction (for sum), and
maximum one more increment (for y).
The restrictions of
x1 <= x2, y1 <= y2, (x2
x1) >= (y2 y1) are handled by making
provisions for each case so that the algorithm can
be applied.
FILLING
Two functions fill
either the whole screen or a rectangle. The function
scrFill fills the entire screen with a pattern,
whereas scrFillBox fills a rectangle in the
screen. The first argument of both functions is
a pointer to a struct _scrBuffer that represents
the shadowed state of the screen. The second argument
of scrFill is a byte that specifies the pattern
to fill the screen. The second and third arguments
of scrFillBox are of type struct _point,
which indicate the upper-left corner and lower-right
corners of the rectangle.
Note that the brush
type applies to both functions. In other words,
scrFill or scrFillBox can set, clear,
flip, or overwrite the pixels on the LCD. The overwrite
mode (SCR_BRUSH_OVR) is not recommended for
rectangles that are not on page boundaries, because
overwrite affects all eight pixels of a page regardless
of the boundary of the rectangle. The following
call sequence efficiently clears the screen:
scrSetBrush(SCR_BRUSH_OVR);
scrFill(&scrBuffer,
0x00);
PREVIOUS
NEXT
|