Graphics App Note
Graphics App Note
INTRODUCTION
Graphic-enabled devices are used extensively in daily
life. They are found everywhere, including indoor
products, such as telephones, calculators, pagers, MP3
players, digital electric meters, smart remote and UPS
displays. They are also used in outdoor products, such
as traffic signals, taxi meters, bus displays, advertise- Human eyes perceive the light as a Yellow colored light
ment boards, etc. The list is virtually endless. A current instead of separate Red and Green colored lights. This
trend is that many existing devices are becoming color recognition property of the human eye is the
graphic-enabled because it is economically feasible, foundation of the RGB (Red, Green and Blue) model.
easy to use and the latest in technology. The model states that the human eye can be made to
This application note is intended to help engineers who perceive different colors by mixing appropriate
are designing their first graphic application. It describes proportions (intensities) of Red, Blue and Green colors.
the basic definitions and jargons of graphics applications Therefore, a ‘colored’ light can be formed by mixing
and it helps the engineer to understand the theory, different proportions of Red, Green and Blue colors.
necessary decision factors, hardware considerations, • Mixing the same proportions of three RGB colors
available microcontrollers and development tools. Soft- gives a Gray color
ware libraries and support are available from Microchip
• Mixing a zero amount of all RGB colors gives a
with further literature references for advanced users.
Black color
• Mixing a maximum amount of all RGB colors
BASICS OF COLOR SCIENCE gives a White color
In its purest form, color is associated with the Varying the intensity of light, while keeping the same
wavelength of light, within human visible range, from proportion of RGB, gives different shades of Gray,
about 400 nm (Violet) to 700 nm (Red), with Yellow which is also known as ‘Grayscale’. Using a single
centered at about 575 nm. That means, if a light of color (a fixed proportion of RGB) throughout an appli-
575 nm wavelength is incident on human eyes, it is cation gives a ‘Monochrome’ application, meaning a
perceived as a Yellow light. We have also learned that single color.
colors can be derived from three basic colors: Red, Since everything is represented in bits and bytes in a
Blue and Green. For example, Yellow can be derived digital system, then how can actual colors be repre-
by mixing Red and Green lights. Is this true? The sented as a number in the form of bits or bytes? Each
answer is both no and yes. It is no because mixing Red of these three basic colors (RGB) can represent a byte
and Green lights will constitute a mixture of lights with for a number ranging from 0 to 255. Therefore, with
wavelengths of 700 nm and 560 nm, and there is not a 3 bytes, we can represent 16 million colors (224) and
wavelength representing Yellow. The answer is yes this is termed as “True Color”. It is also common to use
because human eyes perceive this mixture as a Yellow 16 bits to represent colors. With 16 bits, we can
colored light. Therefore, we see the mixture of Red and represent 64K colors (216), which is sufficient for many
Green lights as a single Yellow light, as shown in graphics applications.
Figure 1. This is due to the color recognition properties
of the human eye.
320 Pixels
3.5''
240 Pixels
Frame Display
Display Glass
Buffer Controller
Microcontroller
Display Glass All the LCD modules include gate and source drivers to
drive the voltage and current for displaying all the
Display glass is the device which displays a sequence of pixels. Table 1 gives a brief comparison of different
colors on the pixels and also converts the digital display technologies.
representation of colors to actual colors. The term, color,
includes grayscale. Generally, the types of displays used
are TFT LCDs, CSTN/MSTN LCDs or OLED/AMOLEDs.
Display Glass
Frame Display
Buffer Controller
Microcontroller
Display Module
A. 2 Devices
Microcontroller
Parallel or
Frame Display Display Glass
RGB
Serial Buffer Controller
B. 3 Devices Microcontroller
Frame Display
RGB Display Glass
Buffer Controller
Microcontroller
C. 2 Devices
SRAM
Frame Buffer
Parallel Display
RGB Display Glass
Buffer Controller
D. 3 Devices Microcontroller
For Options A and B, the Microchip Graphics Library supports optional external RAM as a frame buffer with
currently supports PIC24, dsPIC® and PIC32 a parallel interface through the EPMP module. For
microcontrollers with PMP or EPMP. The more information on the device, refer to the respective
PIC24FJXXXDAXXX family can support Options C and device data sheet and also Section 43. “Graphics
D. PIC24FJ256DA210 contains 96 Kbytes of internal Controller Module (GFX)” (DS39731) from the
memory and has a graphics controller inside. It also “PIC24F Family Reference Manual”.
Voltage
t1 t2 t3 t4
VLCD
VA
VD
Time
t5 VBK t6
Data
Time
VD = Digital Supply VA = Analog Supply
VLCD = LCD Supply VBK = Backlight Supply
Data = Digital Signal from Controller
PIC® MCU
with ADC
Digital I/O
Digital I/O
X X
Digital I/O
Digital I/O
Digital I/O
1
Digital I/O
Sense X
Dig-O/AN-I X
0
Dig-O/AN-I
Y
PIC ® MCU
with ADC
1
Digital I/O
Digital I/O
0 X X
Dig-O/AN-I
Sense
Dig-O/AN-I
FIGURE 15: DISPLAY CONTROLLER’S DISPLAY SIGNALS LESS THAN LCD’S DISPLAY
SIGNALS
dp_Blue[5]
or dp_Blue[0]
Connect to VDD or
GND or MSb
FIGURE 16: DISPLAY CONTROLLER’S DISPLAY SIGNALS ARE MORE THAN LCD’S DISPLAY
SIGNALS (POSSIBLE COLOR DEGRADATION)
dp_Red [0]
Red [0] No Connect
PIC24F Graphics
Controller Module
Display Interface
Clock (DISPCLK) Display Module
Interface
To Display
(G1CLK) Interface VSYNC
Glass
GEN
RCCGPU CHRGPU IPU
CLUT GPWR
System
RAM
FIGURE 18: GRAPHICS PICtail™ PLUS DAUGHTER BOARD WITH 3.2'' DISPLAY KIT (AC164127-3)
Application Layer
Note: The Microchip Graphics Library Version 2.11 is explained here. In future, the software structure may be modified. Refer
to the Help file of your Microchip Graphics Library for the latest information.
The Graphics Display Controller is the hardware module development board-specific files are in the folder,
consisting of the frame buffer and Display Controller. Microchip Solutions/Board Support Package. The
The remaining layers are the software layers. The project path must be set to point to these folders.
Microchip Graphics Library is organized in a set of Starting from the bottom-most Software layer to the
folders under the folder, ‘Microchip Solutions’. The ‘C’ top-most layer, the functionality of each layer and the
files are in the folder, Microchip Solutions/Microchip/ files responsible for those layers are explained further
Graphics, and the header files are in the folder, in the following sections. For more information, refer to
Microchip Solutions/Microchip/Include/Graphics. The the Help file of the Microchip Graphics Library.
EXAMPLE 6:
WORD GOLMsgCallback(WORD objMsg, OBJ_HEADER *pObj, GOL_MSG *pMsg)
{
// beep if button is pressed
if(objMsg == BTN_MSG_PRESSED)
{
Beep();
}
}
CLUT
0 Color 0
1
1 Pixel
Value = 21 2 210 200 9
3 R G B
.
.
21 Color 21 Color Value
TABLE A-1: CONTENTS OF AN EXAMPLE IMAGE USING INDEXES INSTEAD OF RGB VALUES
0 0 0 0 1 1 1 1
0 0 0 0 1 1 1 1
0 0 0 0 1 1 1 1
0 0 0 0 1 1 1 1
2 2 2 2 3 3 3 3
2 2 2 2 3 3 3 3
2 2 2 2 3 3 3 3
2 2 2 2 3 3 3 3
TABLE A-2: PALETTE TABLE (24 BPP) The other way to device a CLUT is to scale the RGB
Color Index G B ranges to generate the 16-bit codes. However, since
R
the human eye is more sensitive to Green, we can give
0 0 255 0 Red and Blue 5 bits each, with 6 bits for Green, and
1 255 0 0 each cell in the image gets replaced by its index. This
may lead to edge artifacts in the image. Therefore, this
2 0 0 255 is not suitable for natural images but may be suitable
3 0 255 255 for artificially created images.
. . . . PIC24FJ256DA210 supports up to a 256-entry CLUT
. . . . with 16 BPP per entry.
255 219 200 198
Median Cut Algorithm
Note: A color index refers to one row of CLUT. It is an adaptive method that tries to put most bits where
A simple color changing type of animation process is colors are most clustered, so that they can be discrim-
possible by changing the CLUT in the above method. inated. This is the most general algorithm used while
This is also known as palette animation. converting a RGB image to a CLUT-based color image,
such as PC applications (e.g., GIMP).
In the above explanation, we saw a simple way to
cluster the image and device a CLUT, but clustering is
a slow process.
The workflow of double-buffering is as follows: • The immediate display of changes is required. For
example, plotting a graph.
1. In the initial stage, the draw buffer and frame buffer
• The RAM available for display is limited.
have the same contents, as shown in Figure B-1.
• The display resolution is smaller than the
FIGURE B-1: INITIAL STAGE WQVGA (this is not a hard rule).
Algorithm:
Step i: The new screen is completely created in the
Draw Buffer Frame Buffer
draw buffer.
Step ii: Move one right line (Height = Screen Height, 2
Width = One Pixel) from the draw buffer to the left side
of the frame buffer using the RCCGPU rectangle copy
command. Algorithm:
Step iii: Move two right lines (Height = Screen Height, Step i: The new screen to be shown is completely
Width = 2 Pixels) from the draw buffer to the left side of created in the draw buffer.
the frame buffer using the RCCGPU rectangle copy Step ii: Move two middle lines (Height = Screen Height,
command. Width = 2 Pixels) from the draw buffer to the middle of
Repeat the above steps until the whole screen is the frame buffer using the RCCGPU rectangle copy
transferred to the frame buffer, as shown in Figure C-1. command.
2. Expanding Rectangle: This effect shows a Step iii: Move four middle lines (Height = Screen Height,
rectangle expanding from the middle to the Width = 4 Pixels) from the draw buffer to the middle of
periphery of the screen. the frame buffer using the RCCGPU rectangle copy
command.
Repeat the above steps until the whole screen is
transferred to the frame buffer, as shown in Figure C-3.
Similarly, many screen transition effects can be
achieved easily.
• Microchip believes that its family of products is one of the most secure families of its kind on the market today, when used in the
intended manner and under normal conditions.
• There are dishonest and possibly illegal methods used to breach the code protection feature. All of these methods, to our
knowledge, require using the Microchip products in a manner outside the operating specifications contained in Microchip’s Data
Sheets. Most likely, the person doing so is engaged in theft of intellectual property.
• Microchip is willing to work with the customer who is concerned about the integrity of their code.
• Neither Microchip nor any other semiconductor manufacturer can guarantee the security of their code. Code protection does not
mean that we are guaranteeing the product as “unbreakable.”
Code protection is constantly evolving. We at Microchip are committed to continuously improving the code protection features of our
products. Attempts to break Microchip’s code protection feature may be a violation of the Digital Millennium Copyright Act. If such acts
allow unauthorized access to your software or other copyrighted work, you may have a right to sue for relief under that Act.
ISBN: 978-1-61341-123-0
02/18/11