INterface LCD

32
AN036401-1013 1 Abstract This application demonstrates how to drive a VIM–404 LCD using the Z51F3220 MCU’s dedicated LCD driver, and includes a discussion about basic LCD operation and Z51F3220 LCD peripheral initialization. Application programming interfaces (APIs) are provided for users to begin using the Z51F3220 LCD peripheral. The source code file associated with this application note, AN0364-SC01.zip , is available free for download from the Zilog website. This source code was compiled using the Keil μVision4 and Small Device C Compiler (SDCC) v 3.1.0 tools. The Keil μVision4 develop- ment tool is available from Keil; the SDCC v3.1.0 tool is included in version 2.1 of the Z8051 Software and Documentation set, which is available free for download from the Zilog Store . For this source code to work properly with other Z8051 MCUs, minor modifi- cations to the source code may be required. Discussion Liquid Crystal Display (LCD) technology is a passive display technology. An LCD does not emit light nor produce light to display an image. An LCD only uses and modifies ambient light from the environment to display images. The LCD product used in this application is based on a Twisted Nematic (TN) liquid crys- tal technology. The molecules within TN liquid crystals exhibit the ability to twist or untwist, at varying degrees, to block or allow light waves to pass. An LCD panel, as shown in Figure 1, is composed of liquid crystal, polarizer, mirror, glass, backplane or common (COM) electrodes and frontplane or segment (SEG) elec- trodes. The TN liquid crystal exhibits rod-like molecules which can be aligned to change orientation by varying the applied electric field on COM and SEG electrodes. The func- tion of the liquid crystal is to change or to not change the polarization of the light entering the LCD panel. Two polarizers are used in an LCD panel: the front or vertical polarizer and the rear or horizontal polarizer. These polarizers are used to optically filter the lights and make the image display on the LCD panel as either ON or OFF. The glasses are used to provide support to the polarizer and electrode. The mirror being used reflects the light that enters the LCD panel. Note: AN036401-1013 Application Note Interfacing an LCD to the Z51F3220 MCU

description

Interface LCD

Transcript of INterface LCD

Page 1: INterface LCD

AN036401-1013

Application Note

Interfacing an LCD to the Z51F3220 MCU

Abstract

This application demonstrates how to drive a VIM–404 LCD using the Z51F3220 MCU’s dedicated LCD driver, and includes a discussion about basic LCD operation and Z51F3220 LCD peripheral initialization. Application programming interfaces (APIs) are provided for users to begin using the Z51F3220 LCD peripheral.

The source code file associated with this application note, AN0364-SC01.zip, is available free for download from the Zilog website. This source code was compiled using the Keil μVision4 and Small Device C Compiler (SDCC) v 3.1.0 tools. The Keil μVision4 develop-ment tool is available from Keil; the SDCC v3.1.0 tool is included in version 2.1 of the Z8051 Software and Documentation set, which is available free for download from the Zilog Store. For this source code to work properly with other Z8051 MCUs, minor modifi-cations to the source code may be required.

Discussion

Liquid Crystal Display (LCD) technology is a passive display technology. An LCD does not emit light nor produce light to display an image. An LCD only uses and modifies ambient light from the environment to display images.

The LCD product used in this application is based on a Twisted Nematic (TN) liquid crys-tal technology. The molecules within TN liquid crystals exhibit the ability to twist or untwist, at varying degrees, to block or allow light waves to pass.

An LCD panel, as shown in Figure 1, is composed of liquid crystal, polarizer, mirror, glass, backplane or common (COM) electrodes and frontplane or segment (SEG) elec-trodes. The TN liquid crystal exhibits rod-like molecules which can be aligned to change orientation by varying the applied electric field on COM and SEG electrodes. The func-tion of the liquid crystal is to change or to not change the polarization of the light entering the LCD panel. Two polarizers are used in an LCD panel: the front or vertical polarizer and the rear or horizontal polarizer. These polarizers are used to optically filter the lights and make the image display on the LCD panel as either ON or OFF. The glasses are used to provide support to the polarizer and electrode. The mirror being used reflects the light that enters the LCD panel.

Note:

AN036401-1013 1

Page 2: INterface LCD

Interfacing an LCD to the Z51F3220 MCUApplication Note

LCD Display OFFWhen light enters the LCD panel, the front polarizer accepts only the vertically-polarized light. The light passes the backplane electrode and goes to the TN liquid crystals. If there is no signal applied to the SEG and COM electrodes, then the orientation of the molecules on the TN liquid crystals will twist the light 90 degrees, causing the light signal to be hori-zontally polarized. The light passes the segment electrode and the rear (i.e., horizontal) polarizer. The light hits the mirror and reflects back along the same path. When this reflected light reaches the viewer, there is no image on the LCD because there is no light obstruction.

LCD Display ONTo reiterate from above, the front polarizer accepts only the vertically-polarized light when it enters the LCD. When light passes the backplane electrode and goes to the TN liq-uid crystals, and if a signal is applied to the SEG and COM electrodes, the orientation of the molecules on the TN liquid crystals is aligned to the vertical polarizer. Therefore, the light will pass the liquid crystals without changing the polarization of the light. The light also passes the segment electrode. Because the light is vertically polarized, the light will not pass the rear or horizontal polarizer. The light will not hit the mirror, and there will be no reflected light wave. In effect, the viewer sees light that has been obstructed and, as a result, an image appears on the LCD.

Basic LCD Operation

