Maker Pro
Maker Pro

Assembler LCD Programming

Hello Electronics point.

I'm trying to initialize an lcd with kiel uvision using assembler lang. Everything looks fine but when i burn the program to the atmel 89c5131a-ua the lcd only showing one bar with black box's.

Here is the code:

Code:
mov A, #38h // Function Set
lcall SendCommand
lcall Delay

lcall SendCommand
lcall Delay

lcall SendCommand
lcall Delay

mov A, #06h // Display Control
lcall SendCommand
lcall Delay

mov A, #0Eh // Entry mode set
lcall SendCommand
lcall Delay

mov A, #01h // Clears the display
lcall SendCommand
lcall Delay

mov A, #'M'
lcall SendData
lcall Delay

mov A, #'A'
lcall SendData
lcall Delay

mov A, #'X'
lcall SendData
lcall Delay

SendCommand:
mov DPTR, #6000h
clr P1.2 // Setting 0 in RS (0=commands,1=data)
movx @DPTR, A
setb P1.3 // Setting 1 in EN (disabling the lcd)
clr P1.3 // Setting 0 in EN (enabling the lcd)
ret

SendData:
mov DPTR, #6000h
setb P1.2 // Setting 1 in RS (0=commands,1=data)
movx @DPTR, A
setb P1.3 // Setting 1 in EN (disabling the lcd)
clr P1.3 // Setting 0 in EN (enabling the lcd)
ret

Delay: // 100x100 = 10000us = 10 ms
mov R7, #100
D1:    mov R6, #100
djnz R6,$
djnz R7,D1
ret

end

Please help me understand why this isn't working?
 
Hello Maxim, welcome to EP. First thing to check is that the contrast is set correctly. This is normally done using a variable POT so you can adjust it to what you like. Check this first.
Adam
 
Hello Maxim, welcome to EP. First thing to check is that the contrast is set correctly. This is normally done using a variable POT so you can adjust it to what you like. Check this first.
Adam
The problem is that im connecting pot to the contrast to pin 3 and i still cant adjust the contrast...
 
Usually when you get a row of black bars it means that the LCD doesn't understand the data. In your code you have the statement "setb P1.3 // Setting 1 in EN (disabling the lcd)" and then you clear that same pin. Do you mean that you are setting and then clearing the 'E' pin to clock in the data? If so, then good. And I assume that you have the R/W pin tied low so it will write the data.

Also, if your micro is running at a reasonable speed (I assume it is) then you are going to need some delays in your code when you send any data too it - or the LCD wont be able to read the data because it goes by too quick. Here's some pseudo code:
Code:
SendCommand:
mov DPTR, #6000h
clr P1.2 // Setting 0 in RS (0=commands,1=data)
movx @DPTR, A
setb P1.3 // Setting 1 in EN (disabling the lcd)
delay for 230ns +
clr P1.3 // Setting 0 in EN (enabling the lcd)
delay for 37us +
ret

SendData:
mov DPTR, #6000h
setb P1.2 // Setting 1 in RS (0=commands,1=data)
movx @DPTR, A
setb P1.3 // Setting 1 in EN (disabling the lcd)
delay for 230ns +
clr P1.3 // Setting 0 in EN (enabling the lcd)
delay for 37us +
ret
Note that the time you should delay for is given in the datasheet. And also note that your delay can be longer than those values, just not any faster.

Dan
 
Top