nitinpatil
Member level 1
- Joined
- Oct 29, 2012
- Messages
- 41
- Helped
- 1
- Reputation
- 2
- Reaction score
- 1
- Trophy points
- 1,288
- Location
- Pune, Maharashtra, India
- Activity points
- 1,557
#include<LPC213X.h>
void delay()
{
int i;
for(i=0;i<900000;i++);
}
void DAT(unsigned char data)
{
IOCLR1 = 0X00FF0000; // port 1.16 to 1.23
IOSET0 = 0X10000000;
IOSET0 = 0X20000000; // port 0.28 to 0.29
IOSET1 = data<<16;
delay();
IOCLR0 = 0x20000000;
}
void CMD(unsigned int cmd)
{
IOCLR1 = 0X00FF0000;
IOCLR0 = 0X10000000;
IOSET0 = 0x20000000;
IOSET1 = cmd<<16;
delay();
IOCLR0 = 0x20000000;
}
int main(void)
{
IODIR1 = 0X00FF0000;
IODIR0 = 0X30000000;
CMD(0X38);
delay();
CMD(0X0C);
delay();
CMD(0X01);
delay();
CMD(0X0E);
delay();
CMD(0X06);
delay();
CMD(0X80);
delay();
DAT('A');
delay();
DAT('B');
delay();
return 0;
}
This is not a direct answer to your qu ! I hv to go through many things for that
But here is a trick :
You can see the sample code for lcd interface in your c:/keil folder, further you can download 'code bundle' for LPC2138(NXP website) to get starting with LCD or any supported peripherals for that matter.
Just modify sourcecode accordingly for your use.
#include <LPC21xx.H>
#include <stdio.h>
void delay( )
{
unsigned int i;
for(i=0;i<4000;i++);
}
void lcddata(unsigned char c)
{
IOCLR1=0x00ff0000; // output p1.16 to p1.24
IOSET0=0x00000001; // rs =1 p0.0
IOCLR0=0x00000002; // rw =0 p0.1
IOSET0=0x00000004; // en=1 p0.2
IOSET1 = c<<16;
delay();
IOCLR0=0x00000004; //en=0 p0.2
}
void lcdcmd(int c)
{
IOCLR1=0x00ff0000;
IOCLR0=0x00000001; // rs =0 p0.0
IOCLR0=0x00000002; // rw =0 p0.1
IOSET0=0x00000004; // en=1 p0.2
IOSET1 = c<<16;
delay();
IOCLR0=0x00000004; //en=0 p0.2
}
void lcdinit()
{
lcdcmd(0x38);
delay();
lcdcmd(0x0e);
delay();
lcdcmd(0x06);
delay();
lcdcmd(0x80);
delay();
}
void lcdputs(const char * s)
{
while(*s)
lcddata(*s++);
}
#include <LPC21xx.H>
#include <stdio.h>
void delay( )
{
unsigned int i;
for(i=0;i<4000;i++);
}
void lcddata(unsigned char c)
{
IOCLR1=0x00ff0000; // output p1.16 to p1.24
IOSET0=0x00000001; // rs =1 p0.0
IOCLR0=0x00000002; // rw =0 p0.1
IOSET0=0x00000004; // en=1 p0.2
IOSET1 = c<<16;
delay();
IOCLR0=0x00000004; //en=0 p0.2
}
void lcdcmd(int c)
{
IOCLR1=0x00ff0000;
IOCLR0=0x00000001; // rs =0 p0.0
IOCLR0=0x00000002; // rw =0 p0.1
IOSET0=0x00000004; // en=1 p0.2
IOSET1 = c<<16;
delay();
IOCLR0=0x00000004; //en=0 p0.2
}
void lcdinit()
{
lcdcmd(0x38);
delay();
lcdcmd(0x0e);
delay();
lcdcmd(0x06);
delay();
lcdcmd(0x80);
delay();
}
void lcdputs(const char * s)
{
while(*s)
lcddata(*s++);
}
#include <LPC21xx.H>
#include <stdio.h>
void delay( )
{
unsigned int i;
for(i=0;i<4000;i++);
}
void lcddata(unsigned char c)
{
IOCLR1=0x00ff0000; // output p1.16 to p1.24
IOSET0=0x00000001; // rs =1 p0.0
IOCLR0=0x00000002; // rw =0 p0.1
IOSET0=0x00000004; // en=1 p0.2
IOSET1 = c<<16;
delay();
IOCLR0=0x00000004; //en=0 p0.2
}
void lcdcmd(int c)
{
IOCLR1=0x00ff0000;
IOCLR0=0x00000001; // rs =0 p0.0
IOCLR0=0x00000002; // rw =0 p0.1
IOSET0=0x00000004; // en=1 p0.2
IOSET1 = c<<16;
delay();
IOCLR0=0x00000004; //en=0 p0.2
}
void lcdinit()
{
lcdcmd(0x38);
delay();
lcdcmd(0x0e);
delay();
lcdcmd(0x06);
delay();
lcdcmd(0x83);
delay();
lcddata('W');
delay();
}
Here again I upload my code by giving a reference of you code find the bug in this code. because its not working,
And I did the connection as per your requirement
Now i upload the connection dig and also the code try this is in your proteus for better debugging purpose
View attachment 83481Code:#include <LPC21xx.H> #include <stdio.h> void delay( ) { unsigned int i; for(i=0;i<4000;i++); } void lcddata(unsigned char c) { IOCLR1=0x00ff0000; // output p1.16 to p1.24 IOSET0=0x00000001; // rs =1 p0.0 IOCLR0=0x00000002; // rw =0 p0.1 IOSET0=0x00000004; // en=1 p0.2 IOSET1 = c<<16; delay(); IOCLR0=0x00000004; //en=0 p0.2 } void lcdcmd(int c) { IOCLR1=0x00ff0000; IOCLR0=0x00000001; // rs =0 p0.0 IOCLR0=0x00000002; // rw =0 p0.1 IOSET0=0x00000004; // en=1 p0.2 IOSET1 = c<<16; delay(); IOCLR0=0x00000004; //en=0 p0.2 } void lcdinit() { lcdcmd(0x38); delay(); lcdcmd(0x0e); delay(); lcdcmd(0x06); delay(); lcdcmd(0x83); delay(); lcddata('W'); delay(); }
void lcdinit()
{
void lcdinit()
{
lcdcmd(0x38);
delay();
lcdcmd(0x0e);
delay();
lcdcmd(0x06);
delay();
lcdcmd(0x80);
delay();
}
void main(void)
{
IODIR1 = 0X00FF0000;
IODIR0 = 0X00000007;
lcdinit();
}
Sorry I forgot to send main function
here it is...
Code:void main(void) { IODIR1 = 0X00FF0000; IODIR0 = 0X00000007; lcdinit(); }
int main(void)
{
while(1)
{
/*code for lcd print*/
PINSEL0=0X00000000; // gpio pin 0.0 to 0.15
PINSEL2=0X00000000; // gpio pin 1.16 to 1.31
IODIR0=0X00000007; //p0.0 rs p0.1 r/w p0.2 e
IODIR1=0X00ff0000; //p1.16 to p1.24 output
lcdinit();
sprintf (buffer, "lcd display: %x", display); // to display the data
lcdputs(buffer);
}
cd.c(55): warning: #223-D: function "sprintf" declared implicitly
lcd.c(56): warning: #223-D: function "lcdputs" declared implicitly
lcd.c(62): warning: #1-D: last line of file ends without a newline
linking...
LCD.axf: Error: L6218E: Undefined symbol lcdputs (referred from lcd.o).
Target not created
@ kodi.sundar...
I tried the code you posted but it the code is not compile giving error like..
/* write a string of chars to the LCD */
void lcdputs (const char * s)
{
while(*s)
lcd_data(*s++);
}
#include <stdio.h>
char buffer [21]; // Set size to LCD width plus one null
sprintf (buffer, "lcd display: %x", display); // to display the data
lcdputs(buffer);
sprintf (buffer, "lcd display: %x", 'd'); // to display the data
lcdputs(buffer);
Hey friend i tried your code, its compiled successfully but it not work in proteus, this LCD just blink continuously not display anything.
I change format specifier %x to %u, change signed to unsigned and const also but it strikes on the same issueCode:sprintf (buffer, "lcd display: %x", 'd'); // to display the data lcdputs(buffer);
I did so many programs on actual hardware for LCD but I want to go for some big project but as soon as I not check on proteus how can i go to hardware directly it may be costly and deterministic output...
Help me ... !!! :-(
#include<LPC213X.h>
void delay()
{
int i;
for(i=0;i<900000;i++);
}
void DAT(unsigned char data)
{
IOCLR1 = 0X00FF0000; // port 1.16 to 1.23
IOSET0 = 0X00000001;
IOCLR0 = 0x00000002;
IOSET0 = 0X00000004; // port 0.28 to 0.29
IOSET1 = data<<16;
delay();
IOCLR0 = 0x00000004;
}
void CMD(unsigned int cmd)
{
IOCLR1 = 0X00FF0000;
IOCLR0 = 0X00000001;
IOCLR0 = 0x00000002;
IOSET0 = 0x00000004;
IOSET1 = cmd<<16;
delay();
IOCLR0 = 0x00000004;
}
void lcdputs (const char *s)
{
while(*s)
DAT(*s++);
}
int main(void)
{
char buffer [21];
PINSEL0 = 0X00000000;
PINSEL1 = 0X00000000;
IODIR1 = 0X00FF0000;
IODIR0 = 0X00000007;
CMD(0x38);
delay();
CMD(0x0e);
delay();
CMD(0x06);
delay();
CMD(0x80);
delay();
sprintf (buffer, "lcd display: %x", 'd'); // to display the data
lcdputs(buffer);
return 0;
}
Here is full code...
Code:#include<LPC213X.h> void delay() { int i; for(i=0;i<900000;i++); } void DAT(unsigned char data) { IOCLR1 = 0X00FF0000; // port 1.16 to 1.23 IOSET0 = 0X00000001; IOCLR0 = 0x00000002; IOSET0 = 0X00000004; // port 0.28 to 0.29 IOSET1 = data<<16; delay(); IOCLR0 = 0x00000004; } void CMD(unsigned int cmd) { IOCLR1 = 0X00FF0000; IOCLR0 = 0X00000001; IOCLR0 = 0x00000002; IOSET0 = 0x00000004; IOSET1 = cmd<<16; delay(); IOCLR0 = 0x00000004; } void lcdputs (const char *s) { while(*s) DAT(*s++); } int main(void) { char buffer [21]; PINSEL0 = 0X00000000; PINSEL1 = 0X00000000; IODIR1 = 0X00FF0000; IODIR0 = 0X00000007; CMD(0x38); delay(); CMD(0x0e); delay(); CMD(0x06); delay(); CMD(0x80); delay(); sprintf (buffer, "lcd display: %x", 'd'); // to display the data lcdputs(buffer); return 0; }
void lcdputs (unsigned char *s)
{
while(*s)
{
DAT(*s++);
}
}
lcdputs("welcome");
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?