Continue to Site

Welcome to our site!

Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

  • Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

4-bit LCD

Status
Not open for further replies.

chandu13

New Member
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
 
Lcd

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
 
There is a required initialisation sequence that is required in order to get the LCD working. Your code doesn't have the required delays between the initialisation command. See any of the online examples of initiation code for the correct way to do it.

Mike.
 
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.
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.)
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);
}

Oh ya, by the way, when you post code here in the forum, PLEASE use Code tags. To do that, simply click on the # icon in the menu just before pasting your code. Alternately you can type [code] before pasting your source code and [/code] after it.

Code tags tell the forum software to leave your formatting alone. Keeps your source code nice looking and readable. People will actually look at readable code and help you. An unformatted mess, not so much. :p

I reformatted your source. Here's what it should have looked like:
Code:
#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++);
}
 
Last edited:
lcd_nybble

Hay

Thanks for reply
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);

Regards

chandu
 
When the display is initialising it only looks at the top 4 bits and if you have code that is written for 4 bit mode communication then you need a routine that just writes 4 bits for the initialisation sequence. If you use lcd_cmd then that will write the 2 nibbles as 2 separate values which will cause the initialisation to fail as a delay is required between the different nibbles.

Mike.
 
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);
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).
 
Aww crap! :( I wired up a 4-bit LCD and went to create a project for it in Crossworks. Much to my disgust, today is the day that my 30-day trial is over. And I can't order a personal license at their online store without signing a non-commercial form and emailing it and waiting.

So I'm installing the Keil demo to see how I like it. Maybe I'll look at IAR too.

EDIT: Keil, as far as I can tell, will not work with my Olimex ARM-USB-TINY. Dumped.

I'm wrestling with Eclipse/Yagarto again. I'm close, I think. I can compile and program the chip and debug the sample project, but not my own for some reason. My own will compile, but nothing else.

Programming and debugging is very slow in Eclipse, compared with Crossworks.
EDIT: Got it working better. Not so slow after all. Works ok.
 
Last edited:
In the code I have not understand the some code
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.

The interrupt stubs are there because the crt.s file wants them and I haven't figured out how to get rid of them yet. I'll end up using them soon anyway, so might just leave it.

These might not be perfect. I just got it working, so some things can almost certainly be improved.

**broken link removed**

My pinout is as follows. You'll have to mod the code to suit yours:
D4 = P0.17
D5 = P0.18
D6 = P0.19
D7 = P0.20
E = P0.21
RS = P0.22
and for the R/W busy flag checking code, R/W = P0.28

Scroll way down for the include file.

This first one uses delays - no busy checking.
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) ;	
}

---------------------------------------------

This one does busy checking. This way is better and usually faster, but takes one more pin (R/W) to do.:
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
	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) ;	
}

---------------------------------------------

And here is the lcd4bit.h include file. It works for both programs:
Code:
#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")));
Enjoy! :D

**broken link removed**
 
Last edited:
open source

Hay

Thank you for Reply, you are really open source
Presently I am making LPC2114 board with in soon I will dump your code in to the my board

Regards
chandu
 
8 bit LCD

Dear,


I am facing a problem with 4x20 line LCD interfacing with LPC2106.
I have modified your code and exicuted, 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 relevent program for 4x20 line LCD with LPC 2106.

Thank U

Prasad
 
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.
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.

There are some LCDs with different controllers though. Check if yours is 44780 or other.
 
Last edited:
4 line LCD

Dear,

Thanks for reply

I don't have controller details of LCD, but the LCD no. FDCC2004B, Fordata Ele. corp Ltd, china. I configured as 2 line LCD and used lines 1 & 3 as line 1, and lines 2 & 4 as line 2. The line addresses of 4-line LCD like 80,C0,94 and D4. Now it is responding but the data is not displaying properly, by default it is displaying on first line only. Even the changes of address, it is displaying on the first line only. can you send the LCD intialization code with LPC2106.

Prasad
 
I don't have controller details of LCD, but the LCD no. FDCC2004B, Fordata Ele. corp Ltd, china.
Then Google is your friend. Go get the details. :p Do a little research for yourself. It's not so difficult.

Can you send the LCD intialization code with LPC2106.
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.

