LCD 16*2 INTERFACING WITH LPC2148.
As given below the pin diagram of 16*2 lcd.
Pin description of 16*2 LCD |
LCD Initialization:
- · RS=0 & RW=0 (Select Command mode)
- · E=1
- · Delay
- · E=0 (Latch data into input register)
Commands:
Sr.No.
|
Hex Code
|
Command to LCD instruction
Register
|
1
|
01
|
Clear display screen
|
2
|
02
|
Return home
|
3
|
04
|
Decrement cursor (shift cursor to
left)
|
4
|
06
|
Increment cursor (shift cursor to
right)
|
5
|
05
|
Shift display right
|
6
|
07
|
Shift display left
|
7
|
08
|
Display off, cursor off
|
8
|
0A
|
Display off, cursor on
|
9
|
0C
|
Display on, cursor off
|
10
|
0E
|
Display on, cursor blinking
|
11
|
0F
|
Display on, cursor blinking
|
12
|
10
|
Shift cursor position to left
|
13
|
14
|
Shift cursor position to right
|
14
|
18
|
Shift the entire display to the
left
|
15
|
1C
|
Shift the entire display to the
right
|
16
|
80
|
Force cursor to beginning ( 1st
line)
|
17
|
C0
|
Force cursor to beginning ( 2nd
line)
|
18
|
38
|
2 lines and 5×7 matrix
|
Interfacing Diagram:
LCD INTERFACING WITH LPC2148 |
It is 8 bit data so there are D0 to D7 data pins.
RS=register select (If '1' then data register select else command register)
R/W= Read write
E= Enable
Algorithm:
- Start
- Initially define hardware of interfacing Diagram
- Initialize LCD by selecting functions of LPC2148 pins as GPIO, Set direction of pins as an output pins, Send Commands to LCD (0x38, 0x0E,0x0C, 0x06, 0x01, 0x80)
- LCD Command function:- Clear command value available on data pins first ,shift the command value by 16 bits to left side to get available on P0.16 to P0.23 , Make RS pin=0, RW pin=0, High to low pulse on Enable pin
- LCD Data function :- Clear data available on data pins first ,shift the data by 16 bits to left side to get available on P0.16 to P0.23 , Make RS pin=1, RW pin=0, High to low pulse on Enable pin
- Pass character to data function until null character
- End
Code: LCD 16*2 interfacing with LPC2148
/**************************************************************************************************
Expt. 2.: Interfacing 16x2 LCD to LPC2148
Platform: LPC2148 Development Board.
College: PICT
Hardware Setup:-
LCD data pin :-P0.16-P0.23
RS-P1.16
RW-P1.17
EN-P1.18
********************************************************************************/
//Include Controller specific header file
#include <lpc214x.h>
#define RS (1<<16)
#define RW (1<<17)
#define E (1<<18)
void LCD_command(unsigned char command);
void delay_ms(unsigned char time);
void LCD_data(unsigned char data);
void LCD_write_string(unsigned char *string);
void LCD_init() ;
int main(void)
{
//PINSEL1 = 0x00000000; //Configure PORT0 as GPIO
//PINSEL2 = 0X00000000; //Configure PORT1 as GPIO
IODIR1= 0x07<<16; //Configure P1.18, P1.17, P1.16 as output
IODIR0= 0xFF<<16; //Configure P0.23 - P0.16 as output
LCD_init(); //Initialize LCD 16x2
LCD_command(0x01);
LCD_write_string("Welcome to PICT");
LCD_command(0xc0); //second line 1st position
LCD_write_string("PUNE");
delay_ms(10) ;
while (1);
}
//Function to generate software delay
//Calibrated to 1ms
void delay_ms(unsigned char time)
{
unsigned int i, j;
for (j=0; j<time; j++)
{
for(i=0; i<8002; i++)
{
}
}
}
void LCD_command(unsigned char command)
{
IOCLR0 = 0xFF<<16; // Clear LCD Data lines
IOCLR1=RS; // RS=0 for command
IOCLR1=RW; // RW=0 for write
IOSET0=command<<16; // put command on data line
IOSET1=E; // en=1
delay_ms(10) ; // delay
IOCLR1=E; // en=0
}
void LCD_data(unsigned char data)
{
IOCLR0 = 0xFF<<16; // Clear LCD Data lines
IOSET1=RS; // RS=1 for data
IOCLR1=RW; // RW=0 for write
IOSET0= data<<16; // put command on data line
IOSET1=E; //en=1
delay_ms(10) ; //delay
IOCLR1=E; //en=0
}
void LCD_init()
{
LCD_command(0x38); //8bit mode and 5x8 dotes (function set)
delay_ms(10) ; // delay
LCD_command(0x0c); //display on, cursor off, cursor char blinking off(display on/off)
delay_ms(10) ; // delay
LCD_command(0x0e); //cursor increment and display shift(entry mode set)
delay_ms(10) ; // delay
LCD_command(0x01); //clear lcd (clear command)
delay_ms(10) ; // delay
LCD_command(0x80);
delay_ms(10) ;//set cursor to 0th location 1st lne
}
void LCD_write_string(unsigned char *string)
{
int i=0;
while(string[i]!='\0')
{ //Check for End of String
LCD_data(string[i]);
i=i+1; //sending data on LCD byte by byte
}
}
/************************************************************************************************** Expt. 2.: Interfacing 16x2 LCD to LPC2148 Platform: LPC2148 Development Board. College: PICT Hardware Setup:- LCD data pin :-P0.16-P0.23 RS-P1.16 RW-P1.17 EN-P1.18 ********************************************************************************/ //Include Controller specific header file #include <lpc214x.h> #define RS (1<<16) #define RW (1<<17) #define E (1<<18) void LCD_command(unsigned char command); void delay_ms(unsigned char time); void LCD_data(unsigned char data); void LCD_write_string(unsigned char *string); void LCD_init() ; int main(void) { //PINSEL1 = 0x00000000; //Configure PORT0 as GPIO //PINSEL2 = 0X00000000; //Configure PORT1 as GPIO IODIR1= 0x07<<16; //Configure P1.18, P1.17, P1.16 as output IODIR0= 0xFF<<16; //Configure P0.23 - P0.16 as output LCD_init(); //Initialize LCD 16x2 LCD_command(0x01); LCD_write_string("Welcome to PICT"); LCD_command(0xc0); //second line 1st position LCD_write_string("PUNE"); delay_ms(10) ; while (1); } //Function to generate software delay //Calibrated to 1ms void delay_ms(unsigned char time) { unsigned int i, j; for (j=0; j<time; j++) { for(i=0; i<8002; i++) { } } } void LCD_command(unsigned char command) { IOCLR0 = 0xFF<<16; // Clear LCD Data lines IOCLR1=RS; // RS=0 for command IOCLR1=RW; // RW=0 for write IOSET0=command<<16; // put command on data line IOSET1=E; // en=1 delay_ms(10) ; // delay IOCLR1=E; // en=0 } void LCD_data(unsigned char data) { IOCLR0 = 0xFF<<16; // Clear LCD Data lines IOSET1=RS; // RS=1 for data IOCLR1=RW; // RW=0 for write IOSET0= data<<16; // put command on data line IOSET1=E; //en=1 delay_ms(10) ; //delay IOCLR1=E; //en=0 } void LCD_init() { LCD_command(0x38); //8bit mode and 5x8 dotes (function set) delay_ms(10) ; // delay LCD_command(0x0c); //display on, cursor off, cursor char blinking off(display on/off) delay_ms(10) ; // delay LCD_command(0x0e); //cursor increment and display shift(entry mode set) delay_ms(10) ; // delay LCD_command(0x01); //clear lcd (clear command) delay_ms(10) ; // delay LCD_command(0x80); delay_ms(10) ;//set cursor to 0th location 1st lne } void LCD_write_string(unsigned char *string) { int i=0; while(string[i]!='\0') { //Check for End of String LCD_data(string[i]); i=i+1; //sending data on LCD byte by byte } }
No comments:
Post a Comment