I can't manage to get my LCD to initialize, am i doing something wrong? Any help appreciated!
#include <stdio.h>
#include <stdlib.h>
#include <p89lpc9351.h>
#define XTAL 7373000L
#define BAUD 115600L
#define LCD_data P2
#define LCD_rs P1_4
#define LCD_rw P1_6
#define LCD_en P1_7
void putchar (char c)
{
while (!TI);
TI=0;
SBUF=c;
}
char getchar (void)
{
while (!RI);
RI=0;
return SBUF;
}
void InitSerialPort(void)
{
BRGCON=0x00; //Make sure the baud rate generator is off
BRGR1=((XTAL/BAUD)-16)/0x100;
BRGR0=((XTAL/BAUD)-16)%0x100;
BRGCON=0x03; //Turn-on the baud rate generator
SCON=0x52; //Serial port in mode 1, ren, txrdy, rxempty
P1M1=0x00; //Enable pins RxD and Txd
P1M2=0x00; //Enable pins RxD and Txd
}
void delay_ms(long ms)
{
long i;
while (ms--)
for (i=0; i < 330; i++)
;
}
void command(char i)
{
LCD_data = i; //put data on output Port
LCD_rs =0; //D/I=LOW : send instruction
LCD_rw =0; //R/W=LOW : Write
LCD_en = 1;
delay_ms(1); //enable pulse width >= 300ns
LCD_en = 0;
}
void write(char i)
{
LCD_data = i; //put data on output Port
LCD_rs =1; //D/I=LOW : send data
LCD_rw =0; //R/W=LOW : Write
LCD_en = 1;
delay_ms(1); //enable pulse width >= 300ns
LCD_en = 0; //Clock enable: falling edge
}
void LCD_init()
{
LCD_en = 0;
delay_ms(100); //Wait >15 msec after power is applied
command(0x30); //command 0x30 = Wake up
delay_ms(30); //must wait 5ms, busy flag not available
command(0x30); //command 0x30 = Wake up #2
delay_ms(10); //must wait 160us, busy flag not available
command(0x30); //command 0x30 = Wake up #3
delay_ms(10); //must wait 160us, busy flag not available
command(0x38); //Function set: 8-bit/2-line
command(0x10); //Set cursor
command(0x0c); //Display ON; Cursor ON
command(0x06); //Entry mode set
}
void main (void)
{
InitSerialPort();
LCD_init();
}
The init sequence looks ok. Did you forget to explicitly set P2 and P1 pins to outputs?