Hay
I want interface 2x16 LCD with LPC2106 in 4 bit mode
I have tried the following code but I am not getting proper out put
Please Check the code.
#include"LPC210x.H"
#define RS_1 IOSET | 0x00000800 // RS=P0.11
#define RS_0 IOCLR | 0x00000800
#define EN_1 IOSET | 0x00000400 //EN=P0.10
#define EN_0 IOCLR | 0x00000400
// Data D4 D5 D6 D7 given to P0.16 P0.17 P0.18 P0.19
// R/W PIN IS CONNECTED TO GROUND
void delay()
{
unsigned int i;
for(i=0;i<=20000;i++);
}
void lcdcmd(unsigned char value) // LCD COMMAND
{
int data,copy;
data=value;
data=data<<16;
copy=data;
data=((data>>4)& 0x000F0000); //Strobe 4-Bit High Nibble to LCD
IOSET=IOSET | data;
IOCLR=IOCLR |~data;
IOCLR=RS_0; //COMMAND REGISTER
IOSET=EN_1;//LCD TO LATCH THE DATA
delay();
IOCLR=EN_0;
//lower nibble
data=copy;
data=(data & 0x000F0000); // Strobe 4-Bit Low -Nibble to LCD
IOSET=IOSET | data;
IOCLR=IOCLR |~data;
IOCLR=RS_0;//COMMAND REGISTER
IOSET=EN_1;//LCD TO LATCH THE DATA
delay();
IOCLR=EN_0;
}
void lcddata(unsigned char value) // LCD DATA
{
int data,copy;
data=value;
data=data<<16;
copy=data;
data=((data>>4) & 0x000F0000); //Strobe 4-Bit High Nibble to LCD
IOSET=IOSET | data;
IOCLR=IOCLR |~data;
IOSET=RS_1;//DATA REGISTER
IOSET=EN_1;//LCD TO LATCH THE DATA
delay();
IOCLR=EN_0;
////lower nibble/////////////////
data=copy;
data=(data & 0x000F0000); //Strobe 4-Bit Low Nibble to LCD
IOSET=IOSET | data;
IOCLR=IOCLR |~data;
IOSET=RS_1;//DATA REGISTER
IOSET=EN_1;;//LCD TO LATCH THE DATA
delay();
IOCLR=EN_0;
}
void main()
{
PINSEL0=0x00000000; //ALL PINS ARE GPIO
PINSEL1=0x00000000;
IODIR=0xFFFFFFFF; // ALL PINS ARE OUTPUT
delay();
lcdcmd(0x28); // 2X16 LCD IN 4 BIT MODE
lcdcmd(0x0E);
lcdcmd(0x01);
lcdcmd(0x06);
lcdcmd(0x80);
lcddata(‘T’);
lcddata(‘H’);
lcddata(‘A’);
lcddata(‘N’);
lcddata(‘K’);
lcddata(‘S’);
while(1);
}
Regards
chandu