LCD Interfacing with 8051 Microcontroller
LCD Interfacing with 8051 Microcontroller
Hex Code | Command to LCD Instruction Register |
0F | LCD ON, cursor ON |
01 | Clear display screen |
02 | Return home |
04 | Decrement cursor (shift cursor to left) |
06 | Increment cursor (shift cursor to right) |
05 | Shift display right |
07 | Shift display left |
0E | Display ON, cursor blinking |
80 | Force cursor to the beginning of the first line |
C0 | Force cursor to the beginning of the second line |
38 | 2 lines and 5×7 matrix |
83 | Cursor line 1 position 3 |
3C | Activate the second line |
08 | Display OFF, cursor OFF |
C1 | Jump to the second line, position 1 |
OC | Display ON, cursor OFF |
C1 | Jump to the second line, position 1 |
C2 | Jump to a second line, position 2 |
Circuit Diagram :
Source Code:
// Program for LCD Interfacing with 8051 Microcontroller (P89V51RD2)
#include<reg51.h>
#include <string.h>
#define display_port P2 //Data pins connected to port 2 on microcontroller
sbit rs = P0^0; //Register Select pin connected to pin 0 of port 0
sbit rw = P0^1; // Read/Write pin connected to pin 0 of port 1
sbit e = P0^2; //Enable pin connected to pin 0 of port 2
void msdelay(unsigned int time) // Function for creating delay in milliseconds.
{
unsigned i,j ;
for(i=0;i<time;i++)
for(j=0;j<1275;j++);
}
void lcd_cmd(unsigned char command) //Function to send command instruction to LCD
{
display_port = command;
rs= 0;
rw=0;
e=1;
msdelay(1);
e=0;
}
void lcd_data(unsigned char disp_data) //Function to send display _data to LCD
{
display_port = disp_data;
rs= 1;
rw=0;
e=1;
msdelay(1);
e=0;
}
void lcd_init() //Function to prepare the LCD and get it ready
{
lcd_cmd(0x38); // for _using 2 lines and 5X7 matrix of LCD
msdelay(10);
lcd_cmd(0x0F); // turn display ON, cursor blinking
msdelay(10);
lcd_cmd(0x01); //clear screen
msdelay(10);
lcd_cmd(0x81); // bring cursor to position 1 of line 1
msdelay(10);
}
void main()
{
unsigned char a[15]="Surajkumar"; //string of 14 characters with a null terminator.
int l=0;
int len = strlen(a);
lcd_init();
for(l;l<len;l++)
{
lcd_data(a[l]);
msdelay(50);
}
// OR
//while(a[l] != '\0') // searching the null terminator in the sentence
//{
// lcd_data(a[l]);
// l++;
// msdelay(50);
//}
while(1);
}
Amazing!!!! :)
ReplyDeleteThank you very much... BloCills...
ReplyDeleteWelcome!!!
Delete