The Godfather talking
You can run, but you can't hide.
Sonsivri
 
*
Welcome, Guest. Please login or register.
Did you miss your activation email?
March 29, 2024, 03:33:48 15:33


Login with username, password and session length


Pages: [1]
Print
Author Topic: LCD INTERFACING  (Read 6394 times)
0 Members and 1 Guest are viewing this topic.
kt053203
Guest
« on: January 21, 2009, 03:32:26 15:32 »

I AM NEW TO INTERFACING VARIOUS DEVICES TO THE MICROCONTROLLER. I AM USING THE AT89C51 CONTROLLER I AM INTERFACING THE LCD WITH IT AND I AM USING PORT 2 AS THE DATA PORT PORT 0 PINS 5,6&7 CONNECTED RESPECTIVELY TO PIN 4,5&6OF THE LCD.I HAVE LOADED THE PROGRAM OF IN CONTROLLER IS CHECKING THE BUSY BIT I.E. OF CHECKIG THE BUSY BIT BY POLLING. THE LCD IS NOT DISPLAYING ANY THING. I AUESS IT IS BEING INTIALIZED BUT IT IS NOT COMING BACK FROM THE SUBROUTINE OF POLLING. PLEASE HELP ME AS SOON AS POSSIBLE
Logged
gamegurus
Newbie
*
 Muted
Offline Offline

Posts: 23

Thank You
-Given: 14
-Receive: 64

Oh what a wonderful morning!!!


« Reply #1 on: January 23, 2009, 04:05:50 04:05 »

You can try this code in 8 bit mode, it works. I used Keil v8 compiler.

Code:
;8 bit LCD routines with check busy flag before sending data, command to LCD       
;*************************************************************
LCD     DATA     P1          ;define LCD data port on port 1
BUSY    BIT      LCD.7       ;define LCD busy flag
E       BIT      P2.2        ;define LCD enable pin on port 2.2
RS      BIT      P2.0        ;define LCD register select pin on port 2.0
RW      BIT      P2.1        ;define LCD read/write pin on port 2.1
;*************************************************************
        ORG      00H

LCD_INIT:
        MOV      A,#38H                ;2 line 5x7
        ACALL    COMMAND   
        MOV      A,#0CH                ;LCD on cursor on
        ACALL    COMMAND
        MOV      A,#01H                ;clear LCD
        ACALL    COMMAND
        MOV      A,#06H                ;shift cursor right
        ACALL    COMMAND
DISPLAY:MOV      A,#81H
        ACALL    COMMAND
        MOV      DPTR,#TEST
        ACALL    DISP_STRING
        MOV      A,#0C1H
        ACALL    COMMAND
        MOV      DPTR,#TEST+0EH
        ACALL    DISP_STRING
HERE:   SJMP     HERE       
;=============================================================
COMMAND:
        ACALL    READY                 ;is LCD ready?
        MOV      LCD,A                 ;issue command code
        CLR      RS                    ;RS=0 for command
        CLR      RW                    ;R/W=0 to write to LCD|
        SETB     E                     ;E=1 for H-to-L pulse
        CLR      E                     ;E=0 ,latch in
        RET
;=============================================================
DATA_DISPLAY:
        ACALL    READY                 ;is LCD ready?
        MOV      LCD,A                 ;issue data
        SETB     RS                    ;RS=1 for data
        CLR      RW                    ;R/W=0 to write to LCD
        SETB     E                     ;E=1 for H-to-L pulse
        CLR      E                     ;E=0 ,latch in
        RET
;=============================================================
READY:
        SETB     BUSY                  ;make P1.7 input port
        CLR      RS                    ;RS=0 access command reg
        SETB     RW                    ;R/W=1 read command reg
;read command reg and check busy flag
BACK:
        CLR      E                     ;E=1 for H-to-L pulse
        SETB     E                     ;E=0 H-to-l pulse
        JB       BUSY,BACK             ;stay until busy flag=0
        RET
;=============================================================
DISP_STRING:
        CLR      A                     ;A=0
MOV      R7,#00H               ;R7=0
NEXT_CHAR:
INC      R7        ;R7+1
MOVC     A,@A+DPTR
ACALL    DATA_DISPLAY
MOV      A,R7
CJNE     R7,#0EH,NEXT_CHAR
RET       
;=============================================================
TEST:   DB       "8-Bit LCD Test","By 80C51 MCU's"     
        END
Logged

Indian Gaming Guru
TomJackson69
Active Member
***
Offline Offline

Posts: 218

Thank You
-Given: 26
-Receive: 63


« Reply #2 on: January 24, 2009, 02:19:45 14:19 »

You may need to have few uS delay when you write data and CMD. I give CMD delay longer than DATA delay.
Also you may want to put one or two NOP in between Hi to Low and/or Low to Hi of pin E. I think you have problem with timing.

;=============================================================
COMMAND:
        ACALL    READY                 ;is LCD ready?
        MOV      LCD,A                 ;issue command code
        CLR      RS                    ;RS=0 for command
        CLR      RW                    ;R/W=0 to write to LCD|
        SETB     E                     ;E=1 for H-to-L pulse

Put  NOP here (one or two)

        CLR      E                     ;E=0 ,latch in
        RET
;=============================================================
DATA_DISPLAY:
        ACALL    READY                 ;is LCD ready?
        MOV      LCD,A                 ;issue data
        SETB     RS                    ;RS=1 for data
        CLR      RW                    ;R/W=0 to write to LCD
        SETB     E                     ;E=1 for H-to-L pulse

