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

LCD help needed

Hello EveryBody, I am working on LCD (16x2) and i have built some of my ideas about LCD programming but i am using Assembly language for my LCD, well as all things was going sweet so as every programmer is having something wrong ... (in starting) my problem specification is that i am using that LCD in 8-bit mode and i have connected my AT89C2051 (with some pull-ups)
P1 DB
P3.7 RS
P3.5 RW
P3.4 E
and i have interfaced my LCD with my MCu but my problem is that i am getting the LCD not working ... (i dont know why) .... i have interfaced my LCD but there only little bit of contrast....i mean to say that there nothing visible... even i move my 10K-ohm-POT to the ground.....

and i have done some programming, so could any one please help me .... (i am really stucked)
any help will be appritiatable.....

<code> ORG 0000H LJMP MAIN ORG 0030H RS EQU P3.7 RW EQU P3.5 EN EQU P3.4
MAIN: LCALL DELAY CLR EN MOV DPTR,#MYCOM LCALL LCD_INI MOV DPTR,#MYDATA LCALL LOOP MOV A,#0C9h LCALL COM LCALL DELAY MOV DPTR,#MYDAT2 LCALL LOOP
AGAIN: SJMP AGAIN
;========================================
COM: MOV P1,A CLR RS CLR RW SETB EN LCALL DELAY CLR EN RET
;========================================
DATAW: MOV P1,A SETB RS CLR RW SETB EN LCALL DELAY CLR EN RET
;========================================
DELAY: MOV R6,#100
HERE2: MOV R7,#250
HERE: DJNZ R7,HERE DJNZ R6,HERE2 RET
;========================================
LCD_INI: CLR A MOVC A,@A+DPTR LCALL COM LCALL DELAY JZ GO_B1 INC DPTR SJMP LCD_INI
GO_B1: RET
;========================================
LOOP: CLR A MOVC A,@A+DPTR LCALL DATAW LCALL DELAY INC DPTR JZ GO_B2 SJMP LOOP
GO_B2: RET
;========================================
MYCOM: DB 38H,0EH,06,01,84H,0
MYDATA: DB "DAREDEVIL",0
MYDAT2: DB "GUNS AND ROSES",0
;======================================== END
</code>

