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.

Help me fix an LCD code in C for 89c52

Status
Not open for further replies.

aditya2806

Newbie level 3
Joined
Jun 13, 2008
Messages
4
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,281
Activity points
1,320
I have written a c code for atmel 89c52.....
i just wanted to see if my lcd is working fine.....
this is just a test code to display "a" on the lcd....
but its not working.... please help me out........

#include<AT89X52.h>

#define lcd_data P1
#define lcd_busy P1_7
#define lcd_rs P3_3
#define lcd_rw P3_2
#define lcd_en P3_4
#define P3 = 0x00;

void lcd_delay()
{
unsigned char i,j;

for(i=0;i<50;i++)

for(j=0;j<255;j++)
;
}

void lcd_init()
{
lcd_data = 0x38;
lcd_rs = 0;
lcd_rw = 0;
lcd_en = 1;
lcd_en = 0;
lcd_delay();
lcd_data = 0x0F;
lcd_rs = 0;
lcd_rw = 0;
lcd_en = 1;
lcd_en = 0;
lcd_delay();
lcd_data = 0x01;
lcd_rs = 0;
lcd_rw = 0;
lcd_en = 1;
lcd_en = 0;
lcd_delay();
lcd_data = 0x06;
lcd_rs = 0;
lcd_rw = 0;
lcd_en = 1;
lcd_en = 0;
lcd_delay();
}

void lcd_command (unsigned char var)
{
lcd_data = var;
lcd_rs = 0;
lcd_rw = 0;
lcd_en = 1;
lcd_en = 0;
lcd_delay();
}

void lcd_senddata (unsigned char var)
{
lcd_data = var;
lcd_rs = 1;
lcd_rw = 0;
lcd_en = 1;
lcd_en = 0;
lcd_delay();

}

void lcd_sendstring(unsigned char *var)
{
while(*var)
lcd_senddata(*var++);
}



void main()
{

lcd_init();
lcd_command(0x83);
lcd_senddata('a');
}
 

lcd interfacing with 89s52

Change this line
lcd_senddata('a');
to
lcd_senddata("a");
 

89c52 c

using 'a' we are getting 0x0061 in output . so might be some other problem is there
 

89c52 delay

This is for 16x1 (8x2 electrical) in Ke*l. Written for AT89S8252/3. Possibly may be of some use to you.

LCD.H

/*
* LCD interface header file
* See lcd.c for more info
*/

/* write a byte to the LCD in 4 bit mode */

extern void lcd_write(unsigned char);

/* Clear and home the LCD */

extern void lcd_clear(void);

/* write a string of characters to the LCD */


LCD.C

#include <reg51.h>
#include "delay.h"

sbit LCD_RS =P1^0; // Register select
sbit LCD_E =P1^1; // Enable

#define LCD_STROBE ((LCD_E = 1),(LCD_E=0))

// Time in Milliseconds
void DelayMs(unsigned char cnt)
{ cnt=2*cnt;
do
{DelayUs(500);}
while(--cnt != 0);
}

// Send to Display
void lcd_write(unsigned char c)
{
unsigned char Movit;
Movit = (c >> 2);
P1 = (P1 & 0xC3) | (Movit & 0x3C);
LCD_STROBE;
Movit = (c << 2);
P1 = (P1 & 0xC3) | (Movit & 0x3C);
LCD_STROBE;
DelayUs(60);
}

// Clear and home the LCD
void lcd_clear(void)
{
LCD_RS = 0;
lcd_write(0x80);
DelayMs(2);
}

// Position the Cursor
void lcd_goto(unsigned char pos)
{
LCD_RS = 0;


DELAY

#define XTAL_FREQ 12
#define DelayUs(x) { unsigned char _dcnt; \
_dcnt = (x)*((XTAL_FREQ)/12); \
while(--_dcnt != 0) \
continue; }

extern void DelayMs(unsigned char);

Added after 10 minutes:

Sorry I forgot the connections

P1.0 = RS
P1.1 = E
P1.2 = D4
P1.3 = D5
P1.4 = D6
P1.5 = D7

Ground Pin 3 on LCD

Delay shown is "Delay.h"

Added after 5 minutes:

Sorry I meant ground R/W pin. Pin 3 is contrast, cannot remember if 3 goes to vcc or vss for full contrast.
 

lcd code

Hi,
This statement appears to be the culprit:
#define P3 = 0x00; Why #define? Also, the LCD_INIT does not seem to have standard delays and sequence of instructins recommended by the manufacturer.
You have also not specified the type of display (numbers of lines and number of characters per line), from your program it appears to be 16*2 and you are using 8bit interface?.

Regards,
Laktronics
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top