Sei sulla pagina 1di 16

Project Report

on

 Interfacing a LCD 128x64 Graphic Module to  89c51
Microcontroller for Graph plotting

Submitted By
Ashutosh Bhatia 
ME 1st Year 
Sr. No 03860
Project Description : The trend in consumer and commercial electronics is
increasing sophistication.  Every year more and more devices include text
LCD's (Liquid Crystal Display) built into their products.  Devices such as
telephones, fax machines, photocopiers, bar code readers, music keyboards
and synthesizers, test instruments, modems, laser printers.  This kind of user
friendliness is a tremendous advantage. The Graphic LCD module has got
versatile applications in engineering as well as consumer elcectronics
domain. Normally they are preferred over the alphanumeric LCD module
for text application also. 

Here, I have interfaced  the 128x64 LCD module (model no. 12864 Oriole)
with 89c51 8­bit microconctroller and written the software in C (Keil) for
plotiing the graph either from look­up table store in data or code segment or
data generated by some function (y = f(x)). The LCD screen (128x64 pixels)
is considered as the cartisian plane as shown in the following fig.

(0,63) (63,63) (127,63)

(127,0)
(0,0) (64,0)
Y Axis
64 pixels
(63,­63) (127,­63)
(0,­63)

(X Axis (128 pixels)

Mapping of LCD 128x64 screen to the Cartisian Plane

Note that (0,0) position is the extreme left of the x­axis. If user application
requires ­ve values in X direction also then the programmer has to pass the
value to the plotting function after adding 64 to the x value.
For example if x value is  x = ­4 then the actual value will be x = x + 64= 60
to the plotting function.
Hardware Descriptiion: Following is the Pin Diagram of Interface
between LCD module and 89c51 microcontroller .

33 pf 8051 OGM 12864


+5v
p1.0  D0 ( 7)
x1   VDD 2
p1.1  D1 (8)
p1.2  D2 (9)
p1.3  D3 (10)
x2 p1.4  D4 (11) VO (3)
p1.5  D5 (12)
p1.6  D6(13)
33 pf p1.7 D7 (14) VOUT 18

VSS (1)

p3.0  RS  (4)
p3.1  R/W (5)
RST
p3.2   E (6)  
p3.3  CS1 (15)
p3.4  CS2 (16) 
P3.5 RSTB (17)

Pin Connection Diagram
LCD Pin Description : 
NO. SYMBOL LEVEL FUNCTION

1 V SS GROUND

2 V DD POWER SUPPLY FOR LOGIC CIRCUIT

3 BRIGHTNESS CONTROL
VO

4 H/L H : DATA INPUT


            RS L : INSTRUCTION CODE INPUT

5. H/L H : DATA READ (LCD MODULE  MPU)


          R / W L : DATA WRITE (LCD MODULE MPU)
6. E ENABLE
(SEE CH.5 - TIMING CHARACTERSTICS)

7-14 DB0-DB7 H/L DATA BUS LINE

15 CS1 H CHIP SELECT FOR IC1

16 CS2 H CHIP SELECT FOR IC2

17 L RESET
RST

18 V OUT NEGATIVE VOLTAGE OUTPUT(-5V)

19 +Vled. BACKLIGHT

20 - Vled. BACKLIGHT

1. VCC,VSS : provides +5v and ground 
2. VOUT:  is used to control the LCD contrast
3. RS, Register Select : There are two very important registers inside the LCD. the RS
pin is used for their selction. If RS = 0, isntruction command register is selected
allowing user to send a command. If RS = 1, the data register is selected, allowing the
user to send data to be displayed.
4. R/W, read write : R/W pin alow the user to write information to the LCD or read
information from LCD.
5. E, Enable : is used by the LCD to latch information presented to its data pins . High to
Low pluse must be supplied to to write the data and a Low to High pulse must be
supplid to read the data.
6. D0­D7 : The data pins
7. CS1,CS2, chip select  : since the LCD module consist of two controller for each 64x64
portion of the screen the above pins are reqiored to select the controller.
7. RST, Reset :  is used to reset the LCD controller.

Software Description : Following is the flow chart for initializing and
writing data to the LCD module.
 
Start

Reset LCD
(RST = 0)

Set Display On

Set Page
(Y address)

Set Column
(X address)

Write Data
Functional Description : following is the list of of major functions
implemented  plot the graph of data stored in the look­up table at code area
refereced by the array named “Pattern[128]” . 

void delay_sec(void) : One Second Delay 
This  function is  used to generate the delay of one second . This provides
the facility to see the step by step plotting of data in animated form on the
screen

void delay_msec(void) : One mili second delay 
This function is used to generate the delay of one milisecond. This provides
the  delay between any two command in order to synchronize  the LCD
module.

void InitializeDisplay(void) :  Initializes the LCD module
This is function resets the LCD module and sets all the control signal like 
RS,E,CS1,CS2 = 0 

void DisplayOn1(void) :  On the controller one display
This function make the controller one display on sets the logical start line
by sending the appropriate command to the LCD module

void SendIns1(void) : Sends command or instruction to the controller one
This function sends intruction to the LCD controller one  . The instructio which has to be
sent is referenced by the variable  “instruction”

void SendData1() : Sends data for the controller to be displayed
This function sends data to the LCD controller one . the data which has to
be sent is referenced by the variable “Data”

void ClearDisplay1() : Clears the previous screen of controller one 
This function clears the complete screen of controller one by send  0 to  as the data value 
in a for loop.

void PlotXY1(int x , int y): Plots the pixel at location specified by the x (x­
axis) and y (y­axis) vaue passed to it. 
void Axis(void) :  Draws the axis .

Note : both the controller has been handled separately. If the user wants to
plot the value let (70,34) then the main program should call the funtion 
PlotXY2 in order to plot the pixel to the next half of the screen. 

Example :    pixel (34,10) ­­­> PlotXY1(34,10)
         pixel(70,10) ­­­­> PlotXY2(70,10)

 Following is the flow chart of main loop of the program.

Start

InitializeDisplay() ;

DisplayOn1(); 

DisplayOn2();

ClearDisplay1() ;

ClearDisplay2() ;

PlotXY() 
/////////////////////////////////Ptogram Source Code //////////////////////////////////////////

/* PROGRAM FOR plotting a graph to the  LCD module (128 * 64 pixels)
using   89C51 */

#include <REGX51.H>

/* function ptototypes */

void delay_sec(void) ;
void delay_msec(void) ;
void InitializeDisplay(void) ;
void DisplayOn1(void);
void SendIns1(void) ;
void SendData1() ;
void ClearDisplay1() ;
void PlotXY1(int x , int y);
void DisplayOn2(void);
void SendIns2(void) ;
void SendData2() ;
void ClearDisplay2() ;
void PlotXY2(int x , int y);
void Axis(void) ;

/* definition of constants */
#define DPON 0x3F // SETS DISPLAY ON
#define DP_STLN 0xC0

sbit RS = P3^0; // RS = 1 ­­> DATA , RS = 0 ­­> INSTR.


sbit RD_WR= P3^1; // READ = 1 , WRITE = 0
sbit ENBL = P3^2; // ENABLE SIGNAL ( ACTIVE HIGH )
sbit CS1 = P3^3; // CHIP SELECT 1 ( ACTIVE HIGH )
sbit CS2 =  P3^4; // CHIP SELECT 2 ( ACTIVE HIGH )
sbit RST = P3^5; // RESET SIGNAL ( ACTIVE LOW )
// The lookup table ( Triangular Wave)
code char Pattern[128]  = {0,1,2,3,4,5,6,7,8,9,10,
11,12,13,14,15,16,17,
18,19,20,21,22,23,24,25,
26,27,28,29,30,31,31,30,29,
28,27,26,25,24,23,22,21,
20,19,18,17,16,15,14,
13,12,11,10,9,8,7,6,5,
4,3,2,1,0,0,­1,­2,­3,­4,­5,
­6,­7,­8,­9,­10,­11,­12,­13,
   ­14,­15,­16,­17,­18,­19,­20,
­21,­22,­23,­24,­25,­26,­27,
­28,­29,­30,­31,­31,­30,­29,
­28,­27,­26,­25,­24,­23,­22,­21,
­20,­19,­18,­17,­16,­15,­14,
­13,­12,­11,­10,­9,­8,­7,­6,­5,
­4,­3,­2,­1,0 };
unsigned char bitmap[8] = {1, 2, 4, 8, 16, 32, 64, 128} ;
unsigned char instruction ;
unsigned char Data ;
unsigned char PageAddress ;
unsigned char ColumnAddress ;
unsigned char overlap = 0 ;
void main()
{
int i ;
delay_sec(); // wait for 1 sec to settle the LCD
InitializeDisplay() ;   // Initialize the LCD display
delay_sec(); // wait
DisplayOn1(); // On Display controller one
delay_msec(); // Syachronization Delay
DisplayOn2(); //  On Display controller Two
delay_msec(); // Syachronization Delay
ClearDisplay1() ; // clear privious data stored in the LCD controller 
delay_msec(); // wait
ClearDisplay2() ; //  clear privious data stored in the LCD controller 
Axis(); // Draw the axis
for(i=0;i<128;i++) // Plot the graph
{
if(i < 64)
{
PlotXY1(i,Pattern[i]) ;
}
else
{
PlotXY2(i,Pattern[i]) ;
}
}
while(1);
}

void InitializeDisplay(void)
{
int i ;
RST = 0 ;
for(i=0;i<=10;i++);
    RST = 1 ;
delay_msec() ;

ENBL = 0  ;
CS1 = 0 ;
    CS2 = 0 ;
RD_WR = 0 ;
RS = 0 ;
}

void DisplayOn1(void)
{
instruction = DPON ;
delay_msec() ;
SendIns1() ;
instruction = DP_STLN ;
delay_msec() ;
SendIns1() ;
}
void SendIns1(void){
int i ;
RD_WR = 0 ;
CS1 = 1 ;
CS2 = 0 ;
RS = 0 ;
i = 0 ;
i = 0 ;
i = 0 ;
P1 = instruction ;
i = 0 ;
i = 0 ;
i = 0 ;
ENBL = 1 ;
i = 0 ;
i = 0 ;
i = 0 ;
ENBL = 0 ;
i = 0 ;
i = 0 ;
i = 0 ;}
void ClearDisplay1(void){
int i ;
PageAddress = 184 ;
ColumnAddress = 0x40 ;
Data = 0x00 ;
while(PageAddress != 192){
instruction = PageAddress ;
delay_msec() ;
SendIns1() ;
delay_msec();
instruction = ColumnAddress ;
for(i=0;i<64;i++){
SendData1();
delay_msec();
//Data = Data ^ 0xff ;
}
PageAddress ++ ;}}
void SendData1(void){
int i ;
RD_WR = 0 ;
CS1 = 1 ;
CS2 = 0 ;
RS = 1 ;
i = 0 ;
i = 0 ;
i = 0 ;
P1 = Data ;
i = 0 ;
i = 0 ;
i = 0 ;
ENBL = 1 ;
i = 0 ;
i = 0 ;
i = 0 ;
ENBL = 0 ;
i = 0 ;
i = 0 ;
i = 0 ;}
void PlotXY1(int x , int y){
y = y + 32 ;
PageAddress = 0xB8 + (7 ­ y / 8) ;
instruction = PageAddress ;
delay_msec() ;
SendIns1() ;
delay_sec() ;
ColumnAddress = 0x40 + x ;
instruction = ColumnAddress ;
delay_msec() ;
SendIns1() ;
if(overlap == 0)
Data = bitmap[7­ (y % 8)] ;
else
Data = 255 ;
delay_sec();
SendData1() ;}
void DisplayOn2(void)
{
instruction = DPON ;
delay_msec() ;
SendIns2() ;

instruction = DP_STLN ;
delay_msec() ;
SendIns2() ;
}

void SendIns2(void)
{
int i ;
RD_WR = 0 ;
CS1 = 0 ;
CS2 = 1 ;
RS = 0 ;
i = 0 ;
i = 0 ;
i = 0 ;
P1 = instruction ;
i = 0 ;
i = 0 ;
i = 0 ;
ENBL = 1 ;
i = 0 ;
i = 0 ;
i = 0 ;
ENBL = 0 ;
i = 0 ;
i = 0 ;
i = 0 ;
}
void ClearDisplay2(void)
{
int i ;
PageAddress = 184 ;
ColumnAddress = 0x40 ;
Data = 0x00 ;
while(PageAddress != 192)
{
instruction = PageAddress ;
delay_msec() ;
SendIns2() ;
delay_msec();
instruction = ColumnAddress ;
for(i=0;i<64;i++)
{
SendData2();
delay_msec();
//Data = Data ^ 0xff ;
}
PageAddress ++ ;
}
}

void SendData2(void)
{
int i ;
RD_WR = 0 ;
CS1 = 0 ;
CS2 = 1 ;
RS = 1 ;
i = 0 ;
i = 0 ;
i = 0 ;
P1 = Data ;
i = 0 ;
i = 0 ;
i = 0 ;
ENBL = 1 ;
i = 0 ;
i = 0 ;
i = 0 ;
ENBL = 0 ;
i = 0 ;
i = 0 ;
i = 0 ;

void PlotXY2(int x , int y)
{
x = x ­ 64 ;
y = y + 32 ;
PageAddress = 0xB8 + (7 ­ y / 8) ;
instruction = PageAddress ;
delay_msec() ;
SendIns2() ;
delay_sec() ;
ColumnAddress = 0x40 + x ;
instruction = ColumnAddress ;
delay_msec() ;
SendIns2() ;
if(overlap == 0)
Data = bitmap[7­ (y % 8)] ;
else
Data = 255 ;
delay_sec();
SendData2() ;
}

void Axis(void)
{
int i ;

for(i=0;i<64;i++)
{
PlotXY1(i,0) ;
delay_msec() ;
}

for(i=0;i<64;i++)
{
PlotXY2(i,0) ;
delay_msec() ;
}
overlap = 1 ;
for(i=0;i<64;i++)
{
PlotXY1(62,i­31) ;
delay_msec() ;

}
overlap = 0 ;

Potrebbero piacerti anche