Today, most of the electronics devices come with a liquid crystal display (LCD). Even new fridges have it. It is interesting as well as useful to know how to use LCDs with any device. Here is how to interface a graphics LCD module with a microcontroller.

Graphics LCD module

There are various types of graphics LCD modules available in the market depending on pixel size such as 120×64, 128×128, 240×64 and 240×128. The graphics LCD used here has a pixel size of 240×128 and is based on T6963 controller IC. The module type is SS24E12DLNW-E from UTC.

Explore Circuits and Projects Explore Videos and Tutorials

The 240×128 LCD panel screen has 240 horizontally and 128 vertically arranged pixels. It can be used for graphics or for text in any combination, like one area of 240×64 for graphics and another area of 240×64 for text. Also, the entire area of 240×128 can be used either for graphics or text.

The LCD module gets the data or command instructions from the interfaced microcontroller through data lines D0 through D7. Depending upon the command received, the T6963 finds out the data from the internal VRAM and displays it as graphics or text at appropriate place on the screen. The module has a 128-character internal character-generator ROM (CG-ROM) and can control up to 64 kB of external video RAM (VRAM). A number of character attribute functions are also available.

For communication from/ to the connected CPU, the LCD module has eight data lines (D0 through D7), write and read lines, chip-enable line, and a command or data line.

Resetting the module. As soon as the power is switched on, the T6963 IC must first be hardware reset by pulling the reset pin down for at least one millisecond.

A22_FIG-1

Font selection. Font size of the LCD module, like 6×8 (which occupies six horizontal pixels and eight vertical pixels) or 8×8 (which occupies eight horizontal pixels and eight vertical pixels), is selected by pulling the FS pin high or low, respectively. Thus if a 6×8 font is selected, you can get 240/6=40 columns and 128/8=16 text display rows. If an 8×8 font is selected, you can get 240/8=30 columns and 128/8=16 text display rows.

The text information is sent by the microcontroller byte by byte to the LCD module. The first byte is displayed in the left corner on the top as shown in Fig. 1. The second byte is displayed to the right of the first byte and so on. The last byte is the 30th byte in the row. The 31st byte is displayed in the second row.

851_fig-2

The graphics image is also sent by the microcontroller byte by byte to the LCD module. If a bit is set as ‘1’ it will be displayed in dark, and a ‘0’ bit will be displayed as a clear pixel. The first byte is displayed in the left corner on the top as shown in Fig. 2. The second byte is displayed to the right of the first byte and so on. The last byte is the 30th byte in the line. Thus the 31st byte is displayed in the second line of pixels.

Initialisation of the LCD module

32C_cursar-position

The initialisation process is always done at the beginning of the software program before we start displaying anything on the screen. It is done by sending a series of commands through data lines from the microcontroller to the LCD module. Some commands may need extra information and therefore should be sent with corresponding data bytes. The C/D pin of the LCD module must be pulled high when sending the command, and pulled low when sending the data.

Cursor pointer set. The ‘cursor pointer set’ command has two data bytes associated with it to specify the position for the cursor. This is the only command which will shift or move the cursor. The cursor cannot be shifted automatically by the data-write commands. Cursor position should be set within the actual display area.

First argument                       Cursor column position

Second argument                   Cursor row position

‘Cursor pointer’ command        (21H)

For example, sending data ‘0FH’ and ‘03H’ and command ‘21H’ will set the cursor position to 15th column in the third line (refer Fig. 3). (Remember the computer starts counting columns from ‘0’ to ‘29’ and rows from ‘0’ to ’15.’)

Offset register set. The lower five bits of the first data byte should be set to the upper five bits of the start address for the character-generator RAM (CG-RAM) area. The second data byte should be set to ‘0.’

First argument                        CG-RAM Address

Second argument must be        (00H)

Offset register command          (22H)

Address pointer set. The ‘address pointer set’ command is used to specify the starting address for writing data to the VRAM or for reading data from the VRAM. The address should be set to a location in the actual display RAM area specified by the memory map.

READ
Dummy Load for Amplifier Testing

First argument                        Address pointer (lower)

Second argument                    Address pointer (upper)

