??? 01/29/07 16:17 Read: times |
#131637 - try this... Responding to: ???'s previous message |
First, I don't know which compiler you are using, so I don't know if your computer can properly process that code.
Secondly, I would remove LJMP MAIN, or else the equates might not apply. Assuming your LCD is HD47780 compatible, you need to connect pin 1 to ground, Pin 2 to +5V, Pin 3 to a resistor of at least 300 ohms. The other end of the resistor is grounded. Pin 4 connects to the connection point in your circuit controlling the RS line. According to your code, It is P3.7 of the micro. Pin 5 connects to P3.5 if you use your code. Pin 6 connects to P3.4 if you use your code. What I personally do is forget about pin 5 and tie it to ground, and then let the 8051 software (that you provided in code) do all the timing. When pin 5 is grounded, you will be writing data to the LCD. Now the Enable line is crazy, because this is what made my LCD experience horrible until I discovered it. Let's ignore the data sheet for the moment. The idea to send stuff to the LCD is to get the RS set to what mode you want, the data set to what you want, and then (lets say 100 us later), turn the enable line on (P3.4 is high) keep it high for lets say 400 ns. At this point, P3.4 needs to be set to low. Now you need to observe data sheets. According to one of mine, it takes between 40us and 2ms for an LCD to process an instruction. Any write instructions sent to it during this time will be ignored. Keep that delay subroutine of yours. If you are using a fast crystal, then your delay might not be long enough, and you will need to add to it. Now I do NOT recommend grounding pin 3 of the LCD, because the display could get so dark, it could screw up. Maybe you need to replace the LCD. Also, make sure your data lines are connected correctly. According to your code, you need to make the following connections: P1.0 to LCD Pin 7 P1.1 to LCD Pin 8 P1.2 to LCD Pin 9 P1.3 to LCD Pin 10 P1.4 to LCD Pin 11 P1.5 to LCD Pin 12 P1.6 to LCD Pin 13 P1.7 to LCD Pin 14 If any of the above connections are different, you will either need to reconnect the LCD to the connections above, or you need to adjust your code. You will need to consider the microcontroller. Is IT feeding the data correctly. To test it, connect a bunch of LED's to each port output and convert the binary output to hexadecimal. The rest of your code seems to be OK. So check your hardware. Also, check that you are programming the microcontroller properly. Remember, the data bits must be connected properly, and they need to be proper throughout all microcontroller related circuits. |