Aim:
This tutorial describes how to interface between a 128×64 graphic LCD and an 8-bit
micro-controller. The techniques described here are useful for any other
controller type and interfacing technique. The micro-controller is
connected via its I/O lines and all signals to the LCD are controlled
directly by software.
This tutorial describes how to interface between a 128×64 graphic LCD and an 8-bit
micro-controller. The techniques described here are useful for any other controller type and interfacing technique. The micro-controller is connected via its I/O lines and all signals to the LCD are controlled directly by software.
micro-controller. The techniques described here are useful for any other controller type and interfacing technique. The micro-controller is connected via its I/O lines and all signals to the LCD are controlled directly by software.
Description:
Display mapping: Individual pixels can be controlled by writing a byte
to a specific address. Each address is mapped to a corresponding set of 8
pixels on the display. Please refer to Figure 1. Note that the order of
the columns is reversed. The first byte of data entered after setting
the address registers to 0 will appear in the upper right of the
display.
The display has 20 pins, numbered from right to left, as we can see in
the picture below. It can be used to communicate with the any
microcontroller using parallel communication. In this article, where the
LCD refresh rate is not a critical point, we will use the parallel
communication
The circuit uses a potentiometer (used a 50K) for adjusting the display contrast, and power is made by 5v power supply.
The specification of this LCD are as follows.
- 128 horizontal pixel and 64 vertical pixel resolution.
- Controlled based on KS0108B
- Parallel 8bit interface
- On board graphic memory.
- Available in Green backlight with dark green pixels.
- Also available in Blue backlight with light blue pixels.
- LED backlight.
- 20 PIN linear connection.
Display mapping: Individual pixels can be controlled by writing a byte
to a specific address. Each address is mapped to a corresponding set of 8
pixels on the display. Please refer to Figure 1. Note that the order of
the columns is reversed. The first byte of data entered after setting
the address registers to 0 will appear in the upper right of the
display.
The display has 20 pins, numbered from right to left, as we can see in
the picture below. It can be used to communicate with the any
microcontroller using parallel communication. In this article, where the
LCD refresh rate is not a critical point, we will use the parallel
communication
The circuit uses a potentiometer (used a 50K) for adjusting the display contrast, and power is made by 5v power supply.
The specification of this LCD are as follows.
- 128 horizontal pixel and 64 vertical pixel resolution.
- Controlled based on KS0108B
- Parallel 8bit interface
- On board graphic memory.
- Available in Green backlight with dark green pixels.
- Also available in Blue backlight with light blue pixels.
- LED backlight.
- 20 PIN linear connection.
PIN Description
PIN
Name
Function
Connection with AVR PIN
1 Vss Ground
2 Vcc +5v Supply in
3 V0 Contrast Adjust
4 RS Instruction/Data Register Select P3.2
5 R/W READ/WRITE SELECTION P3.1
6 E ENABLE SIGNAL P3.0
7 DB0 DATA IN/OUT P2.0
8 DB1 DATA IN/OUT P2.1
9 DB2 DATA IN/OUT P2.2
10 DB3 DATA IN/OUT P2.3
11 DB4 DATA IN/OUT P2.4
12 DB5 DATA IN/OUT P2.5
13 DB6 DATA IN/OUT P2.6
14 DB7 DATA IN/OUT P2.7
15 CS1 Chip Select 1 P3.3
16 CS2 Chip Select 2 P3.4
17 RST RESET SIGNAL RESET
18 VEE NEGATIVE 10V OUT
19 LED+ LED BACKLIGHT
20 LED- LED BACKLIGHT
PIN
|
Name
|
Function
|
Connection with AVR PIN
|
1 | Vss | Ground | |
2 | Vcc | +5v Supply in | |
3 | V0 | Contrast Adjust | |
4 | RS | Instruction/Data Register Select | P3.2 |
5 | R/W | READ/WRITE SELECTION | P3.1 |
6 | E | ENABLE SIGNAL | P3.0 |
7 | DB0 | DATA IN/OUT | P2.0 |
8 | DB1 | DATA IN/OUT | P2.1 |
9 | DB2 | DATA IN/OUT | P2.2 |
10 | DB3 | DATA IN/OUT | P2.3 |
11 | DB4 | DATA IN/OUT | P2.4 |
12 | DB5 | DATA IN/OUT | P2.5 |
13 | DB6 | DATA IN/OUT | P2.6 |
14 | DB7 | DATA IN/OUT | P2.7 |
15 | CS1 | Chip Select 1 | P3.3 |
16 | CS2 | Chip Select 2 | P3.4 |
17 | RST | RESET SIGNAL | RESET |
18 | VEE | NEGATIVE 10V OUT | |
19 | LED+ | LED BACKLIGHT | |
20 | LED- | LED BACKLIGHT |
Block Diagram
Schematic
Code
Main File:
// *******************************************************
// Project: Interfacing Graphical LCD with 8051
// Author: Code Bloges
// Module description: Operate Graphical LCD
// *******************************************************
#include<reg51.h>
#include<intrins.h>
#define dport P2
sbit rs=P3^0;
sbit rw=P3^1;
sbit en=P3^2;
sbit cs1=P3^3;
sbit cs2=P3^4;
unsigned char c,z=0;
unsigned char ar00[]={127,8,8,8,127}; //H,5x7
unsigned char ar11[]={126,17,17,17,126}; //A,5x7
unsigned char ar22[]={62,65,65,65,34}; //C,5x7
unsigned char ar33[]={127,8,20,34,65}; //K,5x7
unsigned char ar44[]={127,9,9,9,6}; //P,5x7
unsigned char ar55[]={127,9,25,41,70}; //R,5x7
unsigned char ar66[]={62,65,65,65,62}; //O,5x7
unsigned char ar77[]={32,64,65,63,1}; //J,5x7
unsigned char ar88[]={127,73,73,73,65}; //E,5x7
unsigned char ar99[]={1,1,127,1,1}; //T,5x7
unsigned char ar01[]={70,73,73,73,49}; //S,5x7
unsigned char ar02[]={0,0,0,0,0}; // ,5x7
void ctrloff()
{
rs=0;
rw=0;
en=0;
cs1=0;
cs2=0;
}
//Display on function
void displayon()
{
ctrloff();
dport=0x3f;
cs1=1;cs2=1;
rw=0;rs=0;
en=1;
_nop_();
en=0;
}
void setcolumn(unsigned char y)
{
if(y<64)
{
ctrloff();
c=y;
dport=0x40|(y&63); //0x40 represents Column 0
cs1=1;cs2=0;
rs=0;
rw=0;
en=1;
_nop_();
en=0;
}
else
{
c=y;
dport=0x40|((y-64)&63); //0x40 represents Column 0
cs2=1;cs1=0;
rs=0;
rw=0;
en=1;
_nop_();
en=0;
}
}
void setpage(unsigned char x)
{
ctrloff();
dport= 0xb8|x; //0xb8 represents Page 0
cs1=1;
cs2=1;
rs=0;
rw=0;
en=1;
_nop_();
en=0;
}
void lcddata(unsigned char *value,unsigned int limit)
{
unsigned int i;
for(i=0;i<limit;i++)
{
if(c<64)
{
dport=value[i];
cs1=1;cs2=0;
rs=1;
rw=0;
en=1;
_nop_();
en=0;
c++;
}
else
{
setcolumn(c);
dport=value[i];
cs2=1;cs1=0;
rs=1;
rw=0;
en=1;
_nop_();
en=0;
c++;
}
if(c>127)
return;
}
}
void clrlcd()
{
unsigned char i,j;
for (i=0;i < 8;i++)
{
setpage(i);
setcolumn(0);
for (j= 0 ;j < 128; j++)
lcddata(&z,1);
}
}
void main()
{
clrlcd();
displayon();
setpage(3);
setcolumn(0);
lcddata(&ar00,5);
setpage(3);
setcolumn(6);
lcddata(&ar11,5);
setpage(3);
setcolumn(12);
lcddata(&ar22,5);
setpage(3);
setcolumn(18);
lcddata(&ar33,5);
setpage(3);
setcolumn(24);
lcddata(&ar02,5);
setpage(3);
setcolumn(30);
lcddata(&ar44,5);
setpage(3);
setcolumn(36);
lcddata(&ar55,5);
setpage(3);
setcolumn(42);
lcddata(&ar66,5);
setpage(3);
setcolumn(48);
lcddata(&ar77,5);
setpage(3);
setcolumn(54);
lcddata(&ar88,5);
setpage(3);
setcolumn(60);
lcddata(&ar22,5);
setpage(3);
setcolumn(66);
lcddata(&ar99,5);
setpage(3);
setcolumn(72);
lcddata(&ar01,5);
while(1)
{
}
}
// *******************************************************
// Project: Interfacing Graphical LCD with 8051
// Author: Code Bloges
// Module description: Operate Graphical LCD
// *******************************************************
#include<reg51.h>
#include<intrins.h>
#define dport P2
sbit rs=P3^0;
sbit rw=P3^1;
sbit en=P3^2;
sbit cs1=P3^3;
sbit cs2=P3^4;
unsigned char c,z=0;
unsigned char ar00[]={127,8,8,8,127}; //H,5x7
unsigned char ar11[]={126,17,17,17,126}; //A,5x7
unsigned char ar22[]={62,65,65,65,34}; //C,5x7
unsigned char ar33[]={127,8,20,34,65}; //K,5x7
unsigned char ar44[]={127,9,9,9,6}; //P,5x7
unsigned char ar55[]={127,9,25,41,70}; //R,5x7
unsigned char ar66[]={62,65,65,65,62}; //O,5x7
unsigned char ar77[]={32,64,65,63,1}; //J,5x7
unsigned char ar88[]={127,73,73,73,65}; //E,5x7
unsigned char ar99[]={1,1,127,1,1}; //T,5x7
unsigned char ar01[]={70,73,73,73,49}; //S,5x7
unsigned char ar02[]={0,0,0,0,0}; // ,5x7
void ctrloff()
{
rs=0;
rw=0;
en=0;
cs1=0;
cs2=0;
}
//Display on function
void displayon()
{
ctrloff();
dport=0x3f;
cs1=1;cs2=1;
rw=0;rs=0;
en=1;
_nop_();
en=0;
}
void setcolumn(unsigned char y)
{
if(y<64)
{
ctrloff();
c=y;
dport=0x40|(y&63); //0x40 represents Column 0
cs1=1;cs2=0;
rs=0;
rw=0;
en=1;
_nop_();
en=0;
}
else
{
c=y;
dport=0x40|((y-64)&63); //0x40 represents Column 0
cs2=1;cs1=0;
rs=0;
rw=0;
en=1;
_nop_();
en=0;
}
}
void setpage(unsigned char x)
{
ctrloff();
dport= 0xb8|x; //0xb8 represents Page 0
cs1=1;
cs2=1;
rs=0;
rw=0;
en=1;
_nop_();
en=0;
}
void lcddata(unsigned char *value,unsigned int limit)
{
unsigned int i;
for(i=0;i<limit;i++)
{
if(c<64)
{
dport=value[i];
cs1=1;cs2=0;
rs=1;
rw=0;
en=1;
_nop_();
en=0;
c++;
}
else
{
setcolumn(c);
dport=value[i];
cs2=1;cs1=0;
rs=1;
rw=0;
en=1;
_nop_();
en=0;
c++;
}
if(c>127)
return;
}
}
void clrlcd()
{
unsigned char i,j;
for (i=0;i < 8;i++)
{
setpage(i);
setcolumn(0);
for (j= 0 ;j < 128; j++)
lcddata(&z,1);
}
}
void main()
{
clrlcd();
displayon();
setpage(3);
setcolumn(0);
lcddata(&ar00,5);
setpage(3);
setcolumn(6);
lcddata(&ar11,5);
setpage(3);
setcolumn(12);
lcddata(&ar22,5);
setpage(3);
setcolumn(18);
lcddata(&ar33,5);
setpage(3);
setcolumn(24);
lcddata(&ar02,5);
setpage(3);
setcolumn(30);
lcddata(&ar44,5);
setpage(3);
setcolumn(36);
lcddata(&ar55,5);
setpage(3);
setcolumn(42);
lcddata(&ar66,5);
setpage(3);
setcolumn(48);
lcddata(&ar77,5);
setpage(3);
setcolumn(54);
lcddata(&ar88,5);
setpage(3);
setcolumn(60);
lcddata(&ar22,5);
setpage(3);
setcolumn(66);
lcddata(&ar99,5);
setpage(3);
setcolumn(72);
lcddata(&ar01,5);
while(1)
{
}
}
Downloads:
The code was compiled in Keil uvision4 and simulation was made in Proteus v7.7.
To download code and proteus simulation click here.
To download code and proteus simulation click here.
Further Reading suggestions:
You may also like,
- Interfacing keypad with 8051
- Interfacing with UART of 8051 controller
- Interfacing SPI communication with 8051
- 8051 Displaying Custom Characters on LCD
- RTC interfacing using I2C in 8051
- Interfacing ultrasonic sensor with 8051
- Interfacing GPS Modu with 8051
- Interfacing GSM Module with 8051
- ADC Module interfacing with 8051
- Interfacing PWM in 8051
- Interfacing keypad with 8051
- Interfacing with UART of 8051 controller
- Interfacing SPI communication with 8051
- 8051 Displaying Custom Characters on LCD
- RTC interfacing using I2C in 8051
- Interfacing ultrasonic sensor with 8051
- Interfacing GPS Modu with 8051
- Interfacing GSM Module with 8051
- ADC Module interfacing with 8051
- Interfacing PWM in 8051
No comments:
Post a Comment