Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

LCD 4-bits Interface to AT89C52

Status
Not open for further replies.

Help

Advanced Member level 2
Joined
Feb 15, 2005
Messages
617
Helped
7
Reputation
14
Reaction score
3
Trophy points
1,298
Activity points
7,065
s6a0069 code

Hi,

Anyone can help to check my coding?

I am using 20x2 LCD. I can get the 1st line display but i can't get the 2nd line display? Why? :cry:

Thank You.
 

bits interface

Probably u r not entering the correct address of the characters starting in the second line... i guess the first char. of the 2nd line has the address: 81h... do verify it... hopefully this will fix ur prob...
 

lcd at89c52

hot_ice said:
Probably u r not entering the correct address of the characters starting in the second line... i guess the first char. of the 2nd line has the address: 81h... do verify it...

As you can see my code. I already created one function which is

Code:
void LCD_SetDDRAM(tByte ADDRESS) 
   {                            
   ADDRESS &= 0x7f;
   ADDRESS |= 0x80;
   LCD_Send_Byte(ADDRESS,0);
   }

my call function for:
1st line LCD_SetDDRAM(0x00 + Character); // First line
2nd line LCD_SetDDRAM(0x40 + Character); // Second line

after go through this LCD_SetDDRAM() function the LCD_DDRAM_ADDRESS with become

LCD_DDRAM_ADDRESS for 1st line = 0x80;
LCD_DDRAM_ADDRESS for 2nd line = 0xC0;

Let say i got 4 characters "Halo" wanna to display on second liine.
'H' = 0xC0 DDRAM addr.
'a' = 0xC1 DDRAM addr.
'l' = 0xC2 DDRAM addr.
'o' = 0xC3 DDRAM addr.

Do you have any ideas?

Thank for you kindly reply.
 

lcd interface at89c52

Since you did not point out which LCD controller is used, but many of character type LCM used HD44780/KS0066(S6A0069) or compatible.
As your mentions and code, I think the LCM is set on "1-line display mode".
So, to try to change/replace as this line in 'LCD_Init' of LCD_A.C: (you used 0x32)
Code:
   LCD_Send_Byte(0x22,0); // Sets Interface to 4-bit
Though, it contains a hidden problem (twice WRITE). Anyway, to check 2nd line is OK or not first.
 

    Help

    Points: 2
    Helpful Answer Positive Rating
4 bit lcd second

yager said:
try to change/replace as this line in 'LCD_Init' of LCD_A.C: (you used 0x32)
Code:
   LCD_Send_Byte(0x22,0); // Sets Interface to 4-bit

After i changed it to LCD_Send_Byte(0x22,0); the display can't display the 1st line properly worst than early setting and no 2nd line display...

I also try this before....
Code:
   for (loop = 0; loop < 3; loop++)
      {
      LCD_Send_Byte(0x32,0); 
      Hardware_Delay_T0(5); 
      }

but still can't display properly and no 2nd line display... :cry:

help......
 

comparison of at89c52 with previous

To check your LCD controller in LCM first. If it is HD44780/KS0066(S6A0069) or compatible.
After Power Up, the initial settings are: 8-bit interface, 2-line, 5x8 font
To switch to 4-bit interface, you have to issue only 1 WRITE for 1st "Function Set" command.
But the 'LCD_Send_Byte' always issue 2 WRITE, that's why the hidden problem is.
(IMHO, it will be ok if 2nd WRITE is fast than 30uS after 1st WRITE, LCM should ignore the 2nd WRITE)
i.e. the 'LCD_Send_Byte' has to have an ability to issue only 1 WRITE.
I made some changes for 'LCD_Send_Byte' & 'LCD_Init'. To try it.
 

    Help

    Points: 2
    Helpful Answer Positive Rating
5x8 ks0066 lcd code

Hi,

I think my LCD is standard. I understand what you trying to do on my code. Thank You!
But we can't see any message on the LCD, 1st line.
I also try few testing on that:
1)
Code:
   bLCD_Send_Nibble = 1;
   for (loop = 0; loop < 3; loop++)
      {
      LCD_Send_Byte(LCD_8BIT_2LINE_5x8FONT,0); // be sure it is 8-bit interface
      Hardware_Delay_T0(5);
      }

   for (loop = 0; loop < 3; loop++)
   {
      LCD_Send_Byte(LCD_4BIT_2LINE_5x8FONT,0); // Sets Interface to 4-bit
      Hardware_Delay_T0(1);
   }
   bLCD_Send_Nibble = 0;
   LCD_Send_Byte(LCD_4BIT_2LINE_5x8FONT,0); // 2-line & 5x8 font
   Hardware_Delay_T0(1);

