SSD1963示例程序
/*
本文引用地址:http://m.butianyuan.cn/article/201611/316729.htm****************************************************************************************
* 數(shù)據(jù)類型
*
****************************************************************************************
*/
typedef unsigned char uchar; /* Unsigned 8 bit quantity */
typedef signed char schar; /* Signed 8 bit quantity */
typedef unsigned int uint; /* Unsigned 16 bit quantity */
typedef signed int sint; /* Signed 16 bit quantity */
//===============================
//Da
//===============================
typedef union {
unsigned char UByte[2];
unsigned int UInt;
} UWORD;
void SSD1963Da
void SSD1963Da
void SSD1963Command_16(uint cmd);
void SetPixel(uint Col,uint Page,uint color); //顯示一個相素點
uint GetPixel(uint Col,uint Page);//得到一個像素點
/******************************************************
SSD1963的Conf腳,用來控制讀寫的方式,
如果為0 則為6800總線MODE
如果位1 ,則為8080總線。
下面的定義是8080 MODE(默認(rèn)情況下為8080),可以通過修改Conf 跳點來修改讀寫方式。
******************************************************/
void SSD1963Command_8(uchar cmd);
void SSD1963Da
void SSD1963Init();
uchar GetSSD1963Da
uint GetSSD1963Da
void ReadSSD1963Set();
#define SetSSD1963RD() SetBit(P4,4)
#define SetSSD1963WR() SetBit(P4,5)
#define SetSSD1963CS() SetBit(P4,2)
#define SetSSD1963DC() SetBit(P4,3)
#define SetSSD1963Reset() SetBit(P4,1)
#define SetSSD1963Wait() SetBit(p4,0)
#define ClrSSD1963RD() ClrBit(P4,4)
#define ClrSSD1963WR() ClrBit(P4,5)
#define ClrSSD1963CS() ClrBit(P4,2)
#define ClrSSD1963DC() ClrBit(P4,3)
#define ClrSSD1963Reset() ClrBit(P4,1)
#define ClrSSD1963Wait() ClrBit(p4,0)
#define DataPortL P1
#define DataPortH P2
//UWORD 是一個結(jié)構(gòu)體
//注意在給1963寫命令時,只能用數(shù)據(jù)線的低8位來傳輸數(shù)據(jù)。
void SSD1963Command_16(uint cmd)
{
UWORD temp;
temp.UInt=cmd;
ClrSSD1963DC();
SetSSD1963RD();
ClrSSD1963CS();
ClrSSD1963WR();
DataPortL=temp.UByte[1];
DataPortH=temp.UByte[0];
SetSSD1963WR();
SetSSD1963CS();
}
void SSD1963Da
{
UWORD temp;
temp.UInt=dat;
SetSSD1963DC();
SetSSD1963RD();
ClrSSD1963CS();
ClrSSD1963WR();
DataPortL=temp.UByte[1];
DataPortH=temp.UByte[0];
SetSSD1963WR();
SetSSD1963CS();
}
void SSD1963Da
{
SetSSD1963DC();
SetSSD1963RD();
ClrSSD1963CS();
ClrSSD1963WR();
DataPortL=sdataL;//temp.UByte[1];
DataPortH=sdataH;//temp.UByte[0];
SetSSD1963WR();
SetSSD1963CS();
}
void SSD1963Command_8(uchar cmd)
{
ClrSSD1963DC();
SetSSD1963RD();
ClrSSD1963CS();
ClrSSD1963WR();
DataPortL=cmd;
DataPortH=0X00;
SetSSD1963WR();
SetSSD1963CS();
}
void SSD1963Da
{
SetSSD1963DC();
SetSSD1963RD();
ClrSSD1963CS();
ClrSSD1963WR();
DataPortL=sdata;
DataPortH=0X00;
SetSSD1963WR();
SetSSD1963CS();
}
/*void SSD1963Da
{
SetSSD1963DC();
SetSSD1963RD();
ClrSSD1963WR();
ClrSSD1963CS();
DataPortL=sdataL;
DataPortH=sdataH;
nop();nop();nop(); nop();nop();nop();
SetSSD1963WR();
SetSSD1963CS();
}*/
uchar GetSSD1963Da
{
uchar sdata;
ClrSSD1963RD();
SetSSD1963WR();
SetSSD1963DC();
ClrSSD1963CS();
sdata=DataPortL;
nop();nop();nop();nop();nop();nop();
SetSSD1963RD();
SetSSD1963CS();
return sdata;
}
uint GetSSD1963Da
{
uint sdata;
unsigned char SFRPAGE_save = SFRPAGE; // Save the current SFRPAGE
SFRPAGE = CONFIG_PAGE; //設(shè)置輸入輸出
P1MDOUT=0x00; ///輸出設(shè)置為 高阻
P2MDOUT=0x00;
SFRPAGE = SFRPAGE_save; // Restore the SFRPAGE
P1=0xff;
P2=0xff;
ClrSSD1963RD();
SetSSD1963WR();
SetSSD1963DC();
ClrSSD1963CS();
nop();
nop();
sdata=DataPortH;
sdata=sdata<<8;
sdata|=DataPortL;
SetSSD1963RD();
SetSSD1963CS();
SFRPAGE = CONFIG_PAGE;
P1MDOUT=0xff;//設(shè)置為 上拉 輸出 。
P2MDOUT=0xff;
SFRPAGE = SFRPAGE_save; // Restore the SFRPAGE
return sdata;
}
uint GetPixel(uint Col,uint Page)
{
uint temp;
uint color;
SSD1963Command_8(0x2a); //設(shè)置行開始和結(jié)束的位置
SSD1963Da
SSD1963Da
temp=Col;
SSD1963Da
SSD1963Da
SSD1963Command_8(0x2b);
SSD1963Da
SSD1963Da
temp=Page;
SSD1963Da
SSD1963Da
SSD1963Command_8(0x2E);
color=GetSSD1963Da
return color;
}
void SetPixel(uint Col,uint Page,uint color)
{
uint temp;
SSD1963Command_8(0x2a); //設(shè)置行開始和結(jié)束的位置
temp=Col;
SSD1963Da
SSD1963Da
temp=Col;
SSD1963Da
SSD1963Da
SSD1963Command_8(0x2b);
temp=Page;
SSD1963Da
SSD1963Da
temp=Page;
SSD1963Da
SSD1963Da
SSD1963Command_8(0x2c);
// for(i=0;i<9;i++)
// {
SSD1963Da
// }
}
//初始化程序
void SSD1963Init()
{
//software reset
SSD1963Command_8(0x01);
Delay_Ms(400);
SSD1963Command_8(0x01);
Delay_Ms(400);
//enable pll
SSD1963Command_8(0xe0);
Delay_Ms(400);
SSD1963Da
Delay_Ms(400);
SSD1963Command_8(0xe0);
Delay_Ms(400);
SSD1963Da
Delay_Ms(400);
//pll: n= 34 m= 3
SSD1963Command_8(0xe2);
SSD1963Da
SSD1963Da
SSD1963Da
//dotclk setting
SSD1963Command_8(0xe6);
SSD1963Da
SSD1963Da
SSD1963Da
//panel setting
SSD1963Command_8(0xb0);
Delay_Us(100);
SSD1963Da
SSD1963Da
SSD1963Da
SSD1963Da
SSD1963Da
SSD1963Da
SSD1963Da
//pixel format
SSD1963Command_8(0x3a);
SSD1963Da
//hsync setting
SSD1963Command_8(0xb4);
SSD1963Da
SSD1963Da
SSD1963Da
SSD1963Da
SSD1963Da
SSD1963Da
SSD1963Da
SSD1963Da
//vsync setting
SSD1963Command_8(0xb6);
SSD1963Da
SSD1963Da
SSD1963Da
SSD1963Da
SSD1963Da
SSD1963Da
SSD1963Da
//col start_end
SSD1963Command_8(0x2a);
SSD1963Da
SSD1963Da
SSD1963Da
SSD1963Da
//row start_end
SSD1963Command_8(0x2b);
SSD1963Da
SSD1963Da
SSD1963Da
SSD1963Da
SSD1963Command_8(0x36);
SSD1963Da
//MCU IF setting
//SSD1963Command_8(13);
SSD1963Command_8(0xf0);
SSD1963Da
//SSD1963Command_8(0x35);
//display on
SSD1963Command_8(0x29);
SSD1963Command_8(0xbe);//設(shè)置PWM
SSD1963Da
SSD1963Da
SSD1963Da
SSD1963Da
SSD1963Da
SSD1963Da
SSD1963Command_8(0xD4);//(Define the threshold value)
SSD1963Da
SSD1963Da
SSD1963Da
SSD1963Da
SSD1963Da
SSD1963Da
SSD1963Da
SSD1963Da
SSD1963Da
SSD1963Command_8(0xd0);
SSD1963Da
// ReadSSD1963Set();
}
評論