An LCD is composed of individually-controlled segments, each of which is connected to the SEG and COM terminals. To turn a segment ON and OFF, an AC signal must be applied on the SEG and COM terminals.

Figure 1. LCD Panel Basic Composition

AN036401-1013 2

Page 3: INterface LCD

Interfacing an LCD to the Z51F3220 MCUApplication Note

One characteristic of the liquid crystal material prohibits the use of a DC signal. Figure 2 shows AC signals applied to the SEG and COM terminals of a single segment. The volt-age across the segment, VSEG, represents the difference between the COM terminal signal and the SEG terminal signal. VRMS is the equivalent root mean square (rms) of the signal across VSEG.

Zilog recommends against using a DC signal because the signal will damage the LCD per-manently.

VRMS is defined in the following equation.

In Figure 2, the signals on the SEG and COM terminals are in phase with each other. The voltage across VSEG is 0 V, and its VRMS value is also 0 V, which means that the single LCD segment is OFF.

Note:

)...(*1 22

22

1 nrms VVVn

V

AN036401-1013 3

Page 4: INterface LCD

Interfacing an LCD to the Z51F3220 MCUApplication Note

In Figure 3, the signals on the SEG and COM terminals are out of phase with each other. By obtaining the difference between these two signals, VSEG at T0 is a negative (–) VDD, and at T1 it is positive (+) VDD. By using the VRMS equation, the effective voltage across the single LCD segment is equal to VDD, which means that the segment is ON.

Figure 2. Single LCD Segment Drive OFF

AN036401-1013 4

Page 5: INterface LCD

Interfacing an LCD to the Z51F3220 MCUApplication Note

VIM-404 LCDThis application uses the VIM-404 LCD, which is also included in the Z51F3220 Devel-opment Kit. This VIM-404 LCD is a 20-pin device, with which 3 pins are used for the COM signal, 12 pins are used for the SEG signal, and 5 pins have no connections. This LCD features four seven-segment displays (Digit 1 to Digit 4) and three decimal points, as shown in Figure 4; these three decimal points represent digits 1 to 3. In this figure, the LCD segments of each digit are labeled A, B, C, D, E, F, and G; decimal points are labeled P.

Figure 3. Single LCD Segment Drive ON

AN036401-1013 5

Page 6: INterface LCD

Interfacing an LCD to the Z51F3220 MCUApplication Note

Table 1 lists the pin assignments for the VIM-404 LCD panel.

Figure 4. Illustration of the VIM-404 LCD Panel

Table 1. VIM-404 LCD Pin Assignment

Pin # Description Pin # Description

1 NC 11 COM1

2 NC 12 SEG12

3 NC 13 SEG11

4 SEG1 14 SEG10

5 SEG2 15 SEG9

6 SEG3 16 SEG8

7 SEG4 17 SEG7

8 COM3 18 SEG6

9 NC 19 SEG5

10 NC 20 COM2

Notes:1. NC: No Connection.2. COMx: Backplane or common electrode terminal.3. SEGx: Frontplane or segment electrode terminal.

AN036401-1013 6

Page 7: INterface LCD

Interfacing an LCD to the Z51F3220 MCUApplication Note

Figure 5 shows how the LCD segments of Digit 1 are connected to the COM and SEG ter-minals. LCD segments Digit 2 to Digit 4 are connected to the COM and SEG terminals in the same manner.

Table 2 lists the LCD segment’s connections to the COM and SEG terminals, including decimal points. For example, LCD segment B of Digit 1 (1B) is connected to terminals SEG1 and COM1.

Figure 5. Digit 1 Pin Assignment

Table 2. VIM-404 LCD Segments Connections to Terminals

Segment COM1 COM2 COM3

SEG1 1B 1C 1P

SEG2 2B 2C 2P

SEG3 3B 3C 3P

SEG4 4B 4C –

SEG5 1F 1E –

AN036401-1013 7

Page 8: INterface LCD

Interfacing an LCD to the Z51F3220 MCUApplication Note

LCD Drive MethodsThere are two ways to drive the LCD: the Static, or Direct Drive method, and the Multi-plex method, as discussed below.

Static or Direct Drive Method

The Static or Direct Drive method is used when an LCD features only one COM terminal for all of the segments, as shown in Figure 6.

This method uses static bias, for which there are only two voltage levels involved in driv-ing the LCD, VDD and 0 V at a 50% duty cycle. This method creates a square wave signal that is supplied to the COM and SEG terminals.

In Figure 6, the seven LCD segments feature one COM terminal and seven SEG terminals. To turn ON a segment, signals on the COM and SEG terminals must be out of phase with

SEG6 1A 1G 1D

SEG7 2F 2E –

SEG8 2A 2G 2D

SEG9 3F 3E –

SEG10 3A 3G 3D

SEG11 4F 4E –

SEG12 4A 4G 4D

Figure 6. Direct Drive Seven-Segment Connections

Table 2. VIM-404 LCD Segments Connections to Terminals (Continued)

Segment COM1 COM2 COM3

AN036401-1013 8

Page 9: INterface LCD

Interfacing an LCD to the Z51F3220 MCUApplication Note

each other. To turn OFF a segment, signals on the COM and SEG terminals must be in phase with each other.

Example. To turn ON LCD segments B and C, signals on SEG2 and SEG3 must be out of phase with the signal on the COM terminal. The signals from all other SEG terminals must be in phase with the COM terminal signal.

The main advantage of using the Static or Direct Drive method is that it is easy to imple-ment. However, if the number of segments increases, the SEG terminal also increases. If the SEG terminal increases, the number of pins required to drive the SEG terminals also increases.

Multiplex Drive Method

The Multiplex LCD drive method is used when an LCD features more than one COM ter-minal. The Multiplex method is used in this application because the VIM-404 LCD fea-tures three COM terminals.

If you plan to convert the VIM-404 LCD to a Direct Drive method, the number of MCU pins required to drive the LCD is 32 pins; i.e., 1 pin for COM and 31 pins for SEG. These 31 SEG pins represent the four digits with seven segments each (i.e., 28 segments) and three decimal points. However, because the VIM-404 LCD is designed for the Multiplex drive method, the LCD only requires 15 MCU pins; i.e., 3 pins for COM and 12 pins for SEG. The advantage of using the Multiplex drive method is that fewer pins are required to drive the LCD. Table 3 lists the pin connections between the Z51F3220 MCU and the VIM-404 LCD.

Table 3. Z51F3220 and VIM-404 LCD Connections

Z51F3220 VIM-404 LCD

Pin # Description Pin # Description

9 SEG1 4 SEG1

10 SEG2 5 SEG2

11 SEG3 6 SEG3

12 SEG4 7 SEG4

13 SEG5 19 SEG5

14 SEG6 18 SEG6

15 SEG7 17 SEG7

16 SEG8 16 SEG8

17 SEG9 15 SEG9

18 SEG10 14 SEG10

23 SEG15 13 SEG11

24 SEG16 12 SEG12

6 COM0 11 COM1

7 COM1 20 COM2

8 COM2 8 COM3

AN036401-1013 9

Page 10: INterface LCD

Interfacing an LCD to the Z51F3220 MCUApplication Note

Frame FrequencyWith the Multiplex drive method, driving the COM pins of the LCD is time-multiplexed. The VIM-404 LCD features three COM pins that require three time slots; the number of time slots is equal to the number of COM pins.

Figure 7 shows the time slots for the VIM-404 LCD. Combined time slots (T0, T1 and T2) are defined as 1 frame; and two frames constitute 1 cycle.

For Frame 1, only one COM is driven to VDD at a given time slot. For Frame 2, only one COM is driven to 0 V at a given time slot.

Frame frequency is the inverse of the sum of T0, T1, and T2. Typically, the frame fre-quency ranges from 50 Hz–150 Hz. Lower frequencies can result in image flickering on the LCD, while higher frequencies often result in higher power consumption.

The Z51F3220 MCU can provide a frame frequency (fLCD) of:

• 128 Hz

• 256 Hz

• 512 Hz

• 1024 Hz

The frame frequency can be selected using the LCD Driver Control Low (LCDCRL) Reg-ister.

The watch timer (fWCK) supplies the clock to the Z51F3220 MCU’s LCD driver, and must be set to 32.768 kHz. The clock source of the watch timer can be sourced either from the system clock oscillator (fX) or subclock oscillator (fSUB). If the subclock oscillator is used as a watch timer clock source, then fWCK will be 32.768 kHz, which is the subclock oscil-lator frequency of the Z51F3220. If the system clock source is used as a watch timer clock source, it should be divisible by 256, 128, or 64 to obtain the required 32.768 kHz watch timer clock frequency.

When using a system clock oscillator as a watch timer clock source, choose a frequency that will provide 32.768 kHz after the clock division.

Example. If 4.19 MHz is used as fX, fX must be divisible by 128 to achieve the required frequency of approximately 32.7 kHz, the value of fWCK.

Figure 7. Time-Multiplexed Diagram

AN036401-1013 10

Page 11: INterface LCD

Interfacing an LCD to the Z51F3220 MCUApplication Note

The Z51F3220 MCU’s Watch Timer Control (WTCR) Register is used to:

• Enable the watch timer

• Select the watch timer source (system clock or subclock oscillator)

• Select the value that will divide the system clock frequency if it is selected as the watch timer source

Duty Cycle RatioThe Duty Cycle Ratio indicates the number of COM terminals. The Duty Cycle Ratio is defined as presented in the following equation, in which n is the number of COM termi-nals.

In a Pulse Width Modulation (PWM), using the Multiplex LCD drive method, the duty cycle refers to the ratio of time ON vs. time OFF; i.e., the ratio of time during which COM is driven to VDD to the time during which COM is not driven to VDD. The duty cycle is also the same as the ratio of time when COM is driven to 0 V and the time when COM is not driven to 0 V.

In the Z51F3220 MCU, the duty cycle ratio is selected via the LCD Driver Control Low (LCDCRL) Register.

BiasBias refers to the number of voltage levels a signal supplies to the COM of the LCD. For the Z51F3220 MCU’s LCDCRL Register, bias is selected together with the duty cycle, as indicated in the following list.

• 1/8 duty, 1/4 bias (60 KΩ)

• 1/6 duty, 1/4 bias (60 KΩ)

• 1/5 duty, 1/3 bias (60 KΩ)

• 1/4 duty, 1/3 bias (60 KΩ)

• 1/3 duty, 1/3 bias (60 KΩ)

• 1/3 duty, 1/2 bias (60 KΩ)

• 1/3 duty, 1/2 bias (120 KΩ)

• 1/2 duty, 1/2 bias (60 KΩ)

• 1/2 duty, 1/2 bias (120 KΩ)

For this application, in which the VIM-404 LCD is used with three COM terminals, apply-ing the Duty Cycle Ratio equation results in a duty cycle ratio of 1/3. The LCDCRL Reg-ister offers three choices of bias for the 1/3 duty cycle, namely 1/3 bias (60 KΩ), 1/2 bias

natioDutyCycleR

1

AN036401-1013 11

Page 12: INterface LCD

Interfacing an LCD to the Z51F3220 MCUApplication Note

(120 KΩ), and 1/2 bias (60 KΩ). Figure 8 shows the resistor bias connection, with R equal to 60 KΩ. VLCx are the voltage levels driven to the COM of the LCD, in which x = 0 to 3.

If the LCD’s contrast controller is disabled, VLC0 = VDD. When using the voltage divider, VLC1 = 75% of VLC0, VLC2 = 50% of VLC0, and VLC3 = 25% of VLC0.

1/3 Bias

For 1/3 bias (60KΩ), VLC2 and VLC3 are connected together bypassing the resistor between them, as illustrated in Figure 9. With this configuration, the VLCx values are:

• VLC0 = VDD

• VLC1 = 2/3 * VLC0

• VLC2 = VLC3 = 1/3 * VLC0

1/2 Bias

For 1/2 bias (120KΩ), VLC1 and VLC3 are not used, as illustrated in Figure 10. With this configuration, the VLCx values are:

• VLC0 = VDD

• VLC2 = 1/2 * VLC0

Figure 8. Resistor Bias Connection

Figure 9. Resistor Bias Connection (1/3 bias 60 KΩ)

AN036401-1013 12

Page 13: INterface LCD

Interfacing an LCD to the Z51F3220 MCUApplication Note

1/2 Bias

For 1/2 bias (60KΩ), VLC1, VLC2, and VLC3 are connected, and they bypass the resis-tors between them, as illustrated in Figure 11. With this configuration, the VLCx values are:

• VLC0 = VDD

• VLC1 = VLC2 = VLC3 = 1/2 * VLC0

ContrastContrast can be defined in terms of the brightness of an LCD image. This function can be controlled by enabling the contrast controller of the Z51F3220 MCU’s LCD driver on the LCD Driver Control High (LCDCRH) Register.

When the contrast controller is enabled, the VLC0 value can be varied by the factors listed in Table 4. The VLC0 value can be selected in the LCDCRH Register. By varying the VLC0 value, the voltage levels that will drive the COM of the LCD also vary. Higher val-ues of VLC0 determine a higher contrast, and lower values of VLC0 result in a lower con-trast.

Figure 10. Resistor Bias Connection (1/2 bias 120 KΩ)

Figure 11. Resistor Bias Connection (1/2 Bias 60 KΩ)

AN036401-1013 13

Page 14: INterface LCD

Interfacing an LCD to the Z51F3220 MCUApplication Note

Sample LCD Displays and Signals

When Digit1, Segment A of the VIM-404 LCD is turned ON (see Figure 12), the signals generated by the LCD driver for this display are illustrated in Figure 13.

Table 4. VLC0 Values to Control Contrast

VLC0

VDD * 16/31 VDD * 16/23

VDD * 16/30 VDD * 16/22

VDD * 16/29 VDD * 16/21

VDD * 16/28 VDD * 16/20

VDD * 16/27 VDD * 16/19

VDD * 16/26 VDD * 16/18

VDD * 16/25 VDD * 16/17

VDD * 16/24 VDD * 16/16

Figure 12. LCD Segment A, Digit 1: ON

AN036401-1013 14

Page 15: INterface LCD

Interfacing an LCD to the Z51F3220 MCUApplication Note

The VRMS value across an LCD segment indicates whether the segment is ON or OFF. Ideally, if the VRMS value is greater than the LCD threshold voltage, the segment is ON; otherwise, the segment is OFF. In reality, the OFF segment is not completely OFF. An OFF segment displays lower contrast compared to an ON segment, which makes the ON segment more visible to the viewer.

For the Z51F3220 MCU and VIM-404 LCD setup, the ON segment exhibits 2.8 VRMS, and the OFF segment exhibits 1.5 VRMS. Table 5 lists the VRMS values for the Digit 1 seg-ments (A, B, C D, G, and P) based on the VRMS equation discussed on page 3 and the sig-nals shown in Figure 13.

Figure 13. Signals to Turn ON LCD Segment A

AN036401-1013 15

Page 16: INterface LCD

Interfacing an LCD to the Z51F3220 MCUApplication Note

Example. The voltage supply to the LCD is 4.5 V, and the Z51F3220 MCU’s LCD driver contrast controller is disabled; a duty cycle ratio of 1/3 is used, along with a 1/3 bias (60KΩ). Given these conditions, VLC0 = VDD, and the voltage levels of the signals shown in Figure 13 are:

• VLC0 = 4.5 V

• VCL1 = 3.0 V

• VLC2 = VLC3 = 1.5 V

• VSS = 0 V

In Table 5, the first column lists the LCD segments used to connect the COM and SEG ter-minals (shown in the second and third columns). To obtain voltage across an LCD seg-ment, compute the difference between the COM and SEG voltages. This process should be performed at T0, T1, and T2. Voltages across these LCD segments should be calculated using the VRMS equation discussed on page 3. These VRMS values indicate whether an LCD segment is ON or OFF.

LCD RAM Addresses and Display DataThe Z51F3220 MCU dedicates 27 RAM locations for the LCD display data listed in Table 6. These LCD RAM addresses accept the display data that will turn the LCD’s seg-ments ON or OFF. Each LCD RAM address is dedicated to a SEG.

Example. LCD RAM address 0x0001 is mapped to SEG1.

Each bit in the display data refers to COM. A logic 0 in this display data means that the LCD display is OFF; a logic 1 means that the LCD display is ON.

Table 5. Voltage Root Mean Square of LCD Segments

Digit 1 Segments

Terminals

Voltage Across Segment (COM–SEG)

VRMS

Segment ON or OFF

Frame 1

COM SEG T0 T1 T2

A COM1 SEG6 4.5V –1.5V –1.5V 2.87V ON

B COM1 SEG1 1.5V –1.5V –1.5V 1.5V OFF

C COM2 SEG1 –1.5V 1.5V –1.5V 1.5V OFF

D COM3 SEG6 1.5V –1.5V 1.5V 1.5V OFF

G COM2 SEG6 1.5V 1.5V –1.5V 1.5V OFF

P COM3 SEG1 –1.5V –1.5V 1.5V 1.5V OFF

AN036401-1013 16

Page 17: INterface LCD

Interfacing an LCD to the Z51F3220 MCUApplication Note

Example. If the number 4 is displayed on Digit1 of the VIM-404 LCD, as shown in Figure 14. Data is sent to RAM in a parallel sequence; however, data to be displayed on the LCD is displayed in a consecutive sequence.

To display the number 4 on digit 1 of the VIM-404 LCD, the following LCD segments should be turned ON: B, C, F, and G.

Table 6. LCD Display RAM Locations

RAM Addresses (hex)

COM

Bit7 Bit6 Bit5 Bit4 Bit3 Bit2 Bit1 Bit0

COM7 COM6 COM5 COM4 COM3 COM2 COM1 COM0

0000 SEG0

0001 SEG1

0002 SEG2

0003 SEG3

0004 SEG4

0005 SEG5

0006 SEG6

0007 SEG7

0008 SEG8

0009 SEG9

000A SEG10

000B SEG11

000C SEG12

000D SEG13

000E SEG14

000F SEG15

0010 SEG16

0011 SEG17

0012 SEG18

0013 SEG19

0014 SEG20

0015 SEG21

0016 SEG22

0017 SEG23

0018 SEG24

0019 SEG25

001A SEG26

AN036401-1013 17

Page 18: INterface LCD

Interfacing an LCD to the Z51F3220 MCUApplication Note

COM1, COM2, and COM3 of the VIM-404 LCD are connected to COM0, COM1, and COM2 of the Z51F3220 MCU, respectively. Refer to Table 3 on page 9.

To turn ON LCD segments B and C, the display data is 0x03. This information should be sent to LCD RAM address 0x0001, which is the address for SEG1. LCD segments B and C are connected to COM1 and COM2 of the VIM-404 LCD, respectively. Both COM1 and COM2 of the VIM-404 LCD are connected to SEG1.

Figure 14. Digit 1 Number 4 Display

Table 7. Display Data for Digit1 Number 4

RAM Addresses (hex)

Display Data

Bit7 Bit6 Bit5 Bit4 Bit3 Bit2 Bit1 Bit0

COM7 COM6 COM5 COM4 COM3 COM2 COM1 COM0

0001 0 0 0 0 0 0 1 1

0005 0 0 0 0 0 0 0 1

0006 0 0 0 0 0 0 1 0

Note:

AN036401-1013 18

Page 19: INterface LCD

Interfacing an LCD to the Z51F3220 MCUApplication Note

To turn ON LCD segment F, the display data is 0x01. This information should be sent to LCD RAM address 0x0005, which is the address for SEG5. LCD segment F is connected to COM1 and SEG5 of the VIM-404 LCD.

To turn ON LCD segment G, the display data is 0x02. This information should be sent to LCD RAM address 0x0006, which is the address for SEG6. LCD segment G is connected to COM2 and SEG6 of the VIM-404 LCD.

Please refer to Table 2 on page 7 to determine the connections of the LCD segments to the SEG and COM terminals.

Firmware Design

This section discusses the two main parts of the firmware developed for this application, which are:

• Initialization of the LCD driver

• LCD application programming interfaces (API)

InitializationTable 8 lists all of the registers and functions used to initialize the LCD driver.

Table 8. LCD Initialization Registers and Functions

Functions Registers Description

OSC_Init() System and Clock Control (SCCR) Register

Selects internal RC oscillator as the system clock source.

Oscillator Control (OSCCR) Register

Selects 16 MHz as the frequency of the internal RC oscillator.

LCD_ClockSource() Port 5 Function Selection (P5FSR) Register

Set up SXIN and SXOUT for 32 kHz subcrystal oscillator.

Oscillator Control (OSCCR) Register

Enables subcrystal oscillator.

Watch Timer Count (WTCR) Register

Enables watch timer, selects subcrystal oscillator as the clock source of watch timer.

LCD_DriverRegisters() LCD Driver Control High (LCDCRH) Register

Selects P3[7:4] as COM0-COM3 LCD terminals; internal bias resistors; and as normal display ON.

LCD Driver Control Low (LCDCRL) Register

Selects 1/3 duty cycle ratio, 1/3 bias and 256Hz LCD clock frequency.

LCD Driver Contrast Control (LCDCCR) Register

Disables LCD contrast.

Note:

AN036401-1013 19

Page 20: INterface LCD

Interfacing an LCD to the Z51F3220 MCUApplication Note

In Table 8, SEG15 and SEG16 are configured as LCD terminals instead of SEG11 and SEG12, because the Z51F3220 Development Board connects SEG15 and SEG16 to VIM-404 LCD SEG11 and SEG12, respectively.

Please refer to Table 3 on page 9 to determine the COM and SEG connections between the VIM-404 LCD and the Z51F3220 MCU.

LCD APIsThe following seven APIs are described in this section:

• LCD_ClearDisplay

• LCD_DisplayError

• LCD_DigitSegmentDisp

• LCD_DigitNumberDisp

• LCD_UnsignedNumDisp

• LCD_SignedNumDisp

• LCD_FloatDisplay

LCD_ClearDisplay

This function clears the LCD display by sending logic 0s to all of the LCD segments. Attributes: none.

LCD_DisplayError

This function is used to indicate an error. As shown in Figure 15, this function displays Err when an error occurs. Attributes: none.

LCD_ConfigPorts() Port 3 Function Selection (P3FSR) Register

Configures Port 3 as COM0-COM2 and SEG1-SEG5 LCD terminals.

Port 2 Function Selection High (P2FSRH) Register

Configures Port2 as SEG6-SEG9 LCD terminals.

Port 2 Function Selection Low (P2FSRL) Register

Configures Port 2 as SEG10 LCD terminals.

Port 1 Function Selection Low (P1FSRL) Register

Configures Port 1 as SEG15-SEG16 LCD terminals.

Table 8. LCD Initialization Registers and Functions (Continued)

Functions Registers Description

Note:

AN036401-1013 20

Page 21: INterface LCD

Interfacing an LCD to the Z51F3220 MCUApplication Note

LCD_DigitSegmentDisp

This function displays an LCD segment of a digit. Attributes: UCHAR ucDigit and UCHAR ucSegment.

• ucDigit represents data that indicates the VIM-404 LCD digit position, as indicated in Table 9.

Figure 15. LCD Error Display

Table 9. Digit Positions

ucDigitVIM-404 LCD Digit Position

0 Digit 1

1 Digit 2

2 Digit 3

3 Digit 4

AN036401-1013 21

Page 22: INterface LCD

Interfacing an LCD to the Z51F3220 MCUApplication Note

• ucSegment represents data that indicates the LCD segment, as indicated in Table 10. If the value of ucDigit is more than 3, or if the value of ucSegment is more than 6, an error is displayed on the LCD.

Example 1

Table 10. LCD Segments

ucSegmentVIM-404 LCD

Segments

0 A

1 B

2 C

3 D

4 E

5 F

6 G

LCD_DigitSegmentDisp (0,0); This line of code displays LCD segment A of Digit 1 as shown in the second quadrant of Figure 16.

LCD_DigitSegmentDisp (1,6); This line of code displays LCD segment G of Digit 2 as shown in the first quadrant of Figure 16.

LCD_DigitSegmentDisp (2,5); This line of code displays LCD segment F of Digit 3 as shown in the third quadrant of Figure 16.

LCD_DigitSegmentDisp (3,2); This line of code displays LCD segment C of Digit 4 as shown in the forth quadrant of Figure 16.

AN036401-1013 22

Page 23: INterface LCD

Interfacing an LCD to the Z51F3220 MCUApplication Note

LCD_DigitNumberDisp

This function displays decimal numbers on a specified digit position on the VIM-404 LCD. Attributes: UCHAR ucDigit and UCHAR ucNumber.

• ucDigit is the data which indicates the VIM-404 LCD digit position as listed in Table 9 on page 21

• ucNumber is the decimal number to be displayed on the VIM-404 LCD

If the value of ucDigit is more than 3, or if the value of ucNumber is more than 9, an error is displayed on the LCD.

Figure 16. LCD Segment Display

AN036401-1013 23

Page 24: INterface LCD

Interfacing an LCD to the Z51F3220 MCUApplication Note

Example 2

LCD_UnsignedNumDisp

This function is used to display decimal numbers from 0000 up to 9999. If the uiData is greater than 9999, an error will be display on the LCD. Attribute: UINT uiData.

LCD_DigitNumberDisp (0,4); This line of code displays number 4 on Digit 1 as shown in the second quadrant of Figure 17.

LCD_DigitNumberDisp (1,3); This line of code displays number 3 on Digit 2 as shown in the first quadrant of Figure 17.

LCD_DigitNumberDisp (2,2); This line of code displays number 2 on Digit 3 as shown in the third quadrant of Figure 17.

LCD_DigitNumberDisp (3,1); This line of code displays number 1 on Digit 4 as shown in the forth quadrant of Figure 17.

Figure 17. LCD Digit Displays

AN036401-1013 24

Page 25: INterface LCD

Interfacing an LCD to the Z51F3220 MCUApplication Note

Example . LCD_UnsignedNumDisp(1234);

This line of code displays decimal number 1234 on the LCD as shown in Figure 18.

LCD_SignedNumDisp

This function is used to display decimal numbers from –999 up to 9999. If the iData is beyond –999 and 9999, an error will be display on the LCD. Attribute: INT iData.

Example. LCD_SignedNumDisp(–123);

This line of code displays decimal number –123 on the LCD, as shown in Figure 19.

Figure 18. Example of an Unsigned Number

AN036401-1013 25

Page 26: INterface LCD

Interfacing an LCD to the Z51F3220 MCUApplication Note

LCD_FloatDisplay

This function is used to display decimal numbers from –99.9 up to –0.01 and from 0.001 up to 999.9. If fData is outside the range that spans –99.9 to 999.9, an error will be dis-play on the LCD. Attribute: FLOAT fData.

Example 1. LCD_FloatDisplay(123.4);

Example 2. LCD_FloatDisplay(–1.23);

These lines of code display the decimal numbers 123.4 and –1.23 on the LCD, as shown in Figure 20.

Figure 19. Example of a Signed Number

AN036401-1013 26

Page 27: INterface LCD

Interfacing an LCD to the Z51F3220 MCUApplication Note

Tools Required

• Keil Compiler µVision V4.24.00.0

• SDCC Compiler 3.1.0

• Z51F3220 Development Kit

• Zilog Z8051 OCD 1.147

• Z8051 OCD Cable

Testing/Demonstrating the Application

This application includes sample code to show how to use the API; this sample code is contained in the main.c file that is contained in the AN0364-SC01.zip source code file. There are two methods for compiling and testing this code:

• Use the Keil compiler for compiling and debugging

• Use the SDCC compiler for compiling the code, and use Zilog’s Z8051 OCD software to download a hex file to the Z8051 MCU

The remainder of this section provides procedures for enabling these two methods.

Test the Code Using the Keil CompilerObserve the following procedure to test the code using the Keil compiler.

1. Connect the Z51F3220 Development Board to a PC using the Z8051 On-Chip Debug-ger cable.

2. Connect one end of the USB A (male) to Mini-B cable (which is contained in the Z51F3220 Development Kit) to the Z51F3220 Development Board, and connect the other end of this cable to the PC’s USB port. The indicator LED near the Board’s USB mini port should illuminate, indicating that the Board is powered up.

Figure 20. Sample Float LCD Display

AN036401-1013 27

Page 28: INterface LCD

Interfacing an LCD to the Z51F3220 MCUApplication Note

3. Download the AN0364-SC01.zip file and unzip it to a convenient location on your PC.

4. Launch the Keil compiler. Select Open Project from the Project menu, and locate the AN0364-SC01 folder from the location in which you saved it on your PC. Open the LCDDRIVE_Z51F3220.uvproj project, which is located in the following filepath:

<PC Directory>\AN0634-SC01\LCD_DRIVE_Z51F3220_Keil

In this path, <PC Directory> is the location of the unzipped AN0364-SC01 file.

5. From the Project menu, select Rebuild all target files to recompile all project files.

6. From the Flash menu, select Download to download the code to the MCU.

7. From the Debug menu, select Start/Stop Debug Session to begin debugging.

8. The LCD will continuously perform the following tasks:

– Turn ON each LCD segment, one at a time

– Count 0 to 9, each digit at a time

– Display 1234, –123, and –1.23 at one-second intervals

Test the Code Using the SDCC CompilerObserve the following procedure to compile the code using the SDCC compiler and down-load a hex file to the Z51F3220 MCU using the Z8051 OCD software.

Debugging is not possible when using the SDCC compiler. The following procedure is intended merely as a guide to compiling and downloading the code to the MCU using the SDCC compiler.

1. Connect the Z51F3220 Development Board to a PC using the Z8051 On-Chip Debug-ger cable.

2. Connect one end of the USB A (male) to Mini-B cable (which is contained in the Z51F3220 Development Kit) to the Z51F3220 Development Board, and connect the other end of this cable to the PC’s USB port. The indicator LED near the Board’s USB mini port should illuminate, indicating that the Board is powered up.

3. Download the AN0364-SC01.zip file and unzip it to a convenient location on your PC.

4. Navigate via the following file path to locate the LCDDRIVE_Z51F3220.bat file.

<PC Directory>\AN0364-SC01\LCD_DRIVE_Z51F3220_SDCC

Ensure that the INSTALL_DIR variable contained in the batch file displays the correct installation path for Z8051_2.1 on your PC. If not, change it to the correct path and save the file.

Note:

Note:

AN036401-1013 28

Page 29: INterface LCD

Interfacing an LCD to the Z51F3220 MCUApplication Note

In this path, <PC Directory> is the location of the unzipped AN0364-SC01 file.

5. Launch the Zilog Z8051 OCD Debugger software.

6. If a Disconnected message is displayed by the debugger, turn the Z51F3220 Development Board OFF, then ON.

7. From the Debugger’s File menu, select Load Hex. The Object File dialog will appear.

8. Click the Browse… button, then locate and open the LCDDRIVE_Z51F3220.hex file from within the following filepath:

<PC Directory>\0364SC01\ LCD_DRIVE_Z51F3220_SDCC

9. In the Object File dialog, click the Download button. The Configuration dialog box will appear.

10. Click the Write button to download the code to the MCU.

11. Disconnect the Z8051 OCD cable. Next, turn the Z51F3220 Development Board OFF, then ON, to run the code.

12. The LCD will continuously perform the following tasks:

– Turn ON each LCD segment, one at a time

– Count 0 to 9, each digit at a time

– Display 1234, –123, and –12.3 at one-second intervals

Results

The firmware developed for this application (LCD API and sample code) has been tested using the Keil compiler, the SDCC compiler, and the Z51F3220 Development Kit. The sample code used all of the APIs to perform a complete demonstration. A timer function is included in the sample code to provide a delay on the display intervals.

With the information contained in this document about how the LCD and the Z51F3220 MCU work together with this application’s source code, developers should easily be able to implement this application and modify it based on application requirements.

Summary

This application provides sample code to properly configure the Z51F3220 MCU’s LCD driver. Six items to consider when setting up the LCD driver are:

• Main clock source

• Watch timer clock source

• LCD frame frequency

• Duty cycle ratio

Note:

AN036401-1013 29

Page 30: INterface LCD

Interfacing an LCD to the Z51F3220 MCUApplication Note

• Bias

• Contrast

Additionally, this application provides LCD driver APIs to display unsigned, signed, and float decimal numbers to the VIM-404 LCD. These APIs can be used for counting, timing, and energy level displays.

References

Documents that support this Z51F3220 MCU-based application are listed below, in addi-tion to external references. Zilog documentation can be obtained for free from the Zilog website by clicking the link associated with its document number where indicated.

• Z51F3220 Product Specification (PS0299)

• Z51F3220 Development Kit User Manual (UM0243)

• Z8051 Tools Product User Guide

• Mechanical drawing of the VIM-404 LCD panel

AN036401-1013 30

Page 31: INterface LCD

Interfacing an LCD to the Z51F3220 MCUApplication Note

Appendix A. LCD Driver APIs

Table 11 presents a list of APIs and their attributes for use with the LCD driver.

Table 11. LCD Driver APIs

LCD_ClearDisplay()

Description Clears the LCD display.

Parameters None.

Return Value(s) None.

LCD_DisplayError()

Description Displays an error message on the LCD.

Parameters None.

Return Value(s) None.

LCD_DigitSegmentDisp (UCHAR ucDigit, UCHAR ucSegment)

Description Displays LCD segment on a specified digit position.

Parameters ucDigit: LCD digit position; only accepts 0 to 3 values.

ucSegment: LCD segment. It only accepts 0 to 6 values.

Return Value(s) None.

ucSegment–LCD segment

Return Value(s) None.

LCD_DigitNumberDisp (UCHAR ucDigit, UCHAR ucNumber)

Description Displays a number on a specified digit position.

Parameters ucDigit: LCD digit position. It only accepts 0 to 3 values.

ucNumber: only accepts 0 to 9 values.

Return Value(s) None.

LCD_UnsignedNumDisp (UINT uiData)

Description Displays xxxx decimal data format.

Parameters uiData: only accepts 0–9999.

Return Value(s) None.

LCD_SignedNumDisp (INT iData)

Description Displays -xxx and xxxx decimal data format.

Parameters iData: only accepts data from –999 to 9999.

Return Value(s) None.

LCD_FloatDisplay(FLOAT fData)

Description Displays –xx.x, –x.xx, x.xxx, xx.xx, and xxx.x decimal data format.

Parameters fData: only accepts data from –99.9 to 999.9.

Return Value(s) None.

AN036401-1013 31

Page 32: INterface LCD

Interfacing an LCD to the Z51F3220 MCUApplication Note

Customer Support

To share comments, get your technical questions answered, or report issues you may be experiencing with our products, please visit Zilog’s Technical Support page at http://support.zilog.com.

To learn more about this product, find additional documentation, or to discover other fac-ets about Zilog product offerings, please visit the Zilog Knowledge Base at http://zilog.com/kb or consider participating in the Zilog Forum at http://zilog.com/forum.

This publication is subject to replacement by a later edition. To determine whether a later edition exists, please visit the Zilog website at http://www.zilog.com.

DO NOT USE THIS PRODUCT IN LIFE SUPPORT SYSTEMS.

LIFE SUPPORT POLICY

ZILOG’S PRODUCTS ARE NOT AUTHORIZED FOR USE AS CRITICAL COMPONENTS IN LIFE SUPPORT DEVICES OR SYSTEMS WITHOUT THE EXPRESS PRIOR WRITTEN APPROVAL OF THE PRESIDENT AND GENERAL COUNSEL OF ZILOG CORPORATION.

As used herein

Life support devices or systems are devices which (a) are intended for surgical implant into the body, or (b) support or sustain life and whose failure to perform when properly used in accordance with instructions for use provided in the labeling can be reasonably expected to result in a significant injury to the user. A critical component is any component in a life support device or system whose failure to perform can be reasonably expected to cause the failure of the life support device or system or to affect its safety or effectiveness.

Document Disclaimer

©2013 Zilog, Inc. All rights reserved. Information in this publication concerning the devices, applications, or technology described is intended to suggest possible uses and may be superseded. ZILOG, INC. DOES NOT ASSUME LIABILITY FOR OR PROVIDE A REPRESENTATION OF ACCURACY OF THE INFORMATION, DEVICES, OR TECHNOLOGY DESCRIBED IN THIS DOCUMENT. ZILOG ALSO DOES NOT ASSUME LIABILITY FOR INTELLECTUAL PROPERTY INFRINGEMENT RELATED IN ANY MANNER TO USE OF INFORMATION, DEVICES, OR TECHNOLOGY DESCRIBED HEREIN OR OTHERWISE. The information contained within this document has been verified according to the general principles of electrical and mechanical engineering.

Z8051 is a trademark or registered trademark of Zilog, Inc. All other product or service names are the property of their respective owners.

Warning:

AN036401-1013 32