This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

Help needed for LCD programming in asm

Hi all.. Im quite new to 8051. Im doing a project that requires me to display value of a peak voltage on a LCD.

Anyway, Im stuck in testing the LCD. I have connected the LCD(Powertip PC 0802-A), otherwise known as 214-3288, to my 8051 development kit. The kit that im using is C8051F206-TB. I connected databus 0-7 to port 3 and RS to P2.4, R/W to P2.5, and EN to P2.6

I also have gone online to source for programs to display "Hello World" on the LCD. I have found a few in C or asm, but i have learnt the basic of assembly language, so i don't really understand C language.

Below is a program i found in 8052.com


$include (c8051f200.inc)

CSEG AT 0000H
LJMP MAIN
CSEG AT 0100H

MAIN:LCALL CONFIG
     LCALL INIT_LCD
     LCALL CLEAR_LCD
     LCALL HELLO

CONFIG:MOV PRT0MX, #000H ; PRT0MX: Initial Reset Value
       MOV PRT1MX, #000H ; PRT1MX: Initial Reset Value
       MOV PRT2MX, #000H ; PRT2MX: Initial Reset Value
       MOV P2MODE, #0FFH ; Input Configuration for P2
       MOV PRT3CF, #0FFH ; Output configuration for P3

INIT_LCD:       CLR P2.4
         MOV P3,#38H
        SETB P2.6
        CLR P2.6
        LCALL WAIT_LCD
        CLR P2.4
        MOV P3,#0EH
        SETB P2.6
        CLR P2.6
        LCALL WAIT_LCD
        CLR P2.4
        MOV P3,#06H
        SETB P2.6
        CLR P2.6
        LCALL WAIT_LCD
        RET

HELLO:  LCALL INIT_LCD
        LCALL CLEAR_LCD
        MOV A,#48H
        LCALL WRITE_TEXT
        MOV A,#45H
        LCALL WRITE_TEXT
        MOV A,#4CH
        LCALL WRITE_TEXT
        MOV A,#4CH
        LCALL WRITE_TEXT
        MOV A,#4FH
        LCALL WRITE_TEXT
        CLR P2.4
        MOV P3,#0CAH
        SETB P2.6
        CLR P2.6
        LCALL WRITE_TEXT
        MOV A,#57H
        LCALL WRITE_TEXT
        MOV A,#4FH
        LCALL WRITE_TEXT
        MOV A,#52H
        LCALL WRITE_TEXT
        MOV A,#4CH
        LCALL WRITE_TEXT
        MOV A,#44H
        LCALL WRITE_TEXT

WAIT_LCD:       CLR P2.6 ;Start LCD command
        CLR P2.4 ;It's a command
        SETB P2.5 ;It's a read command
        MOV P3,#0FFH ;Set all pins to FF initially
        SETB P2.6 ;Clock out command to LCD
        MOV A,P3 ;Read the return value
        JB ACC.7,WAIT_LCD
        CLR P2.6 ;Finish the command
        CLR P2.5 ;Turn off RW for future commands
        RET


CLEAR_LCD:CLR P2.4
        MOV P3,#01H
        SETB P2.6
        CLR P2.6
        LCALL WAIT_LCD
        RET

WRITE_TEXT:SETB P2.4
          MOV P3,A
          SETB P2.6
          CLR P2.6
          LCALL WAIT_LCD
          RET



           END

Parents Reply Children
  • I followed what Dan said, I can see the cursor appearing at the 1st position of the 2nd line and disappeared, and after a few seconds it appeared on the 6th position. It might be printing the word "WORLD", but i cannot see it. I'm quite sure that that i have satisfy the timing required on the datasheet. Or do i have to make a longer delay at the "Move cursor" instruction?

    This is the delay i use for the "move cursor" and after the "CLR EN" instruction, DELAY1 is the delay i used between SETB EN and CLR EN:

    DELAY:  MOV R1,#06H
    D1:     MOV R2,#0FFH
    D2:     MOV R3,#0FFH
    D3:     DJNZ R3,D3
             DJNZ R2,D2
            DJNZ R1,D1
            RET
    
    DELAY1:  MOV R1,#01H
    D1:      MOV R2,#0FFH
    D2:      MOV R3,#OFFH
    D3:      DJNZ R3,D3
             DJNZ R2,D2
             DJNZ R1,D1
             RET
    

  • "... after a few seconds it appeared on the 6th position. It might be printing the word "WORLD", but i cannot see it."

    A few seconds is quite a long time to display 5 characters. Firmware written to satisfy worst case timing for a typical HD44780 controlled display should take under 1ms to display 5 characters. How long do your delays need to be? How long are they actually delaying? Have you measured their durations?

    "Or do i have to make a longer delay at the "Move cursor" instruction?"

    We normally configure our displays, the display controller automatically increments the DDRAM address when a character is written to DDRAM and there is no need for an explicit "move cursor" instruction.

  • The "Move Cursor" instruction is to move the cursor to the 2nd line.

    25Mhz processor and the "DELAY" i'm using, should give me about 37us delay. From the datasheet, most instructions took 40us(max) to execute.

  • I have tried values for R1 ranging from "#01H" to "#0FH". It still have the same problem. "Hello" on the 1st line and nothing on the 2nd. I wonder whether is it my power supply to the LCD is not enough.

  • Ok. I have tried inputting a 5V supply directly from a DC volatge supply but in vain.

  • I have tried printing "WORLD" on the 1st line, but it also cannot print. Does it have something to do with my connection with the C8051 development kit?

  • Ok.. I found the problem. I can now print on the 2nd line. I connected the RS pin to P2.4 which is already connected to a LED. Does that makes the LCD cannot print on the 2nd line?

    Thank you all for all the help you have given me...

  • If the current consumption of the LED makes the signal not reach correct level, then it is obvious that it can affect the display function.

    It's all part of the contract. You have to make sure that all signals have fast enough raise/fall times and settles at correct levels. If not, the display will not do it's part.