‘Address pointer’ command       (24H)

For example, sending data ‘00H’ and ‘00H’ and command ‘24H’ sets the address pointer to start location ‘0000H’ (shaded area in Fig. 4) in the VRAM.

E47_fig5 CF6_internal-cg-rom

Text home address set (TH). This command defines the starting address in the VRAM for text display data. The data is stored in the text home (TH). It is displayed at the top left-hand character position (the home position).

First argument                           Text home address (TH lower)

Second argument                        Text home address (TH upper)

‘Text home address’ command     (40H)

[/stextbox]For example, sending data ‘00H’ and ‘0FH’ and command ‘40H’ sets the text home address as ‘0F00H’ (shaded area address location) in the VRAM area. This is shown in Fig. 4.

Text area set (TA). This command defines the number of columns of text for the text area of VRAM. The text area (TA) may be set independently from the number of characters per line set by hardware settings on the T6963C controller chip. Connecting the FS pin to supply ground means you have selected 8×8 font size, which will allow up to 30 characters per line. However, TA can be programmed for even less than 30, but usually it is set to the same number of characters per line as the LCD module will display.

First argument                          Number of columns of characters (TA)

Second argument                      (00H)

‘Text area’ command                  (41H)

For example, for 240×128 LCD with 8×8 font size selected, set TA=1EH.

Graphic home address set (GH). This command defines the starting address in the VRAM for graphics display area of VRAM (refer Fig. 4). The data stored in the graphics home (GH) address will be displayed in the first six or eight bits (without shaded area in Fig. 4) of the top line in the left-hand side of the LCD screen, depending on the font size selected. When using the attribute function, the GH address indicates the starting address for the attribute RAM area.

First argument                         Graphic home address  (GH lower)

Second argument                     Graphic home address  (GH upper)

‘Text home address’ command    (42H)

Graphic area set (GA). This command defines the number of columns of graphics data for the graphics area of VRAM. The graphics area (GA) may be set independently from the number of characters per line set by hardware settings on T6963C controller chip. It is usual to set the GA to the same number of characters per line as the LCD module will display.

First argument                    Number of columns (GA)

Second argument                (00H)

‘Text area’ command            (43H)

Description of ‘mode set’ commands (command byte only)

This command does not require any data byte.

The higher four bits (D7 down through D4) of this command are always ‘1000,’ while lower four bits (D3 down through D0) decide selection of CG-ROM or RAM and how the graphic display is merged with text display. To use both the 128-character on-chip character-generator ROM (CG-ROM) and the 128-character external CG-RAM function, set D3 to ‘0.’ To use only the 256-character CG-RAM user-defined character generator, set D3 to ‘1.’

D0 through D2 set the mode through which the text area is merged with the graphics area. Text attributes can only be used in the text-only mode as the attribute data is stored in the graphics area.
D0 through D2 should be selected as per the need of merging graphics with text.

Logically ‘OR’ of text with graphics                            0 0 0

Logically ‘EXOR’ of text with graphics                         0 0 1

Logically ‘AND’ of text with graphics                           0 1 1

Text only (with attribute data in graphics area)            1 0 0

Description of ‘display mode set’ commands (command byte only)

This command does not require any data byte.

The higher four bits (D7 through D4) of this command are always ‘1001,’ while the lower four bits (D3 through D0) decide the cursor operation.

Display off                    (90H)

D3-                              ‘0’ means graphic ‘off,’

                                   ‘1’ means graphics ‘on’

D2-                              ‘0’ means text ‘off,’

                                   ‘1’ means text ‘on’

D1-                              ‘0’ means cursor ‘off,’

                                   ‘1’ means cursor ‘on’

D0-                              ‘0’ means cursor blinking ‘off,’

                                   ‘1’ means cursor blinking ‘on’

After reset, D3 through D0 are reset to zero.

Description of ‘cursor-pattern select’ command (command byte only)

This command does not require any data byte.

READ
COMPUTERISED MORSE CODE GENERATOR/TRANSMITTER

The higher four bits (D7 through D4) of this command are always ‘1010,’ while the lower four bits (D3 through D0) decide cursor pattern.