Put  NOP here (one or two)

        CLR      E                     ;E=0 ,latch in
        RET
;=============================================================

Here is my MCC18 routines:

// Send one char to LCD.

void sendChar(unsigned char Char)
{
        TRIS_DATA_PORT = 0;       // set data port to output
        DATA_PORT = Char;          // Write data to data port
        RS_PIN = 1;            // RS = 1 cho data mode
        E_PIN = 1;                // Clock the command in
        DelayChar();
        E_PIN = 0;
        DelayChar();                   // Experiment with this DelayChar()


void sendCMD(unsigned char cmd)
{
        TRIS_DATA_PORT = 0;             // set data port to output
        DATA_PORT = cmd;                // Write command to data port
        RW_PIN = 0;                     // Set the control signals
        RS_PIN = 0;                     // RS = 0 cho CMD mode
        DelayChar();
        E_PIN = 1;                      // Clock the command in
        DelayChar();
        E_PIN = 0;
        DelayLCD();
 
}


void DelayChar()
{
   DelayuS(15);   // 15uS da chay tot voi real circuit at 20MHz
}


void DelayLCD()
{

   DelaymS(10);   // 15mS tot.
}

My method is not POLLING like your but it work good.

Also when you initialize the LCD, I think you have to send #0x38 THREE times. Here is your:

LCD_INIT:
        MOV      A,#38H                ;2 line 5x7
        ACALL    COMMAND   

I would do this three times.

Try it see how it work.

Tom


Logged

Con Rong Chau Tien
Jagi
Newbie
*
Offline Offline

Posts: 27

Thank You
-Given: 26
-Receive: 12


« Reply #3 on: January 24, 2009, 05:32:39 17:32 »

Here are some generic LCD routines that I wrote a few years ago. I had used a PIC 16F877a and interfaced a 20x4 line LCD that incorporates the HITACHI controller. Feel free modify or use the routines @ your own risk. You will need to provide your own delay routines or search for them on the internet and you'll find plenty of them already written waiting for a new home
Logged
jeanninemtv
Senior Member
****
Offline Offline

Posts: 311

Thank You
-Given: 57
-Receive: 25


« Reply #4 on: January 24, 2009, 09:25:00 21:25 »

BTW,
i have a optrex 4x20 lcd dmc 20481 with backlight

i still hae problems, i don't know if its the contrast of the lcd or if its a problem of timing....i am using proton ...
help
Logged
LEAS
Junior Member
**
Offline Offline

Posts: 77

Thank You
-Given: 9
-Receive: 19


« Reply #5 on: January 24, 2009, 10:17:52 22:17 »

Try to simulate in Proteus,see example in it->check the program code. Some of LCD tipes(with extended temperature range) must Vo variable resistor connect to negative supply , not VDD-VSS.
« Last Edit: January 25, 2009, 06:47:58 06:47 by LEAS » Logged
Jagi
Newbie
*
Offline Offline

Posts: 27

Thank You
-Given: 26
-Receive: 12


« Reply #6 on: January 25, 2009, 04:19:58 04:19 »

Hi jeanninemtv,
What exactly is the problem you are facing interfacing the LCD? If you can share the schematic and the code maybe I can help you resolve the issue. The backlight has nothing to do with the LCD itself, it is merely used to illuminate the LCD (just a simple LED with a current limiting resistor)  Wink
Logged
jeanninemtv
Senior Member
****
Offline Offline

Posts: 311

Thank You
-Given: 57
-Receive: 25


« Reply #7 on: January 27, 2009, 04:51:58 16:51 »

are you sure about negative contrast?
Logged
Jagi
Newbie
*
Offline Offline

Posts: 27

Thank You
-Given: 26
-Receive: 12


« Reply #8 on: January 28, 2009, 03:49:32 15:49 »

As LEAS states, please check the contrast. Some (at least most of them) use -VEE supply for the contrast. The typical voltage of the contrast ranges from 0V to -9V. At 0V the display is all white and nothing can be read; and @ -9V the display is all black and again nothing can be read. The values in between provide a change in the contrast. You can connect a linear pot (say 10K) between the -VEE of the LCD and -9V of the supply. Adjust the contrast.

Proteus simulation does not care for contrast supply. If the code simulates correctly on Proteus, then check the contrast circuit as explained above; otherwise check the code or LCD wiring.
Logged
jeanninemtv
Senior Member
****
Offline Offline

Posts: 311

Thank You
-Given: 57
-Receive: 25


« Reply #9 on: April 30, 2009, 03:04:14 15:04 »

yes theres a tc7660  to obtain -5 from 5 with 2 caps and very little in space ..
Logged
ali_asadzadeh
Junior Member
**
Offline Offline

Posts: 82

Thank You
-Given: 5
-Receive: 12


« Reply #10 on: May 03, 2009, 07:33:15 07:33 »

have you set the contrast pot?and also you can use bascom 8051 for testing your hardware.
Logged
Pages: [1]
Print
Jump to:  


DISCLAIMER
WE DONT HOST ANY ILLEGAL FILES ON THE SERVER
USE CONTACT US TO REPORT ILLEGAL FILES
ADMINISTRATORS CANNOT BE HELD RESPONSIBLE FOR USERS POSTS AND LINKS

... Copyright © 2003-2999 Sonsivri.to ...
Powered by SMF 1.1.18 | SMF © 2006-2009, Simple Machines LLC | HarzeM Dilber MC