?? 240160b.c
字號:
// 函數:void LcdClr(void)
//-----------------------------------------------------------------------------
/******************************************************************************
調用方式(Function):LcdClr()
函數描述(Description):清顯示 32K RAM區(清屏)子程序
入口參數(Parameters):無
返回值(Returns):無
創建時間:16:07,PM,2004.4.19
修改時間:無
修改原因:無
******************************************************************************/
void LcdClr(void){
Uint i1=32768;
WriteCmd( 0x4c ); // 光標移動方向定義:自動右移0x4c
WriteCmd( 0x46 ); // 光標Locate,定位0x46
WriteData( 0 ); // 寫入參數CSRL設置參數光標指針低8位
WriteData( 0 ); // 寫入參數CSRH設置參數光標指針高8位
WriteCmd( 0x42 ); // 數據寫入指令,代碼0x42
while(i1--) WriteData( 0x00); // 寫入數據0
}
//-----------------------------------------------------------------------------
// 函數:void Locatexy(Uchar x,Uchar y)
//-----------------------------------------------------------------------------
/******************************************************************************
調用方式(Function):Locatexy(x,y)
函數描述(Description):光標位定位,用于在1區圖形方式下
入口參數(Parameters):
x...水平方向字節單位坐標,即可以以半個漢字寬度設定水平坐標
取值范圍:0...39
y...垂直方向以行線定位的坐標,可以定位到點單位
取值范圍:0...239
左上角約定坐標為(0,0)
返回值(Returns):無
創建時間:16:07,PM,2004.4.20
修改時間:無
修改原因:無
******************************************************************************/
void Locatexy(Uchar x,Uchar y) {
Uint temp;
temp = (Uint)y*paraP9+x;
WriteCmd( CsrW ); // 光標Locate,定位
WriteData( (Uchar)(temp & 0xff) ); // 寫入參數CSRL設置參數光標指針低8位
WriteData( (Uchar)(temp /256 ) ); // 寫入參數CSRH設置參數光標指針高8位
}
//-----------------------------------------------------------------------------
// 函數:Uchar dprintf(Uchar x,Uchar y,char code *ptr,bit attrib)
//-----------------------------------------------------------------------------
/******************************************************************************
調用方式(Function):dprintf(x,y,*ptr,attrib)
函數描述(Description):ASCII(8*16) 及 漢字(16*16) 混合字符串顯示函數
入口參數(Parameters):
x,y顯示字符串的左上角xy坐標
x...8點一字節位置,取值范圍:0...29
y...一條掃描線定位,取值范圍:0...159
*ptr...字符串指針,本函數所指的是flash字串
attrib:屬性參數,為0:反顯;為:1正常顯示
返回值(Returns):輸出字串長度,留意漢字一個算兩個
其它假定:調用時漢字必須在字庫數組中已經存在,否則將輸出不正確的結果
創建時間:16:07,PM,2004.4.20
修改時間:無
修改原因:無
******************************************************************************/
/********************************************************/
/* ASCII(8*16) 及 漢字(16*16) 顯示函數 */
/********************************************************/
Uchar dprintf(Uchar x,Uchar y,char code *ptr,bit attrib)
{
Uchar c1,c2;
Uchar i,j,uLen,uRow,uCol,temp;
Uint k;
uRow = x;
uCol = y;
uLen=0;
WriteCmd( CsrDirD ); // 光標移動方向定義:自動下移
Locatexy(uRow,uCol); //起點定位
while ( (Uchar)ptr[uLen] >= 0x10 ){uLen++;}; //探測字串長度
i=0;
while(i<uLen)
{
c1 = ptr[i];
c2 = ptr[i+1];
//ascii字符與漢字內碼的區別在于128做分界,大于界線的為漢字碼
if(c1 <=128) // ASCII
{
if (c1 >= 0x10) {
WriteCmd( mWrite ); // 寫數據(命令)
for(j=0;j<16;j++)
if(attrib)WriteData( ASC_MSK[(c1-0x20)*16 +j ]);
else WriteData(~(ASC_MSK[(c1-0x20)*16 +j ]));
}
uRow++; // 列數加1
}
else // 中文
{
for(j=0;j<sizeof(Cdotlib)/sizeof(Cdotlib[0]);j++) // 查找定位
{
if((c1 == Cdotlib[j].Index[0]) && (c2 == Cdotlib[j].Index[1]))
break;
}
for(k=0;k<2;k++) // 分16行輸出
{
Locatexy(uRow+k,uCol);
WriteCmd( mWrite ); // 寫數據(命令)
for(temp=0;temp<16;temp++)
if(attrib) WriteData( Cdotlib[j].Msk[temp*2 + k]);
else WriteData(~( Cdotlib[j].Msk[temp*2 + k]));
}
uRow +=2; // 光標右移一大格
i++;
}
if(uRow >= 30) // 光標后移,原來為40
{
uCol += 16;
uRow = 0;
if( uCol >= 160 ) uCol = 0; //共有160點行
}
Locatexy(uRow,uCol);
i++;
}
return uLen; //返回字串長度,漢字按2字節計算
}
//x...8點一字節位置,取值范圍:0...29
//y...一條掃描線定位,取值范圍:0...159
void MyGraph(Uchar x,Uchar y,Uchar Weight,Uchar Height,Uchar code *ptr,bit attrib){
Uchar uRow,uCol,temp,nbyte;
Uint k;
uRow = x;
uCol = y;
WriteCmd( CsrDirD ); // 光標移動方向定義:自動下移
Locatexy(uRow,uCol); //起點定位
nbyte=(Uchar)(Weight/8);
for(k=0;k<nbyte;k++) // 分16行輸出
{
Locatexy(uRow+k,uCol);
WriteCmd( mWrite ); // 寫數據(命令)
for(temp=0;temp<Height;temp++)
if(attrib) WriteData(ptr[temp*nbyte+k]);
else WriteData(~(ptr[temp*nbyte+k]));
}
}
/*====================================================
; 繪點子程序,攜入參數X坐標的最高位決定寫或擦點
====================================================*/
void Point(Uint Px,Uchar Py,Uchar attr){
Uint tempPtr;
Uchar tempD,tempP;
tempPtr = (Uint)Py * paraP9 + (Px & 0x7fff)/8; // 去除最高位(顯示屬性)
WriteCmd( CsrDirD ); // CSRDIR 代碼(光標自動下移)
WriteCmd( CsrW ); // 設置光標地址
WriteData( (Uchar)(tempPtr & 0xff) );
WriteData( (Uchar)(tempPtr /256) );
WriteCmd( mRead ); // 讀顯示ram指令
tempD = ReadfromLcd(); // 讀取當前顯示數據
tempP = 1<<(Uchar)(7-Px & 0x0007);
// 根據預定屬性決定寫點或擦除
if( attr )tempD |= tempP; // 畫點
else tempD &= ~tempP; // 消點
WriteCmd( CsrW ); // 重新設置光標地址
WriteData( (Uchar)(tempPtr & 0xff) );
WriteData( (Uchar)(tempPtr /256) );
WriteCmd( mWrite ); // 代碼0x42,數據寫入指令
WriteData( tempD ); // 寫入合成數據
}
void SYSCLK_Init(void){
Uchar i; // delay counter
OSCXCN = 0x66; // start external oscillator with
// 22.1184MHz crystal
for (i=0; i < 254; i++) ; // wait for osc to start
while (!(OSCXCN & 0x80)) ; // Wait for crystal osc. to settle
OSCICN = 0x88; // select external oscillator as SYSCLK
// source and enable missing clock
// detector
}
void PORT_Init(void)
{
XBR0=0x00; // 1:Enable; UART0,SMBUS
XBR1=0x00;
XBR2=0x40; // Enable crossbar and weak pull-ups
P0MDOUT |=0xf0; // enable P07~P04 as push-pull outputs,4個按鍵(P03~P00)為開漏
P1MDOUT |=0xff; // enable P1 as push-pull outputs
P2MDOUT |=0xfc; //0xfc // enable P27~P22 as push-pull outputs,P21(SCLK),P20(SDA)配置為開漏
P3MDOUT |=0x3f; // // enable P3.5~P3.0 as push-pull outputs,P3.7(IRQ),P3.6(Ctime)為開漏
P74OUT |=0xf3; // //
}
void main(void){
WDTCN = 0xde; // disable watchdog timer
WDTCN = 0xad;
SYSCLK_Init(); // 切換到外部晶振
// OSCICN=0x14; // 內部晶振16M運行,2M:0x14;4M:0x15;8M:0x16;16M:0x17
PORT_Init(); // 端口初始化
LcdInit();
LcdClr();
EL_ON=1; //開背光
dprintf(0,50,"2004/04/25重慶東電",0);
MyGraph(23,111,48,48,Ico_RP,1); //顯示一副圖片
while(1);
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -