Tuesday, October 21, 2014

Memory Mapped LCD Module interfacing and device drivers for 8051

Introduction

A display unit is one of the important components of Embedded systems. It comes in a wide variety of forms and shape. One that is popular for the small and mid-sized system is Hitachi LCD alphanumeric character display module. This is a 12 pins module. Pin diagram for the module is given in Fig. 1 Brief descriptions of the pins of the module are given below.

Pin name Description
Vss Ground
VDD +5V supply
VEE Control voltage
Control Signals RS
Control and data Register Selector
( 1 for data register, 0 for control register)
E Enable Read or Write operation
RW Read and write to selected register( 1 for read, 0 for write)
Data signal D0...D7 Data bus for the module

Figure 1: Pin diagram of Hitachi LCD module

Interfacing module with 8051 micro-controllers

There are two ways of interfacing the Hitachi module with 8051 micro-controllers. They are:
  1. Input/Output mapped
  2. Memory mapped
In Input/Output mapped data and control pins of the LCD module are connected to input/output ports of 8051 micro-controllers. Whereas, in Memory mapped the module is connected like a memory ICs such as RAM or ROM ICs. In this blog, Memory mapped interfacing method will be discussed.
The interfacing circuit for the LCD module is depicted in figure 2↓ In the circuit diagram control pins RS, and RW are connected to AD0, and AD1 of 8051 micro-controllers. The purpose of the latch 74LS373 is to avoid contention between data and address signal. The RD and WR pins of the microcontroller are connected to Nand gate. The output of Nand gate is connected to E of LCD module.


                    Figure 2 Interfacing Circuit for the LCD module

Figure 3↓ . shows the timing diagram of Read and Write cycle of the Hitachi LCD module.



                               (a) Write cycle



                              (b) Read cycle
     Figure 3 Read and Write timing diagram for the LCD module

Checking whether LCD module is busy

Before receiving and sending data from the LCD module, it should be checked whether it is busy or not. The steps for doing this are listed below
  1. Select Control register, i.e. (RS = 0)
  2. Read the Control register, i.e. set RW = 1
  3. Check the D7 bit of Control register, if it is 1 LCD module is busy, else free.

Device driver for the module

As depicted in the interfacing circuit for the LCD Module (Figure 2), Control Signals RW and RS are connected to AD0 and AD1 of 8051 micro-controller. Since AD0 and AD1 are address bit no 1 and 0 of the microcontroller, there are separate addresses for;
  • Read from Control Register
  • Write to Control Register
  • Read from Data Register
  • Write to Data Register
Those addresses should be defined while writing a device driver for the module. The portion of the code for the definition is given below

unsigned char xdata LCDcmdWrite _at_ 0x0000; 
unsigned char xdata LCDdataWrite _at_ 0x0001; 
unsigned char xdata LCDcmdRead _at_ 0x0002;

Similarly, codes that are used to write data on Control and Data register of the module are given below

1void sendCmdLCD(char cmd) {   
2while((LCDcmdRead&0x80) ==0x80)//check busy flag  
3{   /*Delay 50us*/   
4  TH0 = 0xff;   
5  TL0 = 0xd2;   
6  TR0 =1;   
7  while(!TF0);    
8  TF0 =0;    
9  TR0 = 0; 
10  }//checking busy flag 
11 LCDcmdWrite = cmd; 
12}
13void sendDataLCD(char mssg) {  
14 while((LCDcmdRead&0x80) ==0x80)//check busy flag  
15{   /*Delay 50us*/   
16  TH0 = 0xff;
17  TL0 = 0xd2;
18  TR0 =1;
19  while(!TF0);
20  TF0 =0;
21  TR0 = 0; 
22 }//checking busy flag  
23LCDdataWrite = mssg;
2425}


It should be noted that in this code module is checked whether it is busy or not.

No comments:

Post a Comment