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
Erm.. i forgot to say what help i needed... lol...
Can anyone help me to check where the program is wrong or whether i have connected the pins wrong.
By the way, the input voltage of the LCD is connected to a 5V supply and the contrast pin is connected to a 10k variable resistor. I have tried using stepping to find out the problem. I found out that the program keep looping here after the 1st LCALL WAIT_LCD
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
Does EN's timing satisfy the specified timing requirements?
Sorry, but i don't really get what you mean. Isit the En cycle time or the En rise/fall time u are talking about? Sorry.. Im really new to LCD programming...
Dan Henry asked, "Does EN's timing satisfy the specified timing requirements?"
natur3 t0mAt0 replied, "...Is it the En cycle time or the En rise/fall time"
They both form part of "the specified timing requirements"!
Oh. i see. sorry to bother u guys again. but what is the specified timing requirements? How do i check?
"what is the specified timing requirements? How do i check?"
That will be in tha Datasheet for the LCD.
ok.. I found the timing characteristics. Is it all this?
Enable cycle time Enable pulse width ("High" level) Enable rise/fall time Set-up time (RS,R/W,E) Address hold time Data Set-up time Data delay time Data hold time (writing) Data hold time (reading) Clock oscillating frequency
But how do i read these numbers? The datasheet gave me the symbols, min,max and the unit which is in nanosec. I don't know what these means...
If you don't have an oscilloscope to actually measure the signals, you will have to measure, evaluate or guestimate the number of clock cycles the processor needs when performing different operations. You will then have to make sure that all signal changes are made in the correct sequence and with enough delay.
I haven't looked at this specific data sheet, but the numeric parameters in the data sheet should be displayed somewhere in a timing diagram, where you can see between which points in the timing diagram that a specific parameter measures. Then you must make sure that you are always within the min and/or max times for that parameter.
For example: When writing data to the display, you must first emit the data before latching the data. The data sheet will specify the minimum ns the data must be stable before the strobe signal is toggled to latch the data. It will also show how many ns the data must continue to be stable after the latch/strobe signal is toggled again.
"data setup time" is normally how long before, you must have the data stable. "data hold time" is normally how long you must continue to hold the data stable after the latch operation. "data delay time" is how long time it takes for the display to drive the data signals to correct value when you issue a read command.
However, the data sheet should contain clear timing diagrams for these, and then it should be quite easy to understand what the parameters to, and why they are important.
Erm.. I think i get what u mean for the clock cycles. You meant i have to calculate the clock cycles for each routine and make sure that they have enuff delay? Does that mean i have to make another routine called "Delay" and call it from the other routine?
"correct sequence": The routines have to be in a correct sequence? I thought they can be called from anywhere in the program?
Also i do not know what you meant by the data have to be stable before latching and so on.
The datasheet have 2 charts; 1 for write and 1 for read. But i do not understand. if possible, it'll be great if there is a example code to tell me exactly what the timing means.
Thanks in advance.
You do not need any delay function. The required delays are very, very short. Most often, the required delays are shorter than the max speed the CPU can toggle signals. However, you have to make sure.
The timing sequences shows in which order different signals should be toggled to make sure that all required signals have correct values when they are needed.
If I show you a paper, and then remove it again and ask you to read it, you would not be able to. When you tell the display to read a value (when you write to the display), that value must already be available for the display to read. The value you write to the display (requests the display to read) must continue to be available until a while after you stop telling the display to read it.
All such requirements are graphically displayed in the data sheet, as timing or sequence diagrams. They show when a specific signal may take any value, when it must be low and when it must be high.
Well, in my datasheet, there is 2 diagrams, one for write operation and one for read operation. But i do not understand these diagrams. You might want to go this website: docs-asia.electrocomponents.com/.../0900766b800b986e.pdf
as this is where i Downloaded timing datasheet.
You meant i have to calculate the clock cycles for each routine and make sure that they have enuff delay?
Not quite. You will have to determine the timing of those signals. Calculating is only one of many ways of determining it, and hardly ever the best one to choose.
The best method would be to use an oscilloscope or logic analyzer on the actual hardware. If you really can't get your hands on a 'scope, the next best thing is the logic analyzer built into the uVision simulator debugger. Using that, you can generate almost exactly the same kind of diagram as you'll find in the datasheet(s) of devices you're trying to control. That can make things a whole lot easier to check.
"in my datasheet, there is 2 diagrams, one for write operation and one for read operation. But i do not understand these diagrams"
The Write diagram is showing:
1. The first thing that must happen is that R/W must either already be low, or be taken low, and RS must have reached its steady state for the operation
2. A time tAS must then elapse before E reaches its high-level threshold, VIH1
3. The time that it takes E to rise from its low-level threshold, VIL1, to VIH1 is called its rise-time and is specified by tEr
4. E must remain high for a time tDSW after the Data lines DB0~DB7 stabilise to valid levels
5. The Data line must remain valid for a time tH after E falls below VIL1
etc
Looking closer at your code, it appears that the display uses the ubiquitous Hitachi HD44780 controller or similar. It also appears that the code is designed to pace display writes by checking the controller's busy flag and it does so after writing the very first display instruction. Relying on proper busy flag operation right from the start like that require using the display with internal reset. When using the internal reset, the electrical characteristics in the controller data sheet's "Power Supply Conditions Using Internal Reset Circuit" table must be satisfied; otherwise, an "initialization by instruction" sequence must be used. It isn't until after the third step in the "initialization by instruction" sequence that the busy flag can be used reliably.
So, there is another aspect of timing for you to check before using that code you found on the Internet, and that is the power supply rise time. Does your circuit satisfy the rise time requirements to use the display without employing the "initialization by instruction" sequence?
So i have to check the signals by using either an oscilloscope or a logic analyzer in order to make make sure that it is about the same diagram as the write diagram? So where do i get the signals from? From the LCD or the development kit?
Also, how can i check whether my circuit satisfy the rise time to use the display?