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.

89c51 interfacing to LCD - problem in LCD dispalying chars

Status
Not open for further replies.

srikantan

Newbie level 3
Joined
Apr 14, 2009
Messages
4
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,281
Activity points
1,316
89c51 interfacing to LCD

hi..I tried to interface data signals to LCD(2 x16) via P1 and control bits via P2(RS/RW/EN).its the standard code in Mazidi book and still there is problem in LCD dispalying chars.I gave direct connectivity w/o any pullups.is it ok?I suspect the hw.
Any adice please...?
thank you..sri.kc
 

ESHINEDISPLAY

Newbie level 4
Joined
Dec 13, 2010
Messages
7
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,281
Activity points
1,376
//FileName:delay.h

#ifndef __LZP_DELAY_H_

#define __LZP_DELAY_H_

#define TRUE 1

#define FALSE 0

//设置波特率

#define OSC_FREQ 11059200L

#define BAUD_115200 256 - (OSC_FREQ/192L)/115200L // 255

#define BAUD_57600 256 - (OSC_FREQ/192L)/57600L // 254

#define BAUD_38400 256 - (OSC_FREQ/192L)/38400L // 253

#define BAUD_28800 256 - (OSC_FREQ/192L)/28800L // 252

#define BAUD_19200 256 - (OSC_FREQ/192L)/19200L // 250

#define BAUD_14400 256 - (OSC_FREQ/192L)/14400L // 248

#define BAUD_9600 256 - (OSC_FREQ/192L)/9600L // 244

// Timer2

#define RCAP2_50us 65536L - OSC_FREQ/240417L

#define RCAP2_1ms 65536L - OSC_FREQ/12021L

void delay_ms(unsigned int num);

void delay_50us(unsigned char num);

void delay_us(unsigned char num);

#endif

//FileName:delay.c

/********************************************

** start51 study board

** delay function implementation

** author:bluehacker

** QQ:282074921

**********************************************/

#include "delay.h"

#include "reg52.h"

void delay_ms(unsigned int num)

{

RCAP2H = (RCAP2_1ms>>8);

RCAP2L=(RCAP2_1ms&0x00ff);

TH2=(RCAP2_1ms>>8);;

TL2=(RCAP2_1ms&0x00ff);;

ET2 = 0; // Disable timer2 interrupt

T2CON = 0x04; // 16-bit auto-reload, clear TF2, start timer

while (num--)

{

while (!TF2);

TF2 = FALSE;

}

TR2 = FALSE;

}

void delay_50us(unsigned char num)

{

RCAP2H=(RCAP2_50us>>8);

RCAP2L=(RCAP2_50us&0x00ff);

TH2=(RCAP2_50us>>8);

TL2=(RCAP2_50us&0x00ff);

ET2=0;

T2CON=0x04;

while(num--)

{

while(!TF2)

TF2=FALSE;

}

TR2=FALSE;

}

void delay_us(unsigned char num)

{

unsigned char i;

for (i=0;i

{

}

}

//FileName:lcd.h

#ifndef __LZP_LCD_H_

#define __LZP_LCD_H_

#include "reg52.h"

/////////////////////////////

//定义LCD控制引脚

////////////////////////////

sbit LCDRS="P2"^0;

sbit LCDRW="P2"^1;

sbit LCDE="P2"^2;

void lcd_write_cmd(unsigned char cmd);

void lcd_write_data(unsigned char dat);

void lcd_clear(void);

void lcd_init(void);

unsigned char lcd_status(void);

void lcd_set_mode(unsigned char cursor, unsigned char text);

void lcd_write_str(unsigned char x,unsigned char y,unsigned char *s);

void lcd_write_char(unsigned char x,unsigned char y, unsigned char d);

#endif
 

Embedded Partner

Full Member level 5
Joined
Nov 29, 2010
Messages
247
Helped
42
Reputation
84
Reaction score
37
Trophy points
1,308
Location
Hubli(INDIA)
Activity points
2,636
here is the code for your LCD
i think it may help you

wrote the code for your project
 

Attachments

  • lcd.rar
    1.1 KB · Views: 23

qwertyuiop415263

Full Member level 4
Joined
Mar 26, 2010
Messages
231
Helped
50
Reputation
102
Reaction score
39
Trophy points
1,308
Location
Pakistan
Activity points
2,414
You will probably miss the declaration of port pins properly.

see this code I have tested it



#include <reg52.h>
#include <math.h>
void lcdcmd (unsigned char);
void lcddata (unsigned char);
void msdelay (unsigned int);
void LCD_sendstring(unsigned char * );

//////////////////////////////////////
sfr ldata =0x90;
sbit rs=P3^7;
sbit rw=P3^6;
sbit en=P3^5;
sbit g=P2^7;
/////////////////////////////


void main(void)
{
lcdcmd (0x38);
msdelay (100);
lcdcmd (0x0C);
msdelay (100);
LCD_sendstring("16x2 LCD");
msdelay(1000)



lcdcmd (0x01);
msdelay(5);

}

void lcdcmd (unsigned char value)
{
ldata=value;
rs=0;
rw=0;
en=1;
msdelay (10);
en=0;
}

void lcddata (unsigned char value)
{
ldata=value;
rs=1;
rw=0;
en=1;
msdelay (10);
en=0;
}


void msdelay (unsigned int itime)
{
unsigned int i,j;
for (i=0;i<itime;i++)
for (j=0;j<1275;j++);
}


void LCD_sendstring(unsigned char *value)
{
while(*value)
lcddata(*value++);
}
 

pratheeshprm143

Newbie level 6
Joined
Oct 14, 2010
Messages
14
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,281
Location
india
Activity points
1,440
Re: 89c51 interfacing to LCD

you check the connection on your 3 rd pin of lcd, use a 4k7 pot here.
you don't need to connect any pull up for this.
make r/w pin grounded if you don't need to read data from lcd.
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Top