2)
Code:
   bLCD_Send_Nibble = 1;
   for (loop = 0; loop < 3; loop++)
      {
      LCD_Send_Byte(LCD_4BIT_2LINE_5x8FONT,0); 
      Hardware_Delay_T0(5); 
      }

   bLCD_Send_Nibble = 0;
   LCD_Send_Byte(LCD_4BIT_2LINE_5x8FONT,0); // 2-line & 5x8 font
   Hardware_Delay_T0(1);

This two testing also can't show any message on LCD.

What's the following step we need to do?

Thank You!
 

lcd_send_byte 4 bit

Help said:
I think my LCD is standard. I understand what you trying to do on my code. Thank You!
But we can't see any message on the LCD, 1st line.
Well, I port the code to meet my hardware with Data Vision DV-20200 LCM.
As you said, the display is empty. But the initial sequences are ok.
Because there are another problems:
1. it is needed a delay after 'LCD_SetDDRAM' in 'LCD_Update'
2. it is needed a delay after 'LCD_Send_Byte(Data,1);' in 'LCD_Update'
3. it should be needed more delay after 'LCD_Send_Byte(LCD_CLEAR_DISPLAY,0);' in 'LCD_Init'
Now, it is working for both of lines. To check it again.
 

    Help

    Points: 2
    Helpful Answer Positive Rating
lcd4bits

Hi,

My LCD working already! :D Thanks alot! Just now i get a new LCD (different brand) to do the comparison. After that i found out 1 thing, my LCD pin2 never connected to supply 5V. So, we can't see the character on LCD very clear but before we do the modification on software the LCD still can display the 1st line.

Now connected the LCD pin2 to supply, we can see the message on LCD already. By right the early setting u do it for me also can work. But i still not understand why you initial the 8-bit interface?

Code:
   for (loop = 0; loop < 3; loop++)
      {
      LCD_Send_Byte(LCD_8BIT_2LINE_5x8FONT,0); // be sure it is 8-bit interface
      Hardware_Delay_T0(5); 
      }

Now i facing a new problem after this....
I let it keep-on display the characters, after certain time the LCD can't display properly already. It comeout different different.. characters that you unexpected, look like the LCD not stable.... Do you know why?

Thank You.
 

lcm 4-bit mcu

Help said:
Now connected the LCD pin2 to supply, we can see the message on LCD already. By right the early setting u do it for me also can work. But i still not understand why you initial the 8-bit interface?
Code:
   for (loop = 0; loop < 3; loop++)
      {
      LCD_Send_Byte(LCD_8BIT_2LINE_5x8FONT,0); // be sure it is 8-bit interface
      Hardware_Delay_T0(5); 
      }
First, why it is also working by the early setting? As I mentioned, it has a hidden problem.
Because you only use 12MHz OSC, and the 1st half of 'LCD_Send_Byte' is needed over 50uS before 2nd one to send.
So the 0x32 will be recognized by LCM as:
0x3X (POR is 8-bit interface) and 0x2X (switch to 4-bit interface)
If your MCU is working at more fast, LCM will only service 1st 0x3X command (it is busy when send the 2nd 0x2X command).
That's why we have to offer the ability for sending 1 nibble only.

Second, why initial to the 8-bit interace first?
It is trick to make sure the LCM will recognize our commands in 4-bit interace.
To suppose the MCU could be RESET (ex: to implement ISP/IAP), but the LCM not.
After the code reboot, we do not know what codition of LCM is (its power without loss).
It could be 4-bit or 8-bit interface or waiting 2nd nibble data.
To do the magic commands in 3 times, we can recover any conditions back.
Help said:
I let it keep-on display the characters, after certain time the LCD can't display properly already. It comeout different different.. characters that you unexpected, look like the LCD not stable.... Do you know why?
In fact, the 8051 P1/P2/P3 to use internal pull-up resistors to output H level
(quasi-bidirectional), its capability of driving H is so weak.
If use a parallel cable to connect LCM and also if the timing is fast, the problem will be encounted.
The "E" (ENABLE) is so important, I usually use a transistor to invert it
to offer more driving/sinking capability if it is controlled by the weak output as like as 8051.
Besides, to slow down the timing in ''LCD_Send_Byte' will also help.
FYR
 

    Help

    Points: 2
    Helpful Answer Positive Rating
display 4bit interface

Hi,

Thank for your good explanation. Thanks again...

So, you mean we need to add a driver to drive the "E" only or drive the R/W and D4-D7 also?
I try and see... to slow down the "LCD_Send_Byte" then let you know the status.

Thank You.
 

lcd driving with at89c52

Help said:
So, you mean we need to add a driver to drive the "E" only or drive the R/W and D4-D7 also?
I usually connect R/W to GND (WRITE only), so all of commands are necessary to delay before sending next one.
And used a transistor as a driver to invert/drive the "E" only.
 

    Help

    Points: 2
    Helpful Answer Positive Rating
Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top