# LCD

**URL:** <https://community.sparkfun.com/t/lcd/9399>\
**Category:** MicroMod\
**Tags:** arm-lpc\
**Created:** [December 17, 2008, 2:26pm UTC](https://community.sparkfun.com/t/lcd/9399 "2008-12-17T14:26:45Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![chandu13](https://avatars.discourse-cdn.com/v4/letter/c/258eb7/32.png) [@chandu13](https://community.sparkfun.com/u/chandu13)\
**Post date:** [December 17, 2008, 2:26pm UTC](https://community.sparkfun.com/t/lcd/9399/1 "2008-12-17T14:26:45Z")

</div>

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](https://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

---

<div class="post-metadata">

**Author:** ![leon\_heller](https://yyz1.discourse-cdn.com/sparkfun/user_avatar/community.sparkfun.com/leon_heller/32/7602_2.png) [@leon\_heller](https://community.sparkfun.com/u/leon_heller)\
**Post date:** [December 17, 2008, 2:55pm UTC](https://community.sparkfun.com/t/lcd/9399/2 "2008-12-17T14:55:11Z")

</div>

Is your delay long enough?

You’ll find some LCD code in the LPC2000 group’s files section.

Leon

---

<div class="post-metadata">

**Author:** ![chandu13](https://avatars.discourse-cdn.com/v4/letter/c/258eb7/32.png) [@chandu13](https://community.sparkfun.com/u/chandu13)\
**Post date:** [December 23, 2008, 2:58pm UTC](https://community.sparkfun.com/t/lcd/9399/3 "2008-12-23T14:58:22Z")

</div>

hay

Please help me any body regarding the 2x16 LCD in 4 bit mode data interfacing with LPC2106

I am straggling with the above code, I have executed above code. when ever I switched ON the system

Data is not displaying on the LCD, when ever I press reset button at that time data is displaying on the LCD

Please give me some solution

Regards

chandu

---

<div class="post-metadata">

**Author:** ![gdisirio](https://avatars.discourse-cdn.com/v4/letter/g/c4cdca/32.png) [@gdisirio](https://community.sparkfun.com/u/gdisirio)\
**Post date:** [December 23, 2008, 4:48pm UTC](https://community.sparkfun.com/t/lcd/9399/4 "2008-12-23T16:48:08Z")

</div>

This could help. The initialization code is critical or the display does not switch in 4bits mode.

Source:

[http://chibios.svn.sourceforge.net/view … iew=markup](http://chibios.svn.sourceforge.net/viewvc/chibios/trunk/demos/AVR-ATmega128-GCC/lcd.c?revision=219&view=markup)

Header file:

[http://chibios.svn.sourceforge.net/view … iew=markup](http://chibios.svn.sourceforge.net/viewvc/chibios/trunk/demos/AVR-ATmega128-GCC/lcd.h?revision=219&view=markup)

I use this code for ad 2x16 display attached to an AVR micro in 4 bit mode, changing just the code for the I/O ports it should work for any micro, where you see chThdSleep() just insert a delay in milliseconds.

Note that the port is used in output mode only to make things easier, it works just fine.

regards,

Giovanni
