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

Back to Subject List

Old thread has been locked -- no new posts accepted in this thread
???
07/18/06 18:01
Read: times


 
Msg Score: -1
 -1 Didn't Search First
#120503 - Help : LCD Cant Works
Below is a very simple code i created to display a string character on a standard 16x2 LCD. For some reason, the LCD keep showing a string of solid black box everytime the power supply is turned on (by default) and i could not find anything wrong with the codes. Please help me by looking through this code to see if there's anything wrong or i wont be able to proceed with my project :(

For my PIN assignment :

P1.0-P1.7 = Pin 7-Pin 14 of LCD respectively.
P0.5 = Pin 4 of LCD (Rs)
P0.6 = Pin 6 of LCD (E)
P0.7 = Pin 5 of LCD (R/W)

+5V is connected to Pin 2 of LCD (Vcc) and 8051's Vcc like usual.
XTAL1 and XTAL2 is connected to a 11.0592Mhz crystal oscillator as usual.
GND of 8051, Pin 1 and Pin 3 of LCD is grounded as usual.


#include <reg52.h>
#include <stdio.h>

#define On 0
#define Off 1

#define InstReg 0
#define DataReg 1
#define Write 0
#define Read 1

#define DB0_7 P1

sbit EN = P0^6;
sbit RW = P0^7;
sbit RS = P0^5;
sbit BF = P1^7;

// AT89C51ED2 Extensions
sfr CKCON0 = 0x8F;
sfr CKCON1 = 0xAF;
sfr EECON = 0xD2;

char LCD_Buffer[32];

void InitLCD (void);
void LCD_Print (char *str);
void SetLCD (unsigned char RegSelect, unsigned char WRData);
void GetLCDReady (void);
void Delay (unsigned int milisec);

void main ()
{
SetLCD (InstReg, 0x01); // Clear display screen
InitLCD ();

while (1)
{

LCD_Print("WTF");


// write your program here
}
}

void InitLCD (void)
{
SetLCD (InstReg, 0x38); // Init LCD 2 lines, 5 x 7 matrix //0011 1000
SetLCD (InstReg, 0x06); // Auto address increment mode, shift cursor from Left to Right //0000 0110
SetLCD (InstReg, 0x0C); // Display on cursor off // 0000 1100
SetLCD (InstReg, 0x01); // Clear display screen
}

void LCD_Print (char *str)
{
SetLCD (InstReg, 0x02); // Return Cursor to Home
for (; *str != '\0'; str ++)
{
if (*str == '\n')
{
SetLCD (InstReg, 0xC0); // 1100 0000
}
else
{
SetLCD (DataReg, *str);
}
}
}

void SetLCD (unsigned char RegSelect, unsigned char WRData)
{
GetLCDReady ();
RS = RegSelect;
RW = Write;
DB0_7 = WRData;
EN = 1;
EN = 0;

}

void GetLCDReady (void)
{
RS = InstReg;
RW = Read;
BF = 1;
do
{

EN = 0;
EN = 1;

} while (BF == 1);
EN = 0;

}



List of 8 messages in thread
TopicAuthorDate
Help : LCD Cant Works            01/01/70 00:00      
   Initialization?            01/01/70 00:00      
   Some links            01/01/70 00:00      
   Sending a data buffer to LCD            01/01/70 00:00      
      That Depends            01/01/70 00:00      
         hmm            01/01/70 00:00      
            You're on the right track            01/01/70 00:00      
            some choices            01/01/70 00:00      

Back to Subject List