1 line cursor                (A0H)

2 line cursor                (A1H)

“ “ “ “ “ “ “ “ “

“ “ “ “ “ “ “ “ “

7 line cursor                (A6H)

8 line cursor                (A7H)

Description of ‘data auto read/ write’ commands (command byte only)

This command does not require any data byte.

The higher six bits (D7 through D2) of this command are always ‘101100,’ while the lower two bits (D1 and D0) decide auto advance mode.

These single-byte commands are very useful when transferring blocks of data to/from the VRAM.

After sending a ‘data auto write’ (B0H) command, it is not necessary to send the data-write instruction for each data byte being written to the VRAM. The ‘data auto-write’ command should be sent after the ‘address pointer set’ command. The address pointer will automatically increment by ‘1’ for each data written. After sending all data, the ‘auto mode-reset’ command (B2H or B3H) should be sent to resume normal operation. When in the ‘data auto-write’ mode, no commands can be accepted, as all the following bytes are assumed to be display data bytes.

After sending a ‘data auto-read’ (B1H) command, it is not necessary to send the data-read instruction for each data byte being read from the VRAM. The ‘data auto-read’ command should be sent after the ‘address pointer set’ command. The address pointer will automatically increment by ‘1’ for each data read. After reading all data, the ‘auto mode reset’ command (B2H or B3H) should be sent to resume normal operation. When in the ‘data autoread’ mode, no commands can be accepted.

Data Auto Write Set       (B0H)

Data Auto Read Set        (B1H)

Auto Mode Reset            (B2H or B3H)

Description of ‘data-read/ data-write’ commands (command byte only)

This command does not require any data byte.

The higher five bits (D7 down through D3) of this command are always ‘11000,’ while the lower three bits (D2 down through D0) decide the pointer-advance mode.

These commands are used to write data to or read data from the VRAM. Data-read or data-write commands should be sent after setting an address by the ‘pointer set’ command. The address pointer may be automatically incremented, decremented or left unchanged depending on which data read/write command is being sent. A datawrite or data-read command is required for each data byte written to or read from the VRAM.

This command should not be confused with B0H and B1H commands. In the case of B0H or B1H command, you need not send a write or read command between each data-write or data-read. But in the case of C0H and C1H commands, after every data write or data read you need to send C0H or C1H for advancing the pointer.

Data Write   –         Address Pointer Auto Incremented (C0H)

Data Read   –          Address Pointer Auto Incremented (C1H)

Data Write   –         Address Pointer Auto Decremented (C2H)

Data Read   –          Address Pointer Auto Decremented (C3H)

Data Write  –          Address Pointer Auto Unchanged (C4H)

Data Read   –          Address Pointer Auto Unchanged (C5H)

Description of ‘screen peeking’ command (command byte only)

This command does not require any data byte.

This single-byte command is used to transfer one byte of displayed data to the data stack and may be read by the microcontroller using a ‘data read’ command. It is useful to read the logical combination of text and graphic data on the LCD screen. The status flag STA6 should be checked after each ‘screen peeking’ command. If the address pointer is not set to the graphics RAM area, the ‘screen peeking’ command is ignored and STA6 is set to ‘1.

Screen Peeking (E0H)

Description of ‘screen copy’ command (command byte only)

This command does not require any data byte.

This single-byte command is used to copy one row of data displayed on the LCD screen to the graphics RAM area specified by the ‘address pointer set’ command. This ‘screen copy’ command cannot be used if the row of displayed data contains ‘text attribute’ data as set by the ‘mode set’ command. The status flag STA6 should be checked after each ‘screen copy’ command. If the address pointer is not set to the graphics RAM area, the ‘screen copy’ command is ignored and STA6 is set to ‘1.’

Screen Copy (E8H)

Description of ‘bit-set/ bit-reset’ command (command byte only)

This command does not require any data byte.

The high-order four bits (D7 through D4) are always ‘1111.’