I did find a 20x4 LCD here that I forgot I had. Maybe I'll find time later today to test with it and find out the details. If I do get around to it then my code will be posted (for 2148).
 
Last edited:
can you send the LCD initialization 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.

**broken link removed**

You should go over your wiring maybe. Make sure everything is connected correctly.

You ported the code to LPC2106 and a different pinout, so double and triple-check that you didn't make a mistake in the coding.

EDIT: Looked up your LCD. It uses the SPLC780D controller, not a 44780. I haven't looked through **broken link removed** much, but online people say it's at least partly compatible to the 44780.

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.
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.


**broken link removed**

Here's the test code that produced the photo above:
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!");
		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) ;	
}
 
Last edited:
Hello Futz,

I am trying LCD with two-wire as mentioned by Myke Predko.
I have suceeded till LCD Initialisation but facing problem for second line displaying.
Can you pls tell me how should i go further.

While Initialising i have written-
void LCD_init(void)
{
delay_5ms; //settle time delay
delay_5ms;
delay_5ms;
LCD_nybble(0x03,0); //reset LCD by sending 0x03 low nybble (binary 0011) three times
delay_5ms; //long delay after first one
LCD_nybble(0x03,0); //reset LCD by sending 0x03 low nybble (binary 0011) three times
delay_5ms; //long delay after first one
LCD_nybble(0x03,0); //reset LCD by sending 0x03 low nybble (binary 0011) three times
delay_5ms; //long delay after first one

LCD_nybble(0x02,0); //then send 0x02 low nybble (binary 0010)
delay_1ms();
LCD_cmd(0x28); //set 4-bit mode and 2 lines
delay_4us();
LCD_cmd(0x10); //cursor move & shift left
delay_4us();
LCD_cmd(0x06); //entry mode = increment
delay_4us();
LCD_cmd(0x0f); //display on - cursor blink on
delay_4us();
LCD_cmd(0x01); //clear display
delay_1ms();
// LCD_cmd(0x14); //clear display
// delay_1ms();
}


So, Initializes 2-line & 4-bit mode. but how i get cursor on second line.
I am using "HY-1602F6" (E258603) from SHENZHEN AV-diaplays Co. Ltd

Pls help me for seconh line display

Regards
Supri
 
Hello Futz,

I am trying LCD with two-wire as mentioned by Myke Predko & u.
I have suceeded till LCD Initialisation but facing problem for second line displaying.
Can you pls tell me how should i go further.

While Initialising i have written-
void LCD_init(void)
{
delay_5ms; //settle time delay
delay_5ms;
delay_5ms;
LCD_nybble(0x03,0); //reset LCD by sending 0x03 low nybble (binary 0011) three times
delay_5ms; //long delay after first one
LCD_nybble(0x03,0); //reset LCD by sending 0x03 low nybble (binary 0011) three times
delay_5ms; //long delay after first one
LCD_nybble(0x03,0); //reset LCD by sending 0x03 low nybble (binary 0011) three times
delay_5ms; //long delay after first one

LCD_nybble(0x02,0); //then send 0x02 low nybble (binary 0010)
delay_1ms();
LCD_cmd(0x28); //set 4-bit mode and 2 lines
delay_4us();
LCD_cmd(0x10); //cursor move & shift left
delay_4us();
LCD_cmd(0x06); //entry mode = increment
delay_4us();
LCD_cmd(0x0f); //display on - cursor blink on
delay_4us();
LCD_cmd(0x01); //clear display
delay_1ms();
// LCD_cmd(0x14); //clear display
// delay_1ms();
}


So, Initializes 2-line & 4-bit mode. but how i get cursor on second line.
I am using "HY-1602F6" (E258603) from SHENZHEN AV-diaplays Co. Ltd

Pls help me for seconh line display

Regards
Supri
 
LCD second line display problem

Hello Futz,

I am trying LCD with two-wire as mentioned by Myke Predko .
I have suceeded till LCD Initialisation but facing problem for second line displaying.
Can you pls tell me how should i go further.

