Email: Password: Remember Me | Create Account (Free)

Back to Subject List

Old thread has been locked -- no new posts accepted in this thread
???
04/09/11 03:51
Read: times


 
#181788 - LCD 16*2 Display Problem
I have written a C code for 89s52 16*2 lcd. The lcd is displaying same garbage everytime i connect to it. Upon hitting my keyboard buttons, the display changes but the pattern of changes is the same. Also, lcd starts displaying from the 9th character of first row. I'm putting my code below here. The code is working fine on proteus simulation but not on h/w. Please help.

#include <REG51.H>
sbit rs = P2^0;
sbit en = P2^2;
sfr ldata = 0x80;

void delay(void);
void lcdcmd (unsigned char value);
void lcddata (unsigned char value);
void waitLcd (void);
void lcdInit (void);
void displayLCD(char *str, int len);

// Function for small delay
void delay(void)
{
unsigned int j;
for (j=0; j<250; j++);
}

// Function for lcd cmd
void lcdcmd (unsigned char value)
{
ldata = value;
rs = 0;
en = 1;
delay();
en = 0;
}

// Function for lcd data
void lcddata (unsigned char value)
{
ldata = value;
rs = 1;
en = 1;
delay();
en = 0;
}

// Function for lcd power on delay
void waitLcd (void)
{
unsigned int i;
for (i=0; i<20000; i++);
}

// Function to initialize lcd
void lcdInit (void)
{
waitLcd();
lcdcmd (0x38);
waitLcd();
lcdcmd (0x0E);
waitLcd();
lcdcmd (0x01);
waitLcd();
lcdcmd (0x06);
waitLcd();
lcdcmd (0x80);
waitLcd();
}

// Function to display string using function lcd data
void displayLCD(char *str, int len)
{
waitLcd() ;
while(len != 0)
{
lcddata(*str);
delay();
str++;
len--;
}
}

// Main
// Only to test lcd individually!!
void main (void)
{
ldata = 0x00;
rs = 0;
en = 0;
lcdInit();
displayLCD ("Hello",5);
do {} while (1);

}


List of 4 messages in thread
TopicAuthorDate
LCD 16*2 Display Problem            01/01/70 00:00      
   Illegible source code; 'C' timing loops            01/01/70 00:00      
   Delays            01/01/70 00:00      
      RE: Delays            01/01/70 00:00      

Back to Subject List