richardlaishram
Member level 4
- Joined
- Jan 6, 2013
- Messages
- 77
- Helped
- 6
- Reputation
- 12
- Reaction score
- 6
- Trophy points
- 1,298
- Location
- Planet Earth
- Activity points
- 1,804
I have edited an old 8051 LCD Program for LPC2124 which is not working. Since I'm new to ARM programming I'm not able to rectify it. I have also attached a simulation file (Proteus) as pdf (since I'm not able to upload the DSN file directly) in case it'll be helpful.
#include<lpc21xx.h>
//delay function in msec
void delay(unsigned int msec)
{
int i,j;
for(i=0;i<msec;i++)
for(j=0;j<1275;j++);
}
// Function to send command to LCD
void lcdcmd(unsigned char data)
{
data<<=17; // P1.17 to P1.24 as Data Pins
IOPIN1 = data; // Read current status of Pins
IOSET1 = data;
IOCLR0 = 0x00000010; // P0.4 as RS
IOCLR0 = 0x00000020; // P0.5 as RW
IOSET0 = 0x00000040; // P0.6 as E
delay(1);
IOCLR0 = 0x00000040; // P0.6 as E
return;
}
// Function to send data to LCD
void lcddata(unsigned char data)
{
data<<=17; // P1.17 to P1.24 as Data Pins
IOPIN1 = data; // Read current status of Pins
IOSET1 = data;
IOSET0 = 0x00000010; // P0.4 as RS
IOCLR0 = 0x00000020; // P0.5 as RW
IOSET0 = 0x00000040; // P0.6 as E
delay(1);
IOCLR0 = 0x00000040; // P0.6 as E
return;
}
//send string to LCD
void lcddatastring(unsigned char *str)
{
int i=0;
while(str!='\0')
{
lcddata(str);
i++;
delay(1);
}
return;
}
void lcdinit()
{
lcdcmd(0x00380000); // 2-line 5x7 matrix
delay(2);
lcdcmd(0x000C0000); // Display ON, Cursor Blink
delay(2);
lcdcmd(0x00010000); // Clear Screen
delay(2);
lcdcmd(0x00810000); // Cursor to first position of the first line
delay(2);
}
int main(void)
{
IODIR0&=0xFFFFFFFF; // Port-0 as Output Pins
IODIR1&=0xFFFF0000; // Port-1 17-32 as Output Pins
lcdinit();
lcddatastring("Trial Program");
while(1);
}