Friday, July 26, 2013

Reading Data From 16*2 LCD using AT89s52

     In this paper I am going to show the technique of reading data from HD44780 based LCD in 8 bit mode using AT89s52 microcontroller.

figure a:- Pin Layout of 16*2 LCD
The pin configuration of LCD is shown in figure a.

Eight data pins D0-D7 are connected with any one port of AT89s52 microcontroller. Three control pins of LCD i,e RS, RW and EN are connected to any three pins of MCU(Microcontroller unit). In this example, I am connecting the data pins of LCD with PORT2 of MCU and the control pins are connected with first three pins of PORT1 of MCU.


As this paper is mostly focused in reading data from Display RAM of LCD, I am only giving procedure of reading data from LCD,procedure of writing data and sending command to LCD will be skipped. 


                                                                              
DESCRIPTION:-
       
       While reading data from DRAM of LCD, RW and RS control pins needs to be in logic HIGH and the state of enable pin should change from logic LOW to logic HIGH. RW in logic HIGH means the READ mode is selected and RS in logic HIGH means the data register is selected.
        
        Now we once review AT89s52 MCU I/O programming concept. In this MCU, the PORTs are configured as INPUT PORT or as OUTPUT PORT by writing 1s or 0s in the PORTs respectively. Thus,while reading data from display RAM of LCD, 1s should be written in the respective port. In this example FFh is written in PORT2 of MCU before going to reading procedures as described in the above paragraph.

           The routine to read data from LCD is shown in figure b.

ROUTINES DESCRIPTION:-
figure b:-routine to read data from DRAM of LCD

This routine returns the character which is read from DRAM of LCD from the address location which is passed to the function.

lcdcmd is the routine which sends command to the LCD. In this routine calling lcdcmd(address); function sets the address of the DRAM.

RS=1; selects the Data register of LCD. 
RW=1; tells the MCU to read the data from DRAM.

ldata=0xff; this instruction makes PORT2 of MCU as input PORT.

busychk(); this function check if LCD is busy or not.

changing the state of en pin from logic LOW to logic HIGH latches the data to the data pins of LCD. Then it is required to read data from the data pins.
return(ldata); instruction returns the data from the data pins of LCD.

No comments: