?? sed1335.c
字號:
//============================================================================
// Header: SED1335驅動320x240圖形液晶驅動程序
// Author: wjxiao
// Date: 2005-08-15
//============================================================================
#include <C8051F020.h>
//#include <CharInt.h>
#include <intrins.h>
#include <string.h>
#include <font.c>
#include <Asc16x24.c>
#include <ASc16x16.c>
#include <ASc8x16.c>
//============================================================================
// 地址定義
//----------------------------------------------------------------------------
uchar bdata lcd_cbus;
sbit WR = lcd_cbus^3;
sbit RD = lcd_cbus^4;
sbit CS = lcd_cbus^5;
sbit A0 = lcd_cbus^6;
sbit RES = lcd_cbus^7;
//============================================================================
#define SystemSet 0x40 // 初始化設置,后續8字節參數串ParaSysTable8[]
uchar code ParaSysTable8[] = // P1-P8參數
{
0x30,0x87,0x07,0x27,0x42,0xf0,0x28,0x00
};
//----------------------------------------------------------------------------
#define Scroll 0x44 // 顯示域設置,后續10字節參數串ParaScrTableA[]
#define BasePart1 0x00
#define BasePart2 0x28
#define BasePart3 0x28*2
#define BasePart4 0x00
uchar code ParaScrTableA[] =
{
0x00,BasePart1,0xF0,0x00,BasePart2,0xF0,0x00,BasePart3,0x00,BasePart4
};
//----------------------------------------------------------------------------
#define SleepIn 0x53 // 休閑模式設置 后續參數:無
#define DispOn 0x59 // 顯示狀態設置 后續參數1字節
#define DispOff 0x58
#define HdotScr 0x5a // 點位移設置 后續參數1字節
#define Ovlay 0x5b // 顯示合成方式設置 后續參數1字節
#define CgramAdr 0x5c // Cgram首地址設置 后續參數2字節
#define CsrForm 0x5d // 光標形狀設置 后續參數2字節
#define CsrDirR 0x4c // 光標移動方向設置 后續參數:無
#define CsrDirL 0x4d
#define CsrDirU 0x4e
#define CsrDirD 0x4f
#define CsrW 0x46 // 光標指針設置 后續參數2字節
#define CsrR 0x47 // 讀取光標指針 后續參數2字節
#define mWrite 0x42 // 數據寫入設置 后續參數N字節
#define mRead 0x43 // 數據讀取設置 后續參數N字節
//==============================================================================
#define Busy 0x40 // 忙狀態標志位0b0100 0000
#define paraP9 40 // 相對于320 X 240
//==============================================================================
void WriteData( uchar dataW );
void WriteCommand( uchar CommandByte );
void LcmClear( uchar port );
void Locatexy(uchar x,uchar y, uchar attribs);
void PutStr24( uchar Port, uchar x, uchar y, char *ptr, uchar len, bit attr );
void PutStr16( uchar Port, uchar x, uchar y, char *ptr, uchar len, bit attr );
void PutStr32( uchar Port, uchar x, uchar y, char *ptr, uchar len, bit attr );
//============================================================================
// 寫指令代碼子程序
//----------------------------------------------------------------------------
#define databus P7
void WriteCommand( uchar Command )
{
P74OUT = 0xf3;
CS = 0;
A0 = 1;
RD = 1;
WR = 0;
P6 = lcd_cbus;
databus = Command;
WR = 1;
CS = 1;
P6 = lcd_cbus;
}
//============================================================================
// 寫參數及顯示數據子程序
//----------------------------------------------------------------------------
void WriteData( uchar dataW )
{
P74OUT = 0xf3;
A0 = 0;
RD = 1;
WR = 0;
CS = 0;
P6 = lcd_cbus;
databus = dataW;
WR = 1;
CS = 1;
P6 = lcd_cbus;
}
//============================================================================
// 讀參數及顯示數據子程序
//----------------------------------------------------------------------------
uchar ReadDataLcm( void )
{
uchar dataD;
P74OUT = 0x33;
P7 = 0xff;
A0 = 1;
WR = 1;
RD = 0;
CS = 0;
P6 = lcd_cbus;
_nop_();
_nop_();
_nop_();
_nop_();
dataD = databus;
RD = 1;
CS = 1;
P6 = lcd_cbus;
return dataD;
}
//============================================================================
// 初試化
//----------------------------------------------------------------------------
void LcmInition( void )
{
uchar i;
RES = 1;
WriteCommand( SystemSet ); // 系統參數設置
for (i=0;i<8;i++)
{
WriteData( ParaSysTable8[i] );
}
WriteCommand( Scroll ); // 設定顯示區域起始地址
for (i=0;i<10;i++)
{
WriteData( ParaScrTableA[i] );
}
WriteCommand( HdotScr ); // 寫入點位移指令代碼
WriteData( 0 ); // 寫入P1參數
WriteCommand( Ovlay ); // 顯示合成方式設置
WriteData( 0x0d ); // 顯示一區圖形,三區圖形屬性,二重"異或"合成
WriteCommand( DispOn ); // 寫入指令代碼
WriteData( 0x14 ); // 顯示 1~4 區開顯示,光標關顯示
}
//============================================================================
// 光標位定位,圖形方式下
// (1) x: 水平方向字節單位坐標
// (2) y: 垂直方向以行線定位的坐標
// (3) 左上角約定坐標為( 0, 0 )
//----------------------------------------------------------------------------
void Locatexy(uchar port, uchar x,uchar y)
{
uint temp;
temp = (uint)y*paraP9 + x;
WriteCommand( CsrW ); // 光標Locate,定位
WriteData( (uchar)(temp & 0xff) ); // 寫入參數CSRL設置參數光標指針低8位
WriteData( (uchar)( (temp >>8 ) + 0x28 * port) ); // 寫入參數CSRH設置參數光標指針高8位
}
//============================================================================
// 清屏 port 區
//----------------------------------------------------------------------------
void LcmClear( uchar port )
{
uint i = 40*240;
WriteCommand( CsrDirR ); // 光標自動右移
Locatexy( port,0,0 );
WriteCommand( mWrite ); // 數據寫入指令,代碼0x42
while(i--)
WriteData( 0 );
}
//============================================================================
// 顯示中西文混合字符串
// (1) uchar port : 顯示區
// (2) uchar x : 水平方向字節單位坐標
// (3) uchar y : 垂直方向以行線定位的坐標
// (4) uchar * Str : 字符串指針,以 \0 結尾
// (5) uchar LibName : 字庫名(指針號)
// (6) bit attr : 0 - 正常
// 1 - 反白
//----------------------------------------------------------------------------
void PutStr( uchar Port,uchar x,uchar y,char * Str,uchar LibName, bit attr)
{
// 相對于ASCII,漢字為□字
#define Dot8 0
#define Dot16 1
#define Dot24 2
#define Dot32 3
#define ascii8 1, 16
#define ascii16 2, 16
#define ascii24 2, 24
#define ascii32 0, 0
#define gb8 0, 0
#define gb16 2, 16
#define gb24 3, 24
#define gb32 4, 32
uchar i,j,k;
char ASC_GB;
char code *p;
struct
{
uchar byte;
uchar high;
} lattice[][4] =
{
{ // ASCII字庫
ascii8 ,
ascii16 ,
ascii24 ,
ascii32 ,
},
{
gb8 ,
gb16 ,
gb24 ,
gb32 ,
}
};
WriteCommand( CsrDirD ); // 光標自動下移
for( i=0;i<strlen(Str);i++)
{
uchar c1,c2;
c1 = Str[i];
c2 = Str[i+1];
//--------------------------------------------------------------------
if(c1 <=128) // ASCII
{
ASC_GB = 0;
switch(LibName)
{
case Dot8:
j = Str[i]-0x20;
p = Asc8x16[j];
break;
case Dot16:
for(j=0;j<sizeof(Asc16x16)/sizeof(Asc16x16[0]);j++) // 查找定位
if( c1 == Asc16x16[j].Index[0] ) break;
p = Asc16x16[j].Msk;
break;
case Dot24:
for(j=0;j<sizeof(Asc16x24)/sizeof(Asc16x24[0]);j++) // 查找定位
if( c1 == Asc16x24[j].Index[0] ) break;
p = Asc16x24[j].Msk;
break;
}
}
else // 漢字
{
ASC_GB = 1;
switch(LibName)
{
case Dot16:
for(j=0;j<sizeof(GB16)/sizeof(GB16[0]);j++) // 查找定位
if( c1 == GB16[j].Index[0] &&
c2 == GB16[j].Index[1] )
break;
p = GB16[j].Msk;
break;
case Dot24:
for(j=0;j<sizeof(GB24)/sizeof(GB24[0]);j++) // 查找定位
if( c1 == GB24[j].Index[0] &&
c2 == GB24[j].Index[1] )
break;
p = GB24[j].Msk;
break;
case Dot32:
for(j=0;j<sizeof(GB32)/sizeof(GB32[0]);j++) // 查找定位
if( c1 == GB32[j].Index[0] &&
c2 == GB32[j].Index[1] )
break;
p = GB32[j].Msk;
break;
}
}
for(j=0;j<lattice[ASC_GB][LibName].byte;j++) // 分列輸出
{
Locatexy(Port,x,y);
WriteCommand( mWrite ); // 寫數據(命令)
for(k=0;k<lattice[ASC_GB][LibName].high;k++)
{
uchar dat;
dat = *p++;
if(attr) dat = ~dat;
WriteData(dat);
}
x++; // 列數加1
}
if(ASC_GB) i++;
}
}
//============================================================================
// 顯示 顯示光標
//----------------------------------------------------------------------------
void DispCursor(uchar x, uchar y, uchar byte, uchar High, bit attr )
{
uchar i,j;
WriteCommand( CsrDirD );
for(i=0;i<byte;i++) // 分列輸出
{
Locatexy(1,x+i,y);
WriteCommand( mWrite ); // 寫數據(命令)
for(j=0;j<High;j++)
if(attr) WriteData( 0xff );
else WriteData( 0x00 );
}
}
//=====================================================================================
// 繪點子程序,攜入參數X坐標的最高位決定寫或擦點
// ====================================================
void Point(uchar port, uint Px, uchar Py, bit attr )
{
uint tempPtr;
uchar tempD,tempP;
tempPtr = (uint)Py * paraP9 + Px / 8;
WriteCommand( CsrDirD ); // CSRDIR 代碼(光標自動下移)
WriteCommand( CsrW ); // 設置光標地址
WriteData( (uchar)(tempPtr & 0xff) );
WriteData( (uchar)(tempPtr /256) + 0x28 * port );
WriteCommand( mRead ); // 讀顯示ram指令
//Delay(50);
tempD = ReadDataLcm(); // 讀取當前顯示數據
tempP = 1<<(uchar)(7-Px & 0x0007);
// 根據預定屬性決定寫點或擦除
if( attr )tempD |= tempP; // 畫點
else tempD &= ~tempP; // 消點
WriteCommand( CsrW ); // 重新設置光標地址
WriteData( (uchar)(tempPtr & 0xff) );
WriteData( (uchar)(tempPtr /256) + 0x28 * port );
WriteCommand( mWrite ); // 代碼0x42,數據寫入指令
WriteData( tempD ); // 寫入合成數據
}
/********************************************/
/*畫線。任意方向的斜線,直線數學方程 aX+bY=1 */
/********************************************/
// 參數類型有待修改
void Linexy(uchar port, uint x0,uchar y0,uint xt,uchar yt,bit att)
{
register uint t;
int xdata xerr=0,yerr=0,delta_x,delta_y,distance;
int xdata incx,incy;
uint row,col;
delta_x = xt-x0; //計算坐標增量
delta_y = yt-y0;
col = x0;
row = y0;
if(delta_x>0) incx=1; //設置單步方向
else
{
if( delta_x==0 ) incx=0; //垂直線
else {incx=-1;delta_x=-delta_x;}
}
if(delta_y>0) incy=1;
else
{
if( delta_y==0 ) incy=0; //水平線
else {incy=-1;delta_y=-delta_y;}
}
if( delta_x > delta_y ) distance=delta_x; //選取基本增量坐標軸
else distance=delta_y;
for( t=0;t <= distance+1; t++ )
{ //畫線輸出
Point(port,(uint)col,row,att); //畫點
xerr += delta_x ;
yerr += delta_y ;
if( xerr > distance )
{
xerr-=distance;
col+=incx;
}
if( yerr > distance )
{
yerr-=distance;
row+=incy;
}
}
}
//======================================================================
// 矩形
void Rectangle(uchar port, uint x0, uchar y0, uint x1, uchar y1, bit attr)
{
Linexy(port, x0, y0, x1, y0, attr);
Linexy(port, x1, y0, x1, y1, attr);
Linexy(port, x1, y1, x0, y1, attr);
Linexy(port, x0, y1, x0, y0, attr);
}
void PortXCH(bit XCH) // 交換1、3顯示區
{
uchar i;
uchar code ParaScrTableA[][10] =
{
0x00,0x00, 0xF0,0x00,0x28,0xF0,0x00,0x28*2,0x00,0 ,
0x00,0x28*2,0xF0,0x00,0x28,0xF0,0x00,0x00, 0x00,0 ,
};
WriteCommand( 0x44 ); //設定顯示區域起始地址
for (i=0;i<10;i++)
WriteData( ParaScrTableA[XCH][i] );
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -