Hey Chandu. What you need is an LCD initialize function something like this one that I use on my LPC2148 (and many other MCUs, like PICs, AVRs, etc.)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.
void lcd_init(void)
{
delay_ms(500); //settle time delay
lcd_nybble(0x03,0); //reset LCD by sending 0x03 low nybble (binary 0011) three times
delay_ms(5); //long delay after first one
strobe_e();
delay_us(160); //short delays after that
strobe_e();
delay_us(160);
lcd_nybble(0x02,0); //then send 0x02 low nybble (binary 0010)
delay_us(160);
lcd_cmd(0x28); //set 4-bit mode and 2 lines
delay_us(160);
lcd_cmd(0x10); //cursor move & shift left
delay_us(160);
lcd_cmd(0x06); //entry mode = increment
delay_us(160);
lcd_cmd(0x0e); //display on - cursor blink on
delay_us(160);
lcd_cmd(0x01); //clear display
delay_us(160);
}
#include"LPC210x.H"
void delay(void);
void lcdcmd(unsigned char);
void lcddata(unsigned char);
#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
int main(void)
{
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);
}
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 delay(void)
{
unsigned int i;
for(i=0;i<=20000;i++);
}
I could give you the code, but it might not make total sense to you as I wrote it for the Myke Predko 2-wire LCD circuit. Actually, it's on **broken link removed**. Have a look. If that confuses you leave a post here and I'll wire up a 4-bit LCD to my LPC2148 and port some demo code over (or just modify my 2-wire code).In the code I have not understand the some code
What is the difference between lcd_nybble (0x02, 0); & lcd_cmd (0x28);
For commands and Data I can use lcd_cmd (0x28) or lcd_data (0x28) then what is the use of lcd_nybble (0x02, 0);
Hey Chandu. Here is complete working 4-bit LCD code for both delays-operation and for R/W busy flag operation. It's for LPC2148, but LPC2106 won't need many changes.In the code I have not understand the some code
#include "LPC214x.h"
#include "lcd4bit.h"
int main(void)
{
clkinit();
PINSEL0 = 0x00000000;
IODIR0 = 0x107e0000;
IOCLR0 = 0x107e0000;
lcd_init();
while(1){
lcd_line1();
lcd_string("LPC2148 LCD");
delay_ms(1000);
lcd_line2();
lcd_string("It works!");
delay_ms(1000);
}
}
void lcd_string(char *senpoint)
{
while(*senpoint != '\0')
{
lcd_char(*senpoint);
senpoint++;
}
}
void lcd_line1(void)
{
lcd_cmd(0x80);
}
void lcd_line2(void)
{
lcd_cmd(0xc0);
}
void lcd_cmd(unsigned char letter)
{
unsigned char temp;
temp=letter;
temp=temp>>4;
lcd_nybble(temp,0);
temp=letter;
temp=temp&0x0f;
lcd_nybble(temp,0);
}
void lcd_char(unsigned char letter)
{
unsigned char temp;
temp=letter;
temp=temp>>4;
lcd_nybble(temp,1);
temp=letter;
temp=temp&0x0f;
lcd_nybble(temp,1);
}
void lcd_nybble(unsigned char nyb,unsigned char rs)
{
int i,dat;
if(rs)
IOSET0 |= RS; //set RS pin
else
IOCLR0 |= RS; //clear RS pin
dat = nyb; //get the nybble in an int
IOCLR0 = 0x001e0000; //clear D4-D7
IOPIN0 |= dat<<17; //OR the bits in there
strobe_e(); //latch data to LCD
}
void lcd_init(void)
{
delay_ms(500); //settle time delay
lcd_nybble(0x03,0); //reset LCD
delay_ms(5);
strobe_e();
delay_us(160);
strobe_e();
delay_us(160);
lcd_nybble(0x02,0);
delay_us(160);
lcd_cmd(0x28); //set 4-bit mode and 2 lines
delay_us(160);
lcd_cmd(0x10); //cursor move & shift left
delay_us(160);
lcd_cmd(0x06); //entry mode = increment
delay_us(160);
lcd_cmd(0x0e); //display on - cursor blink on
delay_us(160);
lcd_cmd(0x01); //clear display
delay_ms(40);
}
void strobe_e(void)
{
IOSET0 |= E;
delay_us(1);
IOCLR0 |= E;
delay_us(160);
}
void delay_ms(int x)
{
int a,b;
for(a=0;a<x;a++){
for(b=0;b<3500;b++);
}
}
void delay_us(int x)
{
int a,b;
for(a=0;a<x;a++){
for(b=0;b<4;b++);
}
}
void clkinit(void)
{
PLLCFG=0x24; //set multiplier and divider values for 60MHz
PLLFEED=0xAA; //with 12MHz crystal
PLLFEED=0x55;
PLLCON=0x01; //enable PLL
PLLFEED=0xAA;
PLLFEED=0x55;
while(!(PLLSTAT & PLOCK)); //wait for PLL to lock to set frequency
PLLCON=0x3; //connect PLL as clock source
PLLFEED=0xAA;
PLLFEED=0x55;
MAMCR=0x02; //enable MAM
MAMTIM=0x04; //set number of clocks used for flash memory fetch
VPBDIV=0x01; //set peripheral clock (pclk) to system clock (cclk)
}
/* Stubs for various interrupts (may be replaced later) */
/* ---------------------------------------------------- */
void IRQ_Routine (void) {
while (1) ;
}
void FIQ_Routine (void) {
while (1) ;
}
void SWI_Routine (void) {
while (1) ;
}
void UNDEF_Routine (void) {
while (1) ;
}
#include "LPC214x.h"
#include "lcd4bit.h"
int main(void)
{
clkinit();
PINSEL0 = 0x00000000;
IODIR0 = 0x107e0000;
IOCLR0 = 0x107e0000;
lcd_init();
while(1){
lcd_line1();
lcd_string("LPC2148 LCD");
delay_ms(1000);
lcd_line2();
lcd_string("It works!");
delay_ms(1000);
}
}
void lcd_string(char *senpoint)
{
while(*senpoint != '\0')
{
lcd_char(*senpoint);
senpoint++;
}
}
void lcd_line1(void)
{
lcd_cmd(0x80);
}
void lcd_line2(void)
{
lcd_cmd(0xc0);
}
void lcd_cmd(unsigned char letter)
{
unsigned char temp;
temp=letter;
temp=temp>>4;
lcd_nybble(temp,0);
temp=letter;
temp=temp&0x0f;
lcd_nybble(temp,0);
}
void lcd_char(unsigned char letter)
{
unsigned char temp;
temp=letter;
temp=temp>>4;
lcd_nybble(temp,1);
temp=letter;
temp=temp&0x0f;
lcd_nybble(temp,1);
}
void lcd_nybble(unsigned char nyb,unsigned char rs)
{
int i,dat;
if(rs)
IOSET0 |= RS; //set RS pin
else
IOCLR0 |= RS; //clear RS pin
dat = nyb; //get the nybble in an int
IOCLR0 = 0x001e0000; //clear D4-D7
IOPIN0 |= dat<<17; //OR the bits in there
strobe_e(); //latch data to LCD
}
void lcd_init(void)
{
delay_ms(500); //settle time delay
lcd_nybble(0x03,0); //reset LCD
strobe_e();
strobe_e();
lcd_nybble(0x02,0);
lcd_cmd(0x28); //set 4-bit mode and 2 lines
lcd_cmd(0x10); //cursor move & shift left
lcd_cmd(0x06); //entry mode = increment
lcd_cmd(0x0e); //display on - cursor blink on
lcd_cmd(0x01); //clear display
}
void lcd_busy(void)
{
IODIR0 = 0x106e0000; //D7 is input
IOCLR0 |= RS; //set RS low
IOSET0 |= RW; //set R/W high
IOSET0 |= E; //set E high
while(IOPIN0 & busyflag); //wait for busy flag to go low
IOCLR0 |= E; //set E low
IOCLR0 |= RW; //set R/W low
IODIR0 = 0x107e0000; //D7 is output again
}
void strobe_e(void)
{
IOSET0 |= E;
delay_us(1);
IOCLR0 |= E;
lcd_busy();
}
void delay_ms(int x)
{
int a,b;
for(a=0;a<x;a++){
for(b=0;b<3500;b++);
}
}
void delay_us(int x)
{
int a,b;
for(a=0;a<x;a++){
for(b=0;b<4;b++);
}
}
void clkinit(void)
{
PLLCFG=0x24; //set multiplier and divider values
PLLFEED=0xAA;
PLLFEED=0x55;
PLLCON=0x01; //enable PLL
PLLFEED=0xAA;
PLLFEED=0x55;
while(!(PLLSTAT & PLOCK)); //wait for PLL to lock to set frequency
PLLCON=0x3; //connect PLL as clock source
PLLFEED=0xAA;
PLLFEED=0x55;
MAMCR=0x02; //enable MAM
MAMTIM=0x04; //set number of clocks used for flash memory fetch
VPBDIV=0x01; //set peripheral clock (pclk) to system clock (cclk)
}
/* Stubs for various interrupts (may be replaced later) */
/* ---------------------------------------------------- */
void IRQ_Routine (void) {
while (1) ;
}
void FIQ_Routine (void) {
while (1) ;
}
void SWI_Routine (void) {
while (1) ;
}
void UNDEF_Routine (void) {
while (1) ;
}
#define PLOCK 0x400
#define E 0x00200000 //bit 21
#define RS 0x00400000 //bit 22
#define RW 0x10000000 //bit 28
#define busyflag 0x00100000 //D7 - bit 20
void clkinit(void);
void lcd_string(char *);
void lcd_line1(void);
void lcd_line2(void);
void lcd_cmd(unsigned char);
void lcd_char(unsigned char);
void lcd_nybble(unsigned char,unsigned char);
void lcd_init(void);
void strobe_e(void);
void delay_ms(int);
void delay_us(int);
void IRQ_Routine (void) __attribute__ ((interrupt("IRQ")));
void FIQ_Routine (void) __attribute__ ((interrupt("FIQ")));
void SWI_Routine (void) __attribute__ ((interrupt("SWI")));
void UNDEF_Routine (void) __attribute__ ((interrupt("UNDEF")));
Your 4x20 has a 44780 controller? If so, that init should at least get something displaying, though it might need tweaking for a 4x20. I don't have a 4x20 to check with, but I gather they can be configured as 2 line and use lines 1 & 3 as line 1, and lines 2 & 4 as line 2. Or they can be configured as 4 line. But don't quote me on that. I'm partly guessing and going partly from foggy memory. Look at this thread.I am facing a problem with 4x20 line LCD interfacing with LPC2106.
I have modified your code and executed, but i am getting a problem in initialization of the LCD. Is there any different initializations between the 4x20 line LCD and 2x16 line LCD. Can you send me the relavent program for 4x20 line LCD with LPC 2106.
Then Google is your friend. Go get the details.I don't have controller details of LCD, but the LCD no. FDCC2004B, Fordata Ele. corp Ltd, china.
No. First, the code is presented as is. Do whatever you want with it. If it helps you that's great, but I'm not writing code to order for you. Second, I don't have a LPC2106 - only a LPC2148.Can you send the LCD intialization code with LPC2106.
Hey Prasad. Plugged my 20x4 LCD into the same circuit as the 16x2. Everything works normally. The 44780 controller is identical, so the initialization routine is also identical.can you send the LCD initialization code with LPC2106.
Sure, 2 different controllers that are both 'equiv to the 44780'. In other words, they'll mount the same, most likely initialize the same, and except for the different in the number of lines, operate the same.Thanks skimask. the 1x8 uses a KS0066U controller, and the 2x8 uses a SPLC780D. The supplier said both were "equivalent to the 44780". I picked them to get some experince with the two different controllers. I figured it was a good way to learn.
#include "LPC214x.h"
#include "lcd4bit.h"
int main(void)
{
clkinit();
PINSEL0 = 0x00000000;
IODIR0 = 0x107e0000;
IOCLR0 = 0x107e0000;
lcd_init();
while(1){
lcd_line1();
lcd_string("LPC2148 LCD");
delay_ms(1000);
lcd_line2();
lcd_string("It works!");
lcd_line3();
lcd_string("Line 3 here.");
lcd_line4();
lcd_string("Here is line 4!");
delay_ms(1000);
}
}
void lcd_string(char *senpoint)
{
while(*senpoint != '\0')
{
lcd_char(*senpoint);
senpoint++;
}
}
void lcd_line1(void)
{
lcd_cmd(0x80);
}
void lcd_line2(void)
{
lcd_cmd(0xc0);
}
void lcd_line3(void)
{
lcd_cmd(0x94);
}
void lcd_line4(void)
{
lcd_cmd(0xd4);
}
void lcd_cmd(unsigned char letter)
{
unsigned char temp;
temp=letter;
temp=temp>>4;
lcd_nybble(temp,0);
temp=letter;
temp=temp&0x0f;
lcd_nybble(temp,0);
}
void lcd_char(unsigned char letter)
{
unsigned char temp;
temp=letter;
temp=temp>>4;
lcd_nybble(temp,1);
temp=letter;
temp=temp&0x0f;
lcd_nybble(temp,1);
}
void lcd_nybble(unsigned char nyb,unsigned char rs)
{
int i,dat;
if(rs)
IOSET0 |= RS; //set RS pin
else
IOCLR0 |= RS; //clear RS pin
dat = nyb; //get the nybble in an int
IOCLR0 = 0x001e0000; //clear D4-D7
IOPIN0 |= dat<<17; //OR the bits in there
strobe_e(); //latch data to LCD
}
void lcd_init(void)
{
delay_ms(500); //settle time delay
lcd_nybble(0x03,0); //reset LCD
delay_ms(5);
strobe_e();
delay_us(160);
strobe_e();
delay_us(160);
lcd_nybble(0x02,0);
delay_us(160);
lcd_cmd(0x28); //set 4-bit mode and 2 lines
delay_us(160);
lcd_cmd(0x10); //cursor move & shift left
delay_us(160);
lcd_cmd(0x06); //entry mode = increment
delay_us(160);
lcd_cmd(0x0e); //display on - cursor blink on
delay_us(160);
lcd_cmd(0x01); //clear display
delay_ms(40);
}
void strobe_e(void)
{
IOSET0 |= E;
delay_us(1);
IOCLR0 |= E;
delay_us(160);
}
void delay_ms(int x)
{
int a,b;
for(a=0;a<x;a++){
for(b=0;b<3500;b++);
}
}
void delay_us(int x)
{
int a,b;
for(a=0;a<x;a++){
for(b=0;b<4;b++);
}
}
void clkinit(void)
{
PLLCFG=0x24; //set multiplier and divider values
PLLFEED=0xAA;
PLLFEED=0x55;
PLLCON=0x01; //enable PLL
PLLFEED=0xAA;
PLLFEED=0x55;
while(!(PLLSTAT & PLOCK)); //wait for PLL to lock to set frequency
PLLCON=0x3; //connect PLL as clock source
PLLFEED=0xAA;
PLLFEED=0x55;
MAMCR=0x02; //enable MAM
MAMTIM=0x04; //set number of clocks used for flash memory fetch
VPBDIV=0x01; //set peripheral clock (pclk) to system clock (cclk)
}
/* Stubs for various interrupts (may be replaced later) */
/* ---------------------------------------------------- */
void IRQ_Routine (void) {
while (1) ;
}
void FIQ_Routine (void) {
while (1) ;
}
void SWI_Routine (void) {
while (1) ;
}
void UNDEF_Routine (void) {
while (1) ;
}
We use cookies and similar technologies for the following purposes:
Do you accept cookies and these technologies?
We use cookies and similar technologies for the following purposes:
Do you accept cookies and these technologies?