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.

PLZ help me with this code

Status
Not open for further replies.

dashkil

Member level 2
Joined
Mar 3, 2012
Messages
45
Helped
1
Reputation
2
Reaction score
0
Trophy points
1,286
Activity points
1,620
i am interfacing a lcd(which has a ST7066U lcd driver), with AT-89S51 and OSC-20mhz, my code is working in proteus 7.7, but not working in hardware, i am posting the code below: PLZ help me


Code C - [expand]
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
#define count 1700                             // for 1 ms(approximate)
#include <REGX51.H>
sbit RS=P1^0;
sbit RW=P1^1;
sbit EN=P1^2;
//***********************************//
void delay(unsigned int ms);                  // for Lcd delay
void enable();                                // for strobe control
void command(unsigned char cmd_code);         // for instruction
void Lcd_string(unsigned char *text);         // for writting a string
void Lcd_int();                               // for Lcd initialization
//***********************************//
 
void main()
{
delay(50);
while(1)
{
  Lcd_int();
  Lcd_string("ALMIGHTY *****");
  delay(200);
}
}
//***********************************//
 
void delay(unsigned int ms)
{
unsigned char n;
unsigned int i;
for(n=0;n<ms;n++)
{
  for(i=0;i<count;i++)
  ;
}
}
//************************************//
 
void enable()
{
EN=1;
delay(1);
EN=0;
delay(2);
}
//************************************//
void command(unsigned char cmd_code)
{
P2=cmd_code;
enable();
}
//************************************//
void Lcd_int()
{
RS=0;                   // for instruction data
RW=0;                   // for write operation
EN=0;                   // enable is low
command(0x30);          // mode 8 bit, 1 line display,font 5x8
command(0x30);
command(0x0F);          // entire display on,cursor on,blinking on
command(0x02);          // return cursor to origin
command(0x01);          // clear display
command(0x06);          // entry mode is set
} 
//************************************//
void Lcd_string(unsigned char *text)
{
RS=1;
RW=0;
while(*text!='\0')
{
  P2=*text++;             // for outputing a single byte at a time 
  enable();
}
}
//************************************//

 

Have you checked that the connection of the LCDF is correct to the AT-89S51 ? Does it display garbage character or completely blank/off?
 

If it's working in Proteus and not in the real circuit it is probably the delays (unless you have a wrong connection) so try with higher delay.
 

I have several attempts, at 3rd or 4th i got some garbage character but later its only on showing nothing not even cursor blinking.

---------- Post added at 17:46 ---------- Previous post was at 17:25 ----------

i have got some garbage character at 3rd or 4th attempt but later lcd is just on, showing nothing not even cursor blinking, i have adjusted the POT for adjusting the contrast but no improvement.
 

Initialization procedure (lcd_int) for LCD should be out of main loop:

Code:
void main()
{
delay(50);
Lcd_int();

while(1)
{

  Lcd_string("ALMIGHTY *****");
  delay(200);
}
}
 

i have done that and run the code in proteus but new problem appeared, once the text shown, the beginning first two letter is just appearing at last of the text;
for example: "ALMIGHTY ALLAHAL"; how can i eliminate this problem.
 

After lcd initialization procedure you should clear LCD memory. You can do that writing all 16 locations with blank character or sending clear display command
 

Yes, you should clear the LCD as a part of you initialisation procedure which should also be outside of you main() loop.
If your program is working, at least to a certain extent in proteus then it is most likely not to be a problem with you software.
The first thing to check would be you physical connections to the screen, buzz it through with a meter to make sure that they are there and correct.
I have had major problems with LCD displays before which turned out to be due to decoupling, basically the power supply that I used wasn't powerful enough to provide power to the LCD display and to the other things that I was driving on the +5V line, this meant that whenever I was driving these other things, the voltage to the screen would dip and cause it to reset, this caused "garbage" characters to appear and the whole thing not to function as expected, I got around this problem by sticking a big capacitor between the +VCC and GND connections on the back of the LCD display and cutting the +VCC wire to the screen and placing a diode in series so that when the voltage dropped on the +VCC line the capacitor would only power the LCD display and not the whole circuit, I would recommend using a capacitor >1mF. This is worth doing just for noise immunity anyway!
If this doesn't help then I would say have a look at your timings and make sure they correspond to the timing specifications in the LCD datasheet.

Hope this helps,

/Pheetuz.
 

thanks,i appreciate your suggestions,but it is becoming little bit fuzzy, can u provide me a circuit diagram of such connection you mentioned.
 

I don't have any PCB schematic capture software on the computer that I am using at the moment, this diagram below might illustrate what I am trying to say a little more, its the best I can do with the tools I have at the moment.

Diode1
5V ------|>|--------------------------------------- VCC on your LCD
|
---Capacitor 1
---
|
GND------------------------------------------------- GND on your LCD

So as you can see from the (rubbish) diagram above you have a capacitor decoupling your VCC and GND connections but you also have a diode in series with the 5V connection, this diode stops the rest of the circuit being powered if a voltage drop occurs on the 5V line ... I would recommend just putting the capacitor in for the time being and seeing if that makes a difference, if not then give the diode a try.

/Pheetuz

---------- Post added at 22:34 ---------- Previous post was at 22:33 ----------

Drats, that didnt come out how it previewed! ... Capacitor 1 should be on the other side of the diode!
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top