/*****************************************************************************
Company :RICH
LCM moudle :2.4"/240*320
MCU :SSD1297
Type :80 system 16-bit bus interface
Note :Crystal:40MHz,Vcc=Vci=2.8V
/*******************************************************************************
Name :SHOW
Function :
Description :2009-04-08 调试
Modefitied :RDT028C0SA00-Sub LCD
Company :
Version :V00
********************************************************************************/
#include<reg52.h>
#define DBH P2
#define DBL P0
#define P4 0xd8
#define red 0xf800
#define green 0x07e0
#define blue 0x001f
#define black 0x0000
#define white 0xffff
#define gr 0x7bef
#define C 0
#define D 1
unsigned char a;
unsigned int pic;
bit Delayflag=0;
//******************************************************************************
void Initial(void);
void writelcm(unsigned int x,bit R);
void WriteRegister(unsigned char RegisterName,unsigned int RegisterValue);
void FillColour(unsigned int Colour);
void FillGray(unsigned int Gray);
void FillSkripe(void);
void Block(void);
void Field(void);
void Photo(unsigned char Number);
bit KeyScan(void);
void AddressSlect(unsigned char Add);
void write_xdata(int erom);
void Delay(unsigned char i);
void dummy();
//******************************************************************************
sbit CS =P1^7;
sbit CE1 =P1^3;
sbit CE2 =P1^4;
sbit OE =P4^0;
sbit RS =P1^6;
sbit W_R =P3^6;
sbit R_D =P3^7;
sbit RES =P3^5;
sbit A16 =P1^0;
sbit A17 =P1^1;
sbit A18 =P1^2;
sbit G =P1^5;
sbit DB0 =P1^4;
sbit DB9 =P3^4;
sbit Key0 =P3^2;
sbit Key1 =P3^3;
sbit Key2 =0xda;
sbit Key3 =0xdb;
void main(void)
{
TMOD=0x01;
Delay(5);
G=0;
RES=1;
Delay(50);
RES=0;
Delay(10);
Initial();
while(1)
{
for(a=1;a<3;a++)
{
WriteRegister(0x44, 0xef00); // Horizontal RAM Address
WriteRegister(0x45, 0x0000); // Vertical RAM Start Address
WriteRegister(0x46, 0x013f); // Vertical GRAM end Address
WriteRegister(0x4e, 0x0000); //X GDDRAM
WriteRegister(0x4f, 0x0000); //Y GDDRAM
writelcm(0x0022,0);
switch(a)
{
case 0:Photo(0);break;
case 1:Photo(1);break;
case 2:Photo(2);break;
case 3:Photo(3);break;
case 4:Photo(4);break;
case 5:FillColour(black);break;
case 6:FillColour(white);break;
case 7:FillColour(red);break;
case 8:FillColour(green);break;
case 9:FillColour(blue);break;
case 10:FillGray(white);break;
case 11:Field();break;
default:break;
}
Delay(100);
}
}
}
//*************************Initial**********************************
void Initial(void)
{
//******************sub lcd initial***************
WriteRegister(0xE5, 0x8000);
WriteRegister(0x28, 0x0006); // enable test command
WriteRegister(0x07, 0x0021);
WriteRegister(0x00, 0x0001); // Start internal OSC
Delay(3);
WriteRegister(0x07, 0x0023);
WriteRegister(0x10, 0x0000); // Sleep mode off
Delay(3);
WriteRegister(0x07, 0x0033); // Display on
WriteRegister(0x01, 0x2b3f); // Driver output control
WriteRegister(0x02, 0x0600); // Set to line inversion
WriteRegister(0x11, 0x6030); // Entry mode setup
WriteRegister(0x03, 0xa6a8); // Step-up factor/cycle setting
WriteRegister(0x0f, 0x0000); // Gate scan position start at G0
WriteRegister(0x0e, 0x3100); // Set alternating amplitude of VCOM
WriteRegister(0x1e, 0x009f); // Set VcomH voltage
WriteRegister(0x0C, 0x0005); // Adjust VCIX2 output voltage
WriteRegister(0x0D, 0x0005); // Set amplitude magnification of VLCD63
WriteRegister(0x0b, 0x5308); // Frame cycle control
// ----------- Special command ----------
WriteRegister(0x25, 0xe000); // Frame freq control
WriteRegister(0x3f, 0xbb84); // System setting
WriteRegister(0x27, 0x0567); // Internal Vcomh/Vcoml timing
WriteRegister(0x20, 0x316c); // Internal VCOM strength
// ----------- Adjust the Gamma Curve ----------
WriteRegister(0x3a, 0x1000);
WriteRegister(0x3b, 0x0008);
WriteRegister(0x30, 0x0007);
WriteRegister(0x31, 0x0003);
WriteRegister(0x32, 0x0300);
WriteRegister(0x33, 0x0101);
WriteRegister(0x34, 0x0707);
WriteRegister(0x35, 0x0002);
WriteRegister(0x36, 0x0503);
WriteRegister(0x37, 0x0202);
WriteRegister(0x3a, 0x1000);
WriteRegister(0x3b, 0x0008);
//------------------ Set GRAM area ---------------
WriteRegister(0x44, 0xef00); // Horizontal RAM Address
WriteRegister(0x45, 0x0000); // Vertical RAM Start Address
WriteRegister(0x46, 0x013f); // Vertical GRAM end Address
WriteRegister(0x4e, 0x0000);
WriteRegister(0x4f, 0x0000);
WriteRegister(0x48, 0x0000);
WriteRegister(0x49, 0x013f);
WriteRegister(0x4a, 0xef00);
WriteRegister(0x4b, 0x013f);
writelcm(0x0022,0); //Write RAM data
}
//*************************Write command& data**************************************
void WriteRegister(unsigned char RegisterName,unsigned int RegisterValue)
{
G=0;
RS=0;
CS=0;
DBH=0;
DBL=RegisterName;
DBH=0;
DBL=RegisterName;
W_R=0;
W_R=0;
W_R=1;
W_R=1;
RS=1;
DBH=RegisterValue>>8;
DBL=RegisterValue;
DBH=RegisterValue>>8;
DBL=RegisterValue;
W_R=0;
W_R=0;
W_R=1;
W_R=1;
RS=1;
CS=1;
}
//******************************************************************************
void writelcm(unsigned int data1,bit di)
{
G=0;
RS=di;
CS=0;
DBH=data1>>8;
DBL=data1;
DBH=data1>>8;
DBL=data1;
W_R=0;
W_R=0;
W_R=1;
W_R=1;
RS=~di;
CS=1;
}
//******************************************************************************
void write_xdata(int erom)//EXTERNAL DATA WRITE SUB
{
RS=1;RS=1;
CS=0;CS=0;
R_D=1;R_D=1;
DBL=erom;
erom>>=8;
DBH=erom;
W_R=1;W_R=1;
W_R=0;W_R=0;
W_R=1;W_R=1;
CS=1;CS=1;
}
//******************************************************************************
/*Function Name ;Key_Test() */
/*Entireness variable :Key_Value */
/*Local variable :None */
/*Description ;This subroutine detects the keyboard and input
the value of the key,then return the key value
to the program which call it. */
bit KeyScan(void)
{
Key0=Key1=Key2=Key3=1;
if((Key0&&Key1&&Key2&&Key3)!=1)
{
TH1=0x90;TL1=0;TF1=0;TR1=1;while(TF1==0); //Delay 30ms
TF1=0;TR1=0;Key0=Key1=Key2=Key3=1;
if((Key0&&Key1&&Key2&&Key3)!=1)
{
if(Key0==0)a=a<4?a:11; //Photo++
else if(Key1==0)
{ //Photo--
if((a>=1)&&(a<=5))
a-=2;
else if(a==0)
a=3;
else a=3;
}
else if(Key2==0)
a=((a>=5)&&(a<11))?a:4; //Picture++
else if(Key3==0)
{ //Picture--
if((a>=6)&&(a<=12))
a-=2;
else if(a==4)
a=10;
else a=10;
}
return 1;
}
} //Keyboard detect faile
else return 0;
}
//******************************************************************************
void Delay(unsigned char times)
{
unsigned char b;
bit key=0;
for(;times>0;times--)
{
b=Delayflag==0?1:20;
for(;b>0;b--)
{
TH0=0x7e;TL0=0x00;TR0=1;
do{key=KeyScan();}while((TF0==0)&&(key==0)); //Delay for 10ms
TF0=0;
if(key==1)
{
times=1;
b=1;
}
}
}
TR0=0;
Delayflag=key;
}
//******************************************************************************
void FillColour(unsigned int Colour)
{
unsigned int x,y;
WriteRegister(0x44, 0xef00); // Horizontal RAM Address
WriteRegister(0x45, 0x0000); // Vertical RAM Start Address
WriteRegister(0x46, 0x013f); // Vertical GRAM end Address
WriteRegister(0x4e, 0x0000); //X GDDRAM
WriteRegister(0x4f, 0x0000); //Y GDDRAM
writelcm(0x0022,C);
for(y=0;y