8051 INTERFACING WITH KS108 GRAFICAL DISPLAY

PROGRAM:
#include <reg51.h>
#include <stdio.h>
#define DATA P1
sbit CS1= P3^2;
sbit CS2= P3^3;
sbit RS= P3^4;
sbit RW=P3^5;
sbit lcd_e=P3^6;
sbit RST=P3^7;
void GLCD_PutPicture(const unsigned char *);
void Select_page(unsigned char);
int i;
//---------------------------------
//Load your black&white images here
//---------------------------------
code unsigned char const pan_bmp[1024] ={
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 255, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 255, 4, 4, 12, 12, 8, 248, 4, 4, 6, 2, 2, 2, 0, 6, 6, 8, 12, 20, 24, 0, 48, 48, 96, 64, 64, 192, 0, 0, 0, 64, 64, 64, 64, 192, 192, 128, 192, 192, 128, 128, 160, 32, 32, 32, 32, 32, 32, 32, 0, 64, 64, 80, 80, 240, 16, 64, 96, 128, 192, 0, 128, 128, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 255, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 255, 240, 0, 224, 224, 0, 255, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 255, 241, 113, 0, 128, 224, 240, 24, 8, 136, 8, 88, 112, 24, 136, 216, 8, 152, 216, 224, 0, 0, 0, 0, 0, 0, 0, 255, 0, 0, 124, 0, 0, 1, 241, 18, 3, 125, 198, 6, 200, 12, 148, 152, 232, 240, 80, 96, 160, 192, 64, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 255, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 255, 3, 0, 15, 15, 0, 255, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 192, 224, 48, 16, 24, 56, 48, 176, 176, 255, 127, 8, 8, 15, 4, 4, 16, 2, 64, 50, 33, 134, 128, 64, 64, 240, 24, 28, 5, 31, 154, 24, 24, 14, 1, 17, 7, 242, 230, 252, 2, 128, 0, 210, 0, 192, 0, 0, 0, 0, 0, 63, 3, 210, 255, 30, 6, 2, 4, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 255, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 255, 0, 254, 254, 14, 0, 255, 0, 0, 0, 0, 128, 96, 240, 176, 208, 208, 104, 47, 30, 56, 9, 22, 3, 17, 9, 25, 71, 110, 156, 29, 232, 208, 192, 192, 64, 64, 65, 0, 0, 0, 0, 0, 16, 0, 0, 0, 8, 0, 1, 10, 0, 0, 1, 5, 9, 45, 62, 240, 127, 192, 0, 0, 0, 0, 0, 64, 0, 128, 128, 128, 122, 255, 64, 192, 32, 96, 112, 0, 192, 128, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 255, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 255, 0, 224, 224, 0, 16, 255, 16, 56, 108, 212, 63, 39, 67, 84, 194, 196, 4, 192, 112, 144, 64, 224, 64, 64, 80, 208, 224, 192, 65, 130, 129, 17, 2, 130, 130, 128, 129, 129, 0, 254, 2, 2, 22, 0, 144, 0, 128, 16, 0, 128, 64, 0, 0, 4, 2, 2, 3, 1, 21, 3, 102, 179, 243, 246, 20, 31, 15, 8, 64, 98, 100, 50, 33, 16, 16, 24, 8, 5, 4, 37, 239, 214, 96, 112, 64, 0,
0, 0, 0, 0, 0, 0, 0, 56, 0, 0, 0, 0, 0, 0, 128, 128, 160, 112, 112, 192, 240, 224, 192, 224, 96, 64, 64, 127, 0, 160, 0, 0, 64, 0, 128, 128, 64, 128, 0, 192, 64, 127, 0, 15, 143, 128, 128, 255, 128, 0, 2, 3, 7, 7, 6, 2, 3, 2, 2, 2, 2, 198, 252, 1, 3, 3, 3, 255, 255, 253, 5, 9, 130, 248, 14, 7, 12, 13, 6, 3, 2, 255, 3, 6, 252, 159, 0, 15, 30, 31, 22, 26, 8, 132, 26, 16, 32, 48, 43, 63, 5, 1, 33, 177, 105, 33, 47, 48, 96, 64, 72, 98, 98, 90, 128, 192, 144, 246, 130, 130, 146, 2, 194, 209, 67, 124, 64, 0,
0, 0, 0, 0, 0, 0, 148, 0, 0, 0, 0, 0, 0, 0, 254, 3, 3, 2, 2, 2, 2, 2, 2, 2, 150, 2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 2, 2, 2, 2, 2, 3, 3, 67, 1, 1, 0, 0, 0, 2, 3, 3, 2, 18, 16, 16, 16, 16, 16, 144, 208, 144, 243, 255, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 2, 2, 3, 255, 3, 3, 3, 3, 3, 3, 0, 0, 0, 3, 2, 2, 6, 6, 6, 4, 4, 4, 4, 7, 7, 4, 0, 0, 0, 0, 8, 14, 8, 8, 15, 13, 8, 248, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0,
0, 0, 0, 4, 4, 4, 2, 16, 16, 0, 0, 0, 0, 16, 19, 16, 0, 0, 0, 8, 8, 8, 8, 8, 8, 8, 0, 4, 4, 4, 4, 4, 0, 0, 0, 2, 0, 0, 0, 0, 128, 128, 128, 0, 0, 64, 64, 4, 6, 36, 38, 36, 4, 20, 20, 4, 4, 12, 12, 12, 4, 4, 15, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 0, 0, 15, 0, 0, 0, 8, 8, 8, 8, 8, 8, 0, 0, 0, 0, 0, 0, 4, 4, 4, 4, 4, 4, 0, 0, 0, 0, 0, 0, 2, 2, 2, 2, 2, 2, 3, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2
};
//----------------------------------
// LCD Functions
//----------------------------------
void GLCD_Init();
void GLCD_Data(unsigned char);
void GLCD_Comd(unsigned char);
void DelayMs(int);
//----------------------------------
// LCD command Function
//----------------------------------
void GLCD_Comd(unsigned char cmnd)
{
DATA = cmnd; //send command to port
RS = 0; //make it RS to Low
RW = 0; //make it RW to low
lcd_e = 1; //enbale high
DelayMs(10);
lcd_e = 0; //enable low
}
//----------------------------------
// LCD Data Function
//----------------------------------
void GLCD_Data(unsigned char dat)
{
DATA = dat; //send command to port
RS = 1; //make it RS to high
RW = 0; //make it RW to low
lcd_e = 1; //enbale high
DelayMs(10);
lcd_e = 0; //enbale low
}
//----------------------------------
// LCD Delay Function
//----------------------------------
void DelayMs(int k)
{
unsigned int a;
for(a=0;a<=k;a++);
}
//----------------------------------
// GLCD Initialization Function
//----------------------------------
void GLCD_Init()
{
unsigned char Comd[5]={0xc0,0xb8,0x40,0x3f};//LCD Command list
Select_page(1); //send commands to page1
for(i=0;i<4;i++)
GLCD_Comd(Comd[i]);
Select_page(0); //send commands to page0
for(i=0;i<4;i++)
GLCD_Comd(Comd[i]);
}
//----------------------------------
// Page Selection
//----------------------------------
void Select_page(unsigned char Page)
{
if(Page)
{
CS1=0; //Page 0 LCD IC1
CS2=1;
}
else
{
CS1=1; //Page 1 LCD IC2
CS2=0;
}
}
//-------------------------------------
// Display Picture for page0 & page1
//-------------------------------------
void GLCD_PutPicture(const unsigned char *ip) //Change here for method 1,2 and 3
{
int Page=0,i=0;
int Column=0;
for (Page = 0; Page < 8; Page++)
{
Select_page(1); //Display part of image to Page1
GLCD_Comd(0xb8 | Page);
GLCD_Comd(0x40);
for (Column = 0; Column < 128; Column++)
{
if (Column == 64)
{
Select_page(0); //Display part of image to Page0
GLCD_Comd(0xb8 | Page);
GLCD_Comd(0x40);
}
GLCD_Data(*ip++);
}
}
}
//------------------------
// Main Program
//-----------------------
void main(void)
{
long i;
DelayMs(2);
RST = 1;
DelayMs(5);
RST = 0;
DelayMs(5);
RST = 1;
DelayMs(5);
GLCD_Init(); //Initialize GLCD
DelayMs(15);
GLCD_PutPicture(pan_bmp);//Display Image
for(i=0;i<12075;i++);
GLCD_Data("m");
while(1); //wait forever
}
Comments
Post a Comment