We are running a survey to help us improve the experience for all of our members. If you see the survey appear, please take the time to tell us about your experience if you can.
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
Andy: The other thing to note about RC oscillators is that their frequency is usually not accurate.
It may well be stable (ie, it doesn't change), but not accurate (ie, you don't know exactly what fequency it is).
Clearly, to use it as the basis for timing, you need to know precisely what the frequency is!
It was because your normally don't know what the actual frequency is, that I noted that the timing safety margins must be set higher when using an RC oscillator.
The really bad part with RC oscillators is that it isn't so easy to just measure their frequency, since they tend to vary very much with temperature.
This shouldn't normally represent a problem when it comes to making sure that handshake signals aren't run too fast. A 100% safety margin is quite often ok, without getting too low "bandwidth" to connected equipment.
The need to know the real frequency - or to use the ability to trim the oscillator - is more important if trying to use it for baudrate generation or similar.
I see. I managed to print "HELLO" on the 1st line of the LCD. It only works when i use stepping. It does not work when i just let it run by itself, does this means that the processor is too fast? But i cannot get the cursor to move to the 2nd line.
I use this instruction to move the cursor, but it won't move:
CLR RS MOV DATA,#0C0H SETB EN NOP NOP NOP NOP CLR EN NOP NOP NOP NOP
Ok. My bad. I mean the cursor does move to the 2nd line, after i send "CLR EN" when sending "W", the LCD does not show anything, not even the cursor.
I mean after this instruction
the cursor moves to the 2nd(sometimes cannot) line, but after the following instruction which comes after the above instruction, nothing shows.
MOV A,#'W' LCALL WRITE_TEXT WRITE_TEXT:SETB RS MOV DAT,A SETB EN NOP NOP NOP NOP CLR EN NOP NOP NOP NOP RET
Why is this so?
What do i have to do in order to make it print at the 2nd line? Is it printing too fast at the 2nd line? Or do i have to configure something?
In addition to satisfying low-level signal timing requirements, you have the LCD controller's execution timing requirements to deal with. Characters take some time to display. Instructions (e.g., CLEAR, HOME, etc.) take even more time to execute.
So I have to put in more delay in the "Move the cursor to the 2nd line" instruction? Because when i run the program, i can see "Hello" being printed out on the 1st line and the cursor moved to the 2nd line but no words are printed on the 2nd line.
However when i try this:
Hello: CLR EN CLR RS MOV DAT,#0FH SETB EN LCALL DELAY CLR EN CLR RS MOV DAT,#0C2H SETB EN LCALL DELAY CLR EN MOV A,#'H' LCALL WRITE_TEXT
It works, it can print on the 2nd line, 3rd position but not on the 1st and 2nd. Also, when i just let the program keep running, eventually the "Hello" will be printed out on the 2nd line.
"It works, it can print on the 2nd line, 3rd position but not on the 1st and 2nd."
Well, writing #0C2H would set DDRAM address to the third character on the second line, would it not?
Do you have the data sheet for your display controller? For example, the HD44780 display controller's data sheet shows it takes roughly 40us to execute many of the instructions and to write to DDRAM, and is shows some instructions taking 1.52ms to execute. Are you implementing those inter-instruction and inter-character delays?
"Well, writing #0C2H would set DDRAM address to the third character on the second line, would it not?
Well, I tried #0C0H and #0C1H. It can't print.
Yea. This is the delay i used and it print "Hello" just fine on the 1st line.
DELAY: MOV R1,#05H D1: MOV R2,#0FFH D2: MOV R3,#0FFH D3: DJNZ R3,D3 DJNZ R2,D2 DJNZ R1,D1
You want a short delay between taking EN high and taking it back low. The longer delays should come after you take EN low. You need to change RS according to whether you are writing instructions or writing display data. In the example code you posted earlier you never take RS high to write display data.
"you never take RS high to write display data."
I did it in the "LCALL WRITE_TEXT"
WRITE_TEXT: SETB RS CLR RW MOV DAT,A SETB EN LCALL DELAY CLR EN
You mean the delay i use between "SETB EN" and "CLR EN" is too long? I have to use another shorter delay? And after "CLR EN" i have to use the longer delay before i can continue with other instruction?
condensing Dan's post
read and follow the timing requirements stated in the datasheet.
Your posts "does this work" "why does this not work" show nothing but the fact that reading a datasheet evidently is below your dignity.
Erik
'You mean the delay i use between "SETB EN" and "CLR EN" is too long? I have to use another shorter delay?'
I'd change the wording to be "unnecessarily long". If I recall correctly, the data sheet does not indicate a maximum EN pulse width, only a minimum.
'And after "CLR EN" i have to use the longer delay before i can continue with other instruction?'
Right.
I see. Thx Guys.
Erik, I have read the datasheet, but i do not really understand it, thats why i post on this forum. I have never program an LCD before. This is my 1st time programming an LCD. I did not know that timing was so important. Now that i know, it will be easier for me to program. Even though theres some things that I'm still not sure, but i'm sure im will be able to figure that out.
I have read the datasheet, but i do not really understand it Then I suggest that instead of posting like you do, you ask specific questions related to what in the datasheet you do not understand. if you do not develop the skill of understanding a datasheet you will be equally lost at your next project.
I did not know that timing was so important can you elaborate on why that is so, that might make some answers more 'digestible' to you.
before asking datasheet related questions, provide a link to the datasheet for your display.