Component:
- 8051 Development Board
- 16x2 Lcd
Get Datasheet:
Download Datasheet form below link
Please read important topics from datasheet.
- Features
- Absolute Maximum
- Electronic Characteristics
- Pin Assignment
- Instruction Table
Photo:
LCD Basic Circuit Diagram
LCD |
8051 |
D0 |
P0^0 |
D1 |
P0^1 |
D2 |
P0^2 |
D3 |
P0^3 |
D4 |
P0^4 |
D5 |
P0^5 |
D6 |
P0^6 |
D7 |
P0^7 |
RS |
P1^0 |
RW |
P1^1 |
E |
P1^2 |
LCD and 8051 Pin 4 bit mode Connections
RS, RW, E, and D0-D7
D0-D7 is represent as 8bit data-bus
RS=0 means instruction or command
RS=1 means data
E = enable or latch the information from data-bus
Instruction or Command of LCD 16x2
Command Hex |
Description |
1 |
Clear display screen |
2 |
Return home |
4 |
Decrement cursor (shift left) |
6 |
Increment cursor (shift right) |
0x38 |
2 lines 5x7 matrix |
E |
Display on cursor blinking |
80 |
1st line position 0 |
C0 |
2nd line position 0 |
LCD 8bit mode Program
programs in different Categories.
#include <reg51.h>
sfr ldata = 0x80; //P0=LCD data pins
sbit rs = P1^0;
sbit rw = P1^1;
sbit en = P1^2;
void ms_delay(unsigned int itime)
{
unsigned int i, j;
for(i=0;i<itime;i++)
for(j=0;j<1275;j++);
}
void lcdcmd(unsigned char value)
{
ldata = value; //put the value on the pins
rs = 0;
rw = 0;
en = 1; //strobe the enable pin
ms_delay(1);
en = 0;
return;
}
void lcddata(unsigned char value)
{
ldata = value; //put the value on the pins
rs = 1;
rw = 0;
en = 1; //strobe the enable pin
ms_delay(1);
en = 0;
return;
}
void lcdstr(char *str)
{
while(*str)
{
lcddata(*str++);
ms_delay(10);
}
}
void lcd_init()
{
lcdcmd(0x38); // 2 line and 5x7 matrix
ms_delay(10);
lcdcmd(0x0E); // Display On, cursor blinking
ms_delay(10);
lcdcmd(0x01); // clear display
ms_delay(10);
lcdcmd(0x06); // Increment cursor (shit to right)
ms_delay(10);
}
void main(){
lcd_init();
lcdcmd(0x80); // line 1, position 0
lcddata('P');
ms_delay(10);
lcddata('M');
ms_delay(10);
lcddata('V');
ms_delay(10);
lcddata('A');
ms_delay(10);
lcddata('N');
ms_delay(10);
lcddata('K');
ms_delay(10);
lcddata('E');
ms_delay(10);
lcddata('R');
ms_delay(10);
lcdcmd(0xC0); //line 2, position 0
ms_delay(10);
lcdstr("Please Subscribe");
}
LCD 4bit mode Program
programs in different Categories.
#include <reg51.h> #define lcd P0 sbit RS=P1^0; sbit RW=P1^1; sbit EN=P1^2; void init_lcd(void); void cmd_lcd(unsigned char); void data_lcd(unsigned char); void str_lcd(char *); void delay_ms(unsigned int itime) { unsigned int i, j; for(i=0;i<itime;i++) for(j=0;j<1275;j++); } void init_lcd() { cmd_lcd(0x02); //4-bit mode cmd_lcd(0x28); cmd_lcd(0x80); //starting pos of 1st line cmd_lcd(0x01); //clear screen cmd_lcd(0x0C); cmd_lcd(0x06); } void write_lcd(unsigned char ch) { RW=0; lcd=(ch & 0xf0); EN=1; delay_ms(2); EN=0; lcd=(ch<<4); EN=1; delay_ms(2); EN=0; } void cmd_lcd(unsigned char ch) { RS=0; write_lcd(ch); } void data_lcd(unsigned char ch) { RS=1; write_lcd(ch); } void str_lcd(char *p) { while(*p) data_lcd(*p++); } void main() { init_lcd(); cmd_lcd(0x80) // line 1 pos 0 str_lcd("Praful Vanker"); }
Thank You