This single-byte command is used to set/ reset individual bits in the RAM. The ‘address pointer set’ command decides which byte is to be operated on. Any one bit in the byte selected can be set or reset. Multiple bits in a byte cannot be set/ reset at the same time. D2 through D0 specifies the location of the bit to be set/ reset. ‘000’ selects the least significant bit (LSB) and ‘111’ the most significant bit (MSB). For resetting the bit, make D3 as ‘0’ and for setting the bit make D3 as ‘1.’

READ
16-Way Clap-Operated Switch

Bit Reset      (F0H-F7H)

Bit Set         (F8H-FFH)

Circuit description

ZEF_fig-15

After having understood the basic operation of the LCD module, it is fairly simple to interface it with any micro172 Interfacing A Graphics LCD With The Microcontroller controller. Fig. 5 shows the circuit for interfacing the graphics LCD with the microcontroller. Atmel’s AT89S8252 microcontroller (IC2) is used to interface the LCD module. Port P0 (Pins 39 through 32) of the microcontroller is connected to data lines D0 through D7 of the LCD module. Port P0 pins are pulled high with the 10-kilo-ohm resistor network. This data port is used to send and receive the data between the microcontroller and the LCD module. The control lines and RES pins should be connected to port pins P3.3 through P3.7 of the microcontroller, respectively.

8B2_parts-list

EA/VPP pin of the microcontroller is connected to 5 volts to use the internal flash program memory. The power-on-reset for microcontroller IC2 is achieved through capacitor C4 and resistor R3. Diode D5 connected across capacitor C4 allows short power supply failures. A 12MHz crystal is used for internal oscillator clocks. An LED (LED2) is connected at pin P1 of the microcontroller and acts as the program running indicator.

Font-select pin 19 (FS) of the LCD module is grounded to generate 8×8-character font size.

Preset VR1 is used for contrast variation of the LCD. Normally –7.8V will give good contrast. VEE is a negative supply voltage output from the LCD module that outputs around –14 volts.

The LCD modules have an inbuilt fluorescent tube as backlight source. This needs a special inverter that comes with the LCD module as optional. It works off 5V supply and generates 100-200V AC, which is connected to ‘A’ and ‘K’ terminals of the LCD module. If you opted for the LED backlight module, you may not need this inverter.

The 230V, 50Hz AC mains is stepped down by transformer X1 to deliver a secondary output of 9V, 500 mA. The transformer output is rectified by a full-wave bridge rectifier comprising diodes D1 through D4, filtered by capacitor C1 and regulated by IC 7805 (IC1). Provide adequate heat-sink for 7805 as the LCD backlight draws a significant current. Capacitor C2 bypasses the ripples present in the output. LED1 acts as the power indicator. Resistors R1 and R2 act as the current limiters for LED1 and LED2, respectively.

Software program

The software program presented here for the operation of LCD module is just an example and you have to re-develop it for your application. The software is written in ANSI C language and compiled using KEIL compiler. The program has enough remarks inserted on the lines so you can easily understand what the program instructions are really doing.

Starting from the main line, first the ports are initialised, and then the LED blinks four times to indicate that the program and the hardware are working. Basically, the LCD module is first reset and initialised. After initialisation, the LCD module is loaded with graphics data and then with text data. The graphics data contains a scene of the Sun in the background of a tree and hills. The text inserted is ‘The SUN.’ A blinking cursor is also shown as an example. At the end, the ‘graphic and text on’ command is inserted before ending the program with an infinite wait loop.

Note that no data or command should be written to the LCD module if the module is busy doing its own internal operation. As such a subroutine is inserted before every write operation to check whether the LCD module is busy or free. This is done in the ‘check status’ subroutine where both D0 and D1 bits are checked before proceeding any further.

Also note that:
The LCD module has a built-in CG-ROM with 128 characters possible. You can use this address to insert any text character. For example, ‘21H’ will mean ‘A.’

You can make a graphics ‘.bmp’ file of your choice in ‘paint’ software on a 240×128-pixel paper size and use FONTGEN software to convert the ‘.bmp’ image into graphics data file as required by the LCD module. Copy the graphics data code (generated by FONTGEN software) and paste in the source program at the indicated place. For downloading the FONTGEN, visit www.8052.com .

Download source code: click here

Download actual-size single-side PCB layout and component layout: click here

LEAVE A REPLY