Hi i am working on ARM 2138 and trying to interface a 16*2 LCD in 4bit mode. please help me with the same. i cant get the output. some problem in the code. please help!! RS connected to P1.24, enable at P0.7, RW is grounded in my circuit. The data lines are D7- P0.3 , D6- P0.4 , D5-P0.5 , D4-P0.6
#include”lpc213x.h” #include
#define EN (1<<7) #define RS (1<PS-Primer 2148<"}; unsigned char msg1[]= {":: LCD Demo! ::"};
int main() { PINSEL2 = 0; PINSEL0 = 0; IODIR0 = 0x00000078; IODIR1 = 0x01000000; lcd_initialise(); lcd_display(); return 0; }
void lcd_initialise(void) {
int i=0; lcd_convert(0x30); lcd_delay(16); lcd_convert(0x30); lcd_delay(16); lcd_convert(0x30); lcd_delay(16); lcd_convert(0x20); lcd_delay(16);
for(i=0;i<4;i++) { IOCLR0 = 0xF << 3; lcd_cmd(cmd[i]); lcd_delay(15);
}
void lcd_cmd(unsigned char data) { IOCLR1 |= RS; //RS lcd_convert(data); }
void lcd_delay(unsigned int n) { unsigned int i,j; for(i=0;i<n;i++) for(j=0;j<12000;j++); }
void lcd_display (void) { int i=0,j=0; /* first line message */ lcd_cmd(0x80); lcd_delay(15);
while(msg[i]!='')
{ lcd_delay(15); lcd_data(msg[i]); i++; }
lcd_delay(15); /* second line message */ lcd_cmd(0xc0); lcd_delay(15);
while(msg1[j]!='')
{ lcd_delay(5); lcd_data(msg1[j]); j++; }
lcd_delay(15); }
void lcd_convert(char c) {
if(c & 0x08) IOSET0 = 1 << 3; else IOCLR0 = 1 << 3; if(c & 0x04) IOSET0 = 1 << 4; else IOCLR0 = 1 << 4; if(c & 0x02) IOSET0 = 1 << 5; else IOCLR0 = 1 << 5; if(c & 0x01) IOSET0 = 1 << 6; else IOCLR0 = 1 << 6;
IOSET0 = EN; lcd_delay(15); IOCLR0 = EN; lcd_delay(15);
if(c & 0x80) IOSET0 = 1 << 3; else IOCLR0 = 1 << 3; if(c & 0x40) IOSET0 = 1 << 4; else IOCLR0 = 1 << 4; if(c & 0x20) IOSET0 = 1 << 5; else IOCLR0 = 1 << 5; if(c & 0x10) IOSET0 = 1 << 6; else IOCLR0 = 1 << 6;
void lcd_data (unsigned char data) { IOSET1 |= RS; //0x1000; //RS lcd_convert(data); }
The web is full of for loop delays, because beginners always thinks they are the easiest way. And they - when they work, which they quite often doesn't. The language standard or the chip manufacturer or the compiler vendor does not have any paragraph where they claim that they guarantee a for loop delay to give any expected delay time. But lots of people feel fine to program making huge assumptions with trial-and-error designs.
So in the end - the most common solution you find on the net need not be the best. Or even good. Especially since the majority of code available on the net has been published by beginners - not too many professional developers spends any time posting what they consider trivial code.
thank you :)