HT1621 An2343
HT1621 An2343
AN2343
Author: Andrew Smetana Associated Project: Yes Associated Part Family: All PSoC Designer Version: 4.2 SP3 Associated Application Notes: AN2228
Abstract
This Application Note describes implementation of a liquid crystal display (LCD) driver based on the widely available HOLTEK HT1621 LCD Controller. Methods and algorithms of display control are described and an API library is provided. The LCD used in this example was a customers custom part. The proposed algorithms can be easily adapted to any custom LCD panel connected to the controller.
Introduction
LCDs are widely used as data display devices in embedded systems. Among the features that have made LCDs popular are low price, low power dissipation, lightweight, durability, reliability, and broad support by dedicated ICs for communication with microcontrollers. A good example of an LCD driver is the Hitachi character LCD driver HD44780, the industry standard. This dotmatrix LCD controller is supported by PSoC APIs. It is useful in applications that permit alphanumeric data display. However, specialized displays are often needed. Specialized displays keep end- product prices low, simplify the interface between the microcontroller and LCD driver, and decrease weight and size parameters. Examples of specialized displays include clocks, calculators, telephones, and home and industrial appliances. This implementation is based on one of these dedicated drivers, the HT1621. This Application Note addresses implementation in two parts: General Description LCD Driver Implementation the proposed
General Description
The HT1621 driver is a 128-segment (32x4), multifunctional LCD driver with memory mapping. The software configuration feature of HT1621 makes it suitable for many LCD applications, including LCD modules and display subsystems. Only three or four connections are required for interfacing between the host controller and the HT1621. A structural schematic of the display system is shown in Figure 1. This structure requires few external components and uses only three interface connections. The system consists of the PSoC, HT1621 controller, and an LCD panel. The HT1621, besides its primary function as an LCD controller, has peripherals including the watchdog timer, time base generator and the tone frequency generator. For more information about these features, refer to the HT1621 data sheet. Note that the controller has an on-chip RC oscillator (256 kHz) for controlling the LCD and peripherals. This General Description focuses on the components and functions of the HT1621 driver that relate directly to the LCD: Display Memory RAM LCD Driver in HT1621 Command Format Interfacing with HT1621
12/8/2006
Rev. **
-1-
AN2343
HT1621
OSCO +5V VDD PRT02 OSCI CS RD Control and Timing Circuits COM0 ... ... COM3 . . LCD Driver/ Bias Circuit SEG0 Display RAM
PSoC
PRT01 PRT03
VSS
+5V
15K IRQ
+5V
Display Memory RAM The static display memory (RAM) is organized in a 32x4bit matrix, which stores the displayed data. The contents of the RAM are directly mapped to the contents of the LCD driver. Data in the RAM can be accessed by READ, WRITE, and READ-MODIFY-WRITE commands. Note that in the schematic for the proposed LCD system, oneway communication is implemented (from PSoC to HT1621). The correspondence between RAM and the LCD pattern is shown in Figure 2.
Figure 2. RAM Mapping
COM3 COM2 COM1 COM0 SEG0 SEG1 SEG2 SEG3 .. .. 0 1 2 3 .. Address 6 bits (A5, A4, , A0)
LCD Driver in HT1621 The HT1621 is a 128 (32x4)-segment LCD driver. It can be configured as 1/2 or 1/3 bias, and is designed with two, three or four segments in common with the LCD driver. These configuration features make the HT1621 suitable for multiple LCD applications. The LCD driving clock is derived from the system clock. The signal frequency of the display control is 256 Hz. Some LCD commands are described in Table 1.
In the table, the bold font of 100 indicates the command code ID. The X in the code signifies any bit in a corresponding position. If successive commands are issued, the command code ID (except in the first command) is omitted. The LCD OFF command turns the LCD display off by disabling the LCD bias generator. The BIAS and COM commands relate to the LCD panel. LCD commands make the HT1621 compatible with most types of LCD panels.
SEG31 D3 D2 D1 D0
31
Addr Data
12/8/2006
Rev. **
-2-
AN2343
Table 1. LCD Commands Name LCD OFF LCD ON BIAS and COM Command Code 100 00000010X 100 00000011X 100 0010abXcX Function Turn off LCD outputs Turn on LCD outputs c=0: 1/2 bias option c=1: 1/3 bias option ab=00: 2 commons option ab=01: 3 commons option ab=10: 4 commons option
Command Format The HT1621 can be configured by using the software settings. There are two instruction modes: Command mode For configuration of HT1621 resources Data mode For transmission of display data to the LCD. Data mode includes READ, WRITE and READMODIFY-WRITE operations.
Interfacing with HT1621 Only four lines are required to interface with the HT1621: CS, DATA, RD, and WR. The CS line is used to initialize the serial interface circuit and to terminate the connection between the host controller and the HT1621. The DATA line is the serial data input/output (IO) line. Data to be read or written, or commands to be written, must be passed through the DATA line. The RD line is the READ clock input, and the WR line is the WRITE clock input. The data, address or command on the DATA line are all clocked into the HT1621 on the rising edge of the WR signal. In this proposed driver implementation, only three lines are used: CS, WR, and DATA. In this way, simplex communication is used to control the LCD. A time diagram of a WRITE operation is shown in Figure 3.
The instruction mode ID must be issued before the data or command is sent.
Figure 3. Time Diagram of a WRITE Operation
12/8/2006
Rev. **
-3-
AN2343
The following subsections guide you through key aspects of the LCD driver implementation:
Algorithm of Logical Access to the LCD Segments / Symbols Digits and Segment Highlight Display APIs
The code example in the following section describes how logical access to the individual LCD segment is organized; that is, how to switch on or switch off a segment). The code also describes how logical access to whole symbols (for example, digits) is organized.
#define #define #define #define #define #define #define #define #define #define #define #define #define #define #define #define #define
LCD_DIGIT_INDEX LCD_ERROR_INDEX LCD_PC_INDEX LCD_CALC_INDEX LCD_MUSIC_INDEX LCD_VOLUME_INDEX LCD_NUM_LOCK_INDEX LCD_MINUS_INDEX LCD_CAPS_LOCK_INDE LCD_SCROLL_LOCK_INDEX LCD_FUNCTION_INDEX LCD_BATTERY_INDEX LCD_PM_INDEX LCD_AM_INDEX LCD_POINT_INDEX LCD_COMMA_INDEX LCD_COLON_INDEX
0 70 71 72 73 74 75 76 77 78 79 80 81 82 83 93 100
// // // // // // // // // // // // // // // // //
next digit + 7 ERROR PC CALC MUSIC VOLUME NUM LOCK MINUS CAPS LOCK SCROLL LOCK FUNCTION BATTERY PM AM next point + 1 next comma + 1 next + 1
12/8/2006
Rev. **
-4-
AN2343
As can be seen in Figure 4, at first, the digital segments are enumerated in the determined order in the array in series. This standard method of storing enables easy access to any digital position on the display by adding a digital position multiplied by 7 to the LCD_DIGIT_INDEX constant. Access to the points and commas can be arranged in a similar way.
Digits and Segment Highlight Consider how indicating a digit in the single position is implemented. Digits on the screen are presented as a set of 7-character segments. It is necessary to define the template of each digit in order to achieve visualization. Screen images of some digits and the corresponding digits templates in memory are shown in Figure 7.
12/8/2006
Rev. **
-5-
AN2343
68 77 67 69 63
61 60 62 59 58 56
54 53 55 49
47 46 48 42
40 39 41 35
33 32 34 28
26 25 27 21
19 18 14 20 17 15 16 85 78 100 101
12 11 13 10 9 7
5 46 0 82
66 65 70 71
64 92 99
57 91 98 72
52 51
50 90
45 44
43 89 74
38 37
36 88
31 30
29 87 94
24 23
22 86 93
1 83
81
97
96 73
95
84 79
75
76
80
5
Segment No. Common No.
0
7
S4 S3 S2 S1 S0 C1 C0
6 5 4 3 2 1 0
3
0 1
12/8/2006
Rev. **
-6-
AN2343
5 4 3 2
USED BITS
5 0 1 4 3 2
USED BITS
5 0 1 4 3 2
USED BITS
0 1
0
7
0
6
1
5
1
4
1
3
1
2
1
1
1
0
0
7
0
6
0
5
0
4
0
3
0
2
1
1
1
0
0
7
1
6
1
5
0
4
1
3
1
2
0
1
1
0
A template of each digit is stored in the LCD_digit_segments[12] array. In addition to the 10 digits, this array contains the codes of special symbols: SPACE for turning off a digital position, and MINUS for drawing the minus sign (). To explain the process of any digit highlight in i position: Digits are enumerated from right to left, from 0 to 9 on the LCD. First, you must obtain the digit template from the LCD_digit_segments[12] array, using the following sequence:
The elements of the LCD_segments array, in combination with the indexes (index..index+7) ,yield the addresses of the working segments in i-digit position. Also, in the loop, each bit of a digits template is examined and it is determined whether a segment must be turned on or off in element the corresponding LCD_segments[index+j] (j=0..6) in the display. This process is shown in Figure 8. The element LCD_segment[index+j] determines the physical address (coordinate) of a segment in video memory.
digit_template = LCD_digit_segment[digit]
(1)
Calculate the index of the first segment in i-digit position in the LCD_segments table:
(2)
Figure 8. Correspondence Between the Template of a Digit and the Templates Segment Indexes in the LCD_segments[102] Array
index+6 index+5 index+4 index+3 index+2 index+1 index
0
7
0
6
0
5
0
4 5 4 3 2 6
0
3
0
2
1
1
1
0
0 1
12/8/2006
Rev. **
-7-
AN2343
To provide convenient access to the video memory of the HT1621 display driver, a local copy of the drivers memory was created in the RAM of the PSoC device and declared as BYTE LCD_memory[16]. Also, a unidirectional communication interface requires this kind of LCD RAM usage. Each bit in this memory is responsible for the state (1 - on, 0 - off) of one segment in the LCD. After changes are made to the local copy of the displays video memory, it is copied to the memory of HT1621, and the screen image is automatically updated. Access to an individual segment in the LCD_memory array must be executed on the basis of a corresponding segment address [segment, common]. The video memory of HT1621 is organized in a 32x4-bit matrix, so 16 bytes of device RAM is enough to save a local copy of the video memory. Display of the remaining LCD elements is simpler, because they occupy only one segment. For example, consider the output of a PC segment on the LCD:
Addr = LCD_segments[LCD_PC_INDEX]; Segment = Addr >> 2; // calculating Common = Addr & 0x03; // physical address of segment
void LCD_show_segment(char segment_index, BOOL state) Shows/hides a given segment, depending on the state parameter. The segment is defined by the index in the LCD_segments array. Segment indexes definitions are presented in the lcd.h code example earlier in this Application Note.
In addition to the above functions, other LCD APIs are implemented. They control the state of the special symbols on the screen (Calc, PC, AM, PM, and so on). The preceding bulleted list of functions works only with the local copy of video memory. The functions do not form images on the actual LCD. To enable images on the actual LCD, subroutines were written that implement the physical interface between PSoC and the HT1621 driver. These subroutines are implemented fully in the firmware, without use of PSoC hardware resources. The subroutines that enable images on the actual LCD are the following:
By means of this physical address [segment, common], the corresponding bit in local video memory is modified. Next, the RAM video memory is copied to controller of the display.
void LCM_Initial(void) Performs initializations actions to start the HT1621 driver. This subroutine executes three functions: turns on the built-in oscillator, sets the 1/3 bias and 1/4 duty LCD properties, and turns on the built-in bias voltage generator to highlight the LCD panel. void SendLcdCommand(BYTE command) Sends a command to the HT1621 driver void LcdWrite(void); Copies the local video memory to the HT1621 driver
Display APIs After access is gained to the segments of the display, images are created on the LCD by means of the following functions: void LCD_show_digit(char pos, char digit) Displays a digit in a given position void LCD_show_minus(BOOL state) Shows/hides the minus (-) segment for a calculators display, depending on the state parameter void LCD_show_colon(BOOL state) Shows/hides a colon (:), depending on the state parameter void LCD_show_point(char pos,BOOL state) Shows/hides a point in the given position, depending on the state parameter
The LCD driver and its corresponding library occupy about 1.6K of Flash memory in the PSoC small memory model and 1.8K in the large memory model. RAM use is the same for both models and requires 16 bytes of static memory. To save memory, a bidirectional driver interface must be implemented.
Conclusion
This Application Note has described a display system built on a PSoC, HT1621 controller and LCD panel. The interface between the device and the HT1621 driver has been described, as has access to the LCD. Using the proposed material, a customer-selected LCD panel can be applied, and a corresponding API library can be developed with a minimum of effort. Step-by-step implementation of the system has been detailed. An inexpensive, reliable, and durable display system is the result.
12/8/2006
Rev. **
-8-
AN2343
LCD Photograph
Contact:
Cypress Semiconductor 198 Champion Court San Jose, CA 95134-1709 Phone: 408-943-2600 Fax: 408-943-4730 http://www.cypress.com
Cypress Semiconductor Corporation, 2006. The information contained herein is subject to change without notice. Cypress Semiconductor Corporation assumes no responsibility for the use of any circuitry other than circuitry embodied in a Cypress product. Nor does it convey or imply any license under patent or other rights. Cypress products are not warranted nor intended to be used for medical, life support, life saving, critical control or safety applications, unless pursuant to an express written agreement with Cypress. Furthermore, Cypress does not authorize its products for use as critical components in life-support systems where a malfunction or failure may reasonably be expected to result in significant injury to the user. The inclusion of Cypress products in life-support systems application implies that the manufacturer assumes all risk of such use and in doing so indemnifies Cypress against all charges.
12/8/2006
Rev. **
-9-