Asif Ali "DareDevil"

  • Oops i have missplased that "pre" tag applogize me please
    <code>

                    ORG 0000H
                    LJMP MAIN
                    ORG 0030H
                    RS EQU P3.7
                    RW EQU P3.5
                    EN EQU P3.4
    MAIN:           LCALL DELAY
                    CLR EN
                    MOV DPTR,#MYCOM
                    LCALL LCD_INI
                    MOV DPTR,#MYDATA
                    LCALL LOOP
                    MOV A,#0C9h
                    LCALL COM
                    LCALL DELAY
                    MOV DPTR,#MYDAT2
                    LCALL LOOP
    AGAIN:          SJMP AGAIN
    ;========================================
    COM:            MOV P1,A
                    CLR RS
                    CLR RW
                    SETB EN
                    LCALL DELAY
                    CLR EN
                    RET
    ;========================================
    DATAW:          MOV P1,A
                    SETB RS
                    CLR RW
                    SETB EN
                    LCALL DELAY
                    CLR EN
                    RET
    ;========================================
    DELAY:          MOV R6,#100
    HERE2:          MOV R7,#250
    HERE:           DJNZ R7,HERE
                    DJNZ R6,HERE2
                    RET
    ;========================================
    LCD_INI:        CLR A
                    MOVC A,@A+DPTR
                    LCALL COM
                    LCALL DELAY
                    JZ GO_B1
                    INC DPTR
                    SJMP LCD_INI
    GO_B1:          RET
    ;========================================
    LOOP:           CLR A
                    MOVC A,@A+DPTR
                    LCALL DATAW
                    LCALL DELAY
                    INC DPTR
                    JZ GO_B2
                    SJMP LOOP
    GO_B2:          RET
    ;========================================
    MYCOM:          DB 38H,0EH,06,01,84H,0
    MYDATA:         DB "DAREDEVIL",0
    MYDAT2:         DB "GUNS AND ROSES",0
    ;========================================
                    END
    </code>
    


    Asif Ali "DareDevil"

  • Oops i have missplased that "pre" tag

    evidently you have 'misplaced' the comments as well.

    expecting someone to help you with uncommented code for free is an insult.

    Were I to help you for money, the first billable hour(s) would be spent figuring out what you are doing and adding comments to the code.

    Erik

  • There are 3 things that you need to do:
    1) Get the tech docs for the LCD and read it. The document will have a table showing all the command words and probably a flow diagram on how to initialize and read/write data to the LCD.

    2) There are a lot of code samples on the web. Try searching.

    3) Why assembly? Try learning 'C'.

  • I have a few comments:

    1) You most probably need to have a negative voltage on the VC pin to achieve high contrast on your LCD. Check the particular datasheet;

    2) Port 3 already has internal pullup on its pins;

    3) In the LCD_INI and LOOP routines you seem to be testing for loop finish when byte 0x00 is loaded in A. There are a number of problems with your approach:

    A) None of the instructions you are using affect the Z flag, and yet you are testing for Z to finish the loops (MOVC does not set the flags). You have to test the value loaded in A for zero using an instruction that sets the Z flag.

    B) Depending on the state of the PSW on RESET, your program will blaze through the whole code memory and dump its contents on port P1 as LCD commands, OR it will just sent the first byte of your 3 strings to the display and stop dead.

    I have no idea if the LCD init codes on MYCOM are right for the LCD you are using, but your program as it is will not work as you expect it to. I suggest you to simulate it on uVision to test its logic before commiting to silicon.

    One piece of advice: do not trust RESET values for registers and PSW values. Always initialize what you use.

  • Hello sir I as you have said that Why Assembly ? use C. so sir the answer is that i was C programmer but for evantually i have learnt the Assembly just for my LCD interfacing and i have done very much hard working in learning Assembly :-( well i will create the program in C also but as you have pointed out that pin3 to ground ... well i have tried that but there is problem that only the Second coulmn of LCD is showing me Black boxes ... and that boxes are not very much black .... (Why?)

    And thank you for your Reply well and hoping that you will help me little more..

    i have read the DataSheet of 16x2 LCD (HD44780A) but nothing good is happend .... :-(

  • Well sir Jhonny i have tried to varify the output on Keil Simulator in Single step Debugging . but the output is desired ... but i dont know that why its not working in Real world....

    And sir as you have told that i am using Null charecter for ending String so sir i have also tried by sending one command or word at saperate time. like (after sending commands such as to set lcd and Clear Screen)

    MOV A,#'A'
    LCALL DATAW
    LCALL DELAY
    

  • Jonny Doin said, "I have no idea if the LCD init codes on MYCOM are right for the LCD you are using, but your program as it is will not work as you expect it to." (my emphasis)

    Asif Ali replied, "i have tried to varify the output on Keil Simulator in Single step Debugging but the output is desired"

    That's the problem with simulation: if your design is based on a flawed interpretation, and your simulation is also based on that same flawed assumption, then the simulator will give you the results that you expected - but the real hardware will not!

    "One piece of advice: do not trust RESET values"

    This is a very common area where the simulator can differ from reality!

    "Always initialize what you use."

    Absolutely!

  • i was C programmer
    1) that C is 'self documenying' is a myth that has been debunked often, did you believe that one?
    2) whatever C is or is not, assembly definitely is not in any way 'self documenying'

    hoping that you will help me little more
    gladly will help with commented code.

    The amazing thing is that if you commented your code and, as suggested above, compared it to the flowchart in the LCD datasheet I would bet you would find the problem yourself.

    Erik

  • Thanks Sir Andy for your comments well sir i have done a new code for my MCu and hoping that you will tell me my Mistake ... thanks in advance

                    ORG 0000H
                    LJMP MAIN
                    ORG 0030H
    MAIN:            MOV A,#038H
                    LCALL COM
                    MOV A,#00EH
                    LCALL COM
                    MOV A,#001H
                    LCALL COM
                    MOV A,#006H
                    LCALL COM
                    MOV A,#084H
                    LCALL COM
                    MOV A,'A'
                    LCALL DATAW
                    MOV A,'L'
                    LCALL DATAW
                    MOV A,'I'
                    LCALL DATAW
    AGAIN:          SJMP AGAIN
    COM:            MOV P1,A
                    CLR P2.0
                    CLR P2.1
                    SETB P2.2
                    CLR P2.2
                    LCALL DELAY
                    RET
    DATAW:          MOV P1,A
                    SETB P2.0
                    CLR P2.1
                    SETB P2.2
                    CLR P2.2
                    LCALL DELAY
                    RET
    DELAY:          MOV R6,#50
    HERE2:          MOV R7,#255
    HERE:           DJNZ R7,HERE
                    DJNZ R6,HERE2
                    RET
                    END
    

    Well sir It will only Send "ALI" to LCD (in my imagination)

  • erik malund wrote: "The amazing thing is that if you commented your code ... I would bet you would find the problem yourself"

    Absolutely. Code documentation is not meant just for 'other people read'. A well commented code will capture the programmer's intentions and clarify the effects of the related logic.

    The best definition for a bug I've ever seen is:

      A bug is a mismatch between the documentation and the actual behavior of a program.
    

    You can write spaghettiware in pretty much any language. It doesn't really matter whether you program in C, Python or Assembly, as long as you write clear comments and structure your code cleanly. But PLEASE, never write comments like "load 0x41 into the accumulator", or "go to LOOP".

  • Hi Ali,
    It seems your reset sequence is going wrong somewhere.
    Try the soft reset sequence properly .
    I remember that Some LCDs require 0x38 (the first seq) to be written 3 times and then follow the other ones.

    suvidh

  • "tell me my Mistake"

    You have still not put one single comment in it!

  • I wrote above: "None of the instructions you are using affect the Z flag, ..."

    Which is ABSOLUTE NONSENSE!
    Please forgive-me for that. OF COURSE, the 8051 core has no Z flag. Testing for zero in A should work as written. (thank you all for not flaming immediately)

    The fact that I routinely write 8051 assembly functions does not make my gross mistake better. I can only blame it to cross-cpu contamination or brain damage :-0

    Anyway, I am following this subject in the other forum you have started, and you seem to have progressed to the point of locating your mistake in the initialization code. The Hitachi documentation specifies that you send the init sequence to the display 4 times, with a delay of 10ms between sequences. Check your timings.

  • Well sir i have checked my initialization according to HD44780 in my simulator i have found that its 0.012S so i think that its very enough for delay purpose Right ?

  •                 ORG 0000H
                    LJMP MAIN
                    ORG 0030H
                                        ;initialization
    MAIN:           MOV A,#038H                     ;first time
                    LCALL COM
                    MOV A,#038H             ;second time
                    LCALL COM
                    MOV A,#038H             ;third time
                    LCALL COM
                    MOV A,#038H             ;fourth time
                    LCALL COM
                    MOV A,#00EH
                    LCALL COM
                    MOV A,#001H
                    LCALL COM
                    MOV A,#006H
                    LCALL COM
                    MOV A,#084H
                    LCALL COM                ;initialization End
                    MOV A,#'A'               ;data to write on LCD
                    LCALL DATAW
                    MOV A,#'L'
                    LCALL DATAW
                    MOV A,#'I'              ;data end
                    LCALL DATAW
    AGAIN:          SJMP AGAIN               ;endless loop
    COM:            MOV P1,A                         ;command write sequence
                    CLR P3.7
                    CLR P3.5
                    SETB P3.4
                    CLR P3.4
                    ;LCALL DELAY
                    RET
    DATAW:          MOV P1,A                        ;data write sequence
                    SETB P3.7
                    CLR P3.5
                    SETB P3.4
                    CLR P3.4
                    ;LCALL DELAY
                    RET
    DELAY:          MOV R6,#50              ;simple delay routine
    HERE2:          MOV R7,#255             ;for 0.0124S or 124MS
    HERE:           DJNZ R7,HERE
                    DJNZ R6,HERE2
                    RET
                    END