pavan_85
Member level 1
Hi all,
I wanted to write a code for 4-bit mode LCD(16x2) using LPC 2114 Microcontroller.
I am unable to figure out what went wrong. please go through my code and help me out.
The code which i wrote worked quite well using AT89c52(not the syntax, but the concept...)
Please do the needful.....
pavan
I wanted to write a code for 4-bit mode LCD(16x2) using LPC 2114 Microcontroller.
I am unable to figure out what went wrong. please go through my code and help me out.
The code which i wrote worked quite well using AT89c52(not the syntax, but the concept...)
Code:
//D4 - p1.31; D5 - p1.30; D6 - p1.29; D7 - p1.28; RS - p1.27; EN - p1.26
#include <lpc21xx.h>
#include <stdio.h>
#define RS 0X08000000;
#define EN 0x04000000;
void LCD_INIT (void );
void LCD_CMD (unsigned char );
void LCD_DATA (unsigned char );
void LCD_DISPLAY(unsigned char *);
void delay (unsigned int );
int main(void)
{
//configuring ports p1.31-p1.26 as outputs
PINSEL2 = 0x00000030;
IO1DIR = 0xFF000000;
LCD_INIT();
LCD_CMD(0x80);
LCD_DISPLAY("Jai Hanuman");
return 0;
}
void LCD_INIT()
{
LCD_CMD(0x33);
delay(25);
LCD_CMD(0x32);
delay(25);
LCD_CMD(0x28);
delay(25);
LCD_CMD(0x0E);
delay(25);
LCD_CMD(0x06);
delay(25);
LCD_CMD(0x01);
delay(25);
}
void LCD_CMD(unsigned char value)
{
unsigned long val,val_1;
val = val_1 = value;
val = value << 24;
val_1 = value << 28;
IO1CLR |= RS;
IO1SET |= val&0xF0000000;
IO1SET |= EN;
delay(1);
IO1CLR |= EN;
IO1CLR = 0xF0000000;
IO1SET |= val_1&0xF0000000;
IO1SET |= EN;
delay(1);
IO1CLR |= EN;
}
void LCD_DATA(unsigned char value)
{
unsigned long val,val_1;
val = val_1 = value;
val = value << 24;
val_1 = value << 28;
IO1SET |= RS;
IO1SET |= val&0xF0000000;
IO1SET |= EN;
delay(1);
IO1CLR |= EN;
IO1CLR = 0xF0000000;
IO1SET |= val_1&0xF0000000;
IO1SET |= EN;
delay(1);
IO1CLR |= EN;
}
void LCD_DISPLAY(unsigned char *take)
{
while(*take)
{
LCD_DATA(*take++);
}
}
void delay(unsigned int it)
{
int i,j;
for(i=0;i<it;i++)
for(j=0;j<1000;j++);
}
Please do the needful.....
pavan