While Initialising i have written-
void LCD_init(void)
{
delay_5ms; //settle time delay
delay_5ms;
delay_5ms;
LCD_nybble(0x03,0); //reset LCD by sending 0x03 low nybble (binary 0011) three times
delay_5ms; //long delay after first one
LCD_nybble(0x03,0); //reset LCD by sending 0x03 low nybble (binary 0011) three times
delay_5ms; //long delay after first one
LCD_nybble(0x03,0); //reset LCD by sending 0x03 low nybble (binary 0011) three times
delay_5ms; //long delay after first one

LCD_nybble(0x02,0); //then send 0x02 low nybble (binary 0010)
delay_1ms();
LCD_cmd(0x28); //set 4-bit mode and 2 lines
delay_4us();
LCD_cmd(0x10); //cursor move & shift left
delay_4us();
LCD_cmd(0x06); //entry mode = increment
delay_4us();
LCD_cmd(0x0f); //display on - cursor blink on
delay_4us();
LCD_cmd(0x01); //clear display
delay_1ms();
// LCD_cmd(0x14); //clear display
// delay_1ms();
}


So, Initializes 2-line & 4-bit mode. but how i get cursor on second line.
I am using "HY-1602F6" (E258603) from SHENZHEN AV-diaplays Co. Ltd

Pls help me for seconh line display

Regards
Supri
 
Hello Futz,

I am trying LCD with two-wire as mentioned by Myke Predko .
I have suceeded till LCD Initialisation but facing problem for second line displaying.
Can you pls tell me how should i go further.

While Initialising i have written-
void LCD_init(void)
{
delay_5ms; //settle time delay
delay_5ms;
delay_5ms;
LCD_nybble(0x03,0); //reset LCD by sending 0x03 low nybble (binary 0011) three times
delay_5ms; //long delay after first one
LCD_nybble(0x03,0); //reset LCD by sending 0x03 low nybble (binary 0011) three times
delay_5ms; //long delay after first one
LCD_nybble(0x03,0); //reset LCD by sending 0x03 low nybble (binary 0011) three times
delay_5ms; //long delay after first one

LCD_nybble(0x02,0); //then send 0x02 low nybble (binary 0010)
delay_1ms();
LCD_cmd(0x28); //set 4-bit mode and 2 lines
delay_4us();
LCD_cmd(0x10); //cursor move & shift left
delay_4us();
LCD_cmd(0x06); //entry mode = increment
delay_4us();
LCD_cmd(0x0f); //display on - cursor blink on
delay_4us();
LCD_cmd(0x01); //clear display
delay_1ms();
// LCD_cmd(0x14); //clear display
// delay_1ms();
}


So, Initializes 2-line & 4-bit mode. but how i get cursor on second line.
I am using "HY-1602F6" (E258603) from SHENZHEN AV-diaplays Co. Ltd

Pls help me for seconh line display

Regards
Supri
 
LCD second line display problem

Hello,

I am trying LCD with two-wire as mentioned by Myke Predko.
I have suceeded till LCD Initialisation but facing problem for second line displaying.
Can you pls tell me how should i go further.

While Initialising i have written-
void LCD_init(void)
{
delay_5ms; //settle time delay
delay_5ms;
delay_5ms;
LCD_nybble(0x03,0); //reset LCD by sending 0x03 low nybble (binary 0011) three times
delay_5ms; //long delay after first one
LCD_nybble(0x03,0); //reset LCD by sending 0x03 low nybble (binary 0011) three times
delay_5ms; //long delay after first one
LCD_nybble(0x03,0); //reset LCD by sending 0x03 low nybble (binary 0011) three times
delay_5ms; //long delay after first one

LCD_nybble(0x02,0); //then send 0x02 low nybble (binary 0010)
delay_1ms();
LCD_cmd(0x28); //set 4-bit mode and 2 lines
delay_4us();
LCD_cmd(0x10); //cursor move & shift left
delay_4us();
LCD_cmd(0x06); //entry mode = increment
delay_4us();
LCD_cmd(0x0f); //display on - cursor blink on
delay_4us();
LCD_cmd(0x01); //clear display
delay_1ms();
// LCD_cmd(0x14); //clear display
// delay_1ms();
}


So, Initializes 2-line & 4-bit mode. but how i get cursor on second line.
I am using "HY-1602F6" (E258603) from SHENZHEN AV-diaplays Co. Ltd

Pls help me for seconh line display

Regards
Supri
 
Status
Not open for further replies.

Latest threads

Back
Top