/*LCD
Count value display */
/*Connections from LPC2148 to LCD Module:
P0.0 to P0.7 used as Data bits.
P1.16 connected to pin4 i.e. RS - Command / Data
P1.17 connected to pin6 i.e. E - Enable
Pin5 of LCD Module i.e. 'R/W' connected to
ground
*/
#include<lpc213x.h> /*header file
to be included*/
void initLCD(void);
void enable(void);
void LCD_WriteChar(char c);
void LCD_WriteString(char * string);
void LCD_Cmd(unsigned int cmd);
void delay(void);
{
int i,j,k=0,l,m; /*initializing the variables*/
while(1)
{
k=0;
initLCD();
for(i=0;i<=200;i++)
{
if(i<10)
/* if the value is from 1 to 9*/
{
l=i+48; /* ASCII value Addition*/
LCD_WriteChar(l);
LCD_Cmd(0x80);
k++;
}
else
if((i>=10)&&(i<100)) /* if the value from 10 to 99*/
{
j=i/10;
j=j+48; /*ASCII value Addition*/
LCD_WriteChar(j);
k++;
j=i%10;
j=j+48;
LCD_WriteChar(j);
LCD_Cmd(0x80);
k++;
}
else
if(i>=100) /* if the value from 100 to 199*/
{
j=i/100;
j=j+48; /*ASCII value Addition*/
LCD_WriteChar(j);
m=i/10;
l=m%10;
l=l+48;
LCD_WriteChar(l);
l=i%10;
l=l%10;
l=l+48;
LCD_WriteChar(l);
LCD_Cmd(0x80);
}
}
}
}
void initLCD(void)
{
IODIR0 = 0xFF; //P0.0
to P0.7 configured as Output - Using 8 Bit mode
IODIR1 = (1<<16) | (1<<17); //P1.16 and P1.17 configured as Output -
Control Pins
IOPIN0 = 0x0; //Reset Port0 to 0.
IOPIN1 = 0x0; //Reset Port1 to 0 - Which also makes
RS and Enable LOW.
//LCD Initialization Sequence Now starts
delay(); //Initial
Delay
LCD_Cmd(0x3C); //Function Set Command : 8 Bit Mode , 2 Rows , 5x10 Font
Style
LCD_Cmd(0x0F); //Display
Switch Command : Display on , Cursor on , Blink on
LCD_Cmd(0x06); //Input
Set : Increment Mode
LCD_Cmd(0x01); //Screen
Clear Command , Cursor at Home
LCD_Cmd(0x80);
LCD_Cmd(0x1C);
//Not required the 1st time but
needed to reposition the cursor at home after Clearing Screen
//Done!
}
void enable(void)
{
delay();
IOPIN1 |= (1<<17); //Enable=High
delay();
IOPIN1 &= ~(1<<17); //Enable=Low
delay();
}
void LCD_WriteChar(char c)
{
IOPIN1 |= (1<<16); //Switch to Data Mode RS=1
IOPIN0 = (int) c; //Supply Character Code
enable(); //Pulse Enable to process it
}
void LCD_WriteString(char * string)
{
int c=0;
while (string[c]!='\0') /*loop continues until the string ends*/
{
LCD_WriteChar(string[c]); /*character pass to lcd*/
c++;
}
}
void LCD_Cmd(unsigned int cmd)
{
IOPIN1 = 0x0; //Enter
Instruction Mode
IOPIN0 = cmd; //Supply Instruction/Command Code
enable(); //Pulse Enable to
process it
}
void delay(void)
{
int i=0,x=0;
for(i=0; i<19999; i++){ x++; }
}
Connections:
From the above circuit
PORT0
i.e P0.0 to p0.7 connected to data pins D0 to D7
PORT1 i.e P1.16 to RS pin P1.17
connected to EN
GROUND the RW pin.
*** don’t forget to give BAT1 value as
3v****
Output:
0 comments:
Post a Comment