?? t6963液晶驅(qū)動(5行漢字).c
字號:
#include "extern.h"
#include "fontlib.h"//顯示字符庫。
#include <stdarg.h>
#include <stdio.h>
// T6963C 命令定義
#define LC_ADD_POS 0x24 // 地址指針位置
#define LC_TXT_STP 0x40 // 文本區(qū)首址
#define LC_TXT_WID 0x41 // 文本區(qū)寬度
#define LC_GRH_STP 0x42 // 圖形區(qū)首址
#define LC_GRH_WID 0x43 // 圖形區(qū)寬度
#define LC_MOD_OR 0x80 // 顯示方式:邏輯“或”
#define LC_MOD_XOR 0x81 // 顯示方式:邏輯“異或”
#define LC_MOD_AND 0x82 // 顯示方式:邏輯“與”
#define LC_MOD_TCH 0x83 // 顯示方式:文本特征
#define LC_DIS_SW 0x90 // 顯示開關(guān):D0=1/0:光標(biāo)閃爍啟用/禁用;
// D1=1/0:光標(biāo)顯示啟用/禁用;
// D2=1/0:文本顯示啟用/禁用;
// D3=1/0:圖形顯示啟用/禁用;
#define LC_CUR_SHP 0xA0 // 光標(biāo)形狀選擇:0xA0-0xA7 表示光標(biāo)占的行數(shù)
#define LC_AUT_WR 0xB0 // 自動寫設(shè)置
#define LC_AUT_RD 0xB1 // 自動讀設(shè)置
#define LC_AUT_OVR 0xB2 // 自動讀/寫結(jié)束
#define LC_INC_WR 0xC0 // 數(shù)據(jù)一次寫,地址加1
#define LC_INC_RD 0xC1 // 數(shù)據(jù)一次讀,地址加1
#define LC_DEC_WR 0xC2 // 數(shù)據(jù)一次寫,地址減1
#define LC_DEC_RD 0xC3 // 數(shù)據(jù)一次讀,地址減1
#define LC_NOC_WR 0xC4 // 數(shù)據(jù)一次寫,地址不變
#define LC_NOC_RD 0xC5 // 數(shù)據(jù)一次讀,地址不變
#define LC_SCN_RD 0xE0 // 屏讀
#define LC_SCN_CP 0xE8 // 屏拷貝
#define LC_BIT_OP 0xF0 // 位操作:D0-D2:定義D0-D7 位;D3:1 置位;0:清除
char gCurRow=0,gCurCol=0,revfonthead=0,revfontnum=0;
char busyRCMD(void)
{
char cmd;
D_PDIR=0x00;
CD_1; CE_0; RD_0;
cmd=D_PIN;
RD_1; CE_1;
D_PDIR=0xff;
return(cmd);
}
void busyWCMD(char cmd)
{
CD_1; CE_0;
D_POUT=cmd;
WR_0;WR_1;CE_1;
}
void busyWDAT(char data)
{
CD_0;CE_0;
D_POUT=data;
WR_0;WR_1;CE_1;
}
char GetSTA(char n)
{
char i;
for(i=5;i>0;i--){ if((busyRCMD() & n) == n) break;}
return i;
}
char WrCMD2(char uCmd,char uPar1,char uPar2)
{
if ( GetSTA(0x03) == 0 ) return 1;
busyWDAT(uPar1);
if ( GetSTA(0x03) == 0 ) return 2;
busyWDAT(uPar2);
if ( GetSTA(0x03) == 0 ) return 3;
busyWCMD(uCmd);
return 0;
}
char WrCMD0(char uCmd)
{
if( GetSTA(0x03) == 0 ) return 1;
busyWCMD(uCmd);
return 0;
}
char WrData(char uData)
{
if(GetSTA(0x08) == 0) return 1;
busyWDAT(uData);
return 0;
}
//****************設(shè)置光標(biāo)(行0~63,列0~15)************************//
void SetPos(char urow, char ucol)
{
unsigned int iPos;
gCurRow = urow+(ucol/16)*16;
gCurCol = ucol%16;
iPos = gCurRow * 30 + gCurCol;
WrCMD2(LC_ADD_POS,iPos & 0xFF,iPos / 256);
}
//****************清行(首行0~63,尾行0~15)*********************//
void ClrFromTo(char x0,char y0)
{
int length,i;
char x=x0,y=y0;
length=y-x;
length*=30;
SetPos(x,0);
WrCMD0(LC_AUT_WR);
for(i=0;i<length;i++)
{
while(GetSTA(0x08)== 0);
WrData(0x00);
}
WrCMD0(LC_AUT_OVR);
}
//**************** 清屏 *********************//
void Cls(void)
{
ClrFromTo(0,64);
WrCMD2(LC_ADD_POS,0x00,0x00);
gCurRow = 0;
gCurCol = 0;
}
//**************** T6963初始化 *********************//
char LcmInit(void)
{
if(WrCMD2(LC_TXT_STP,0x00,0x00) != 0) return 0xff;
WrCMD2(LC_TXT_WID,0x1E,0x00);
WrCMD2(LC_GRH_STP,0x00,0x00);
WrCMD2(LC_GRH_WID,0x1E,0x00);
WrCMD0(LC_CUR_SHP | 0x01);
WrCMD0(LC_MOD_OR);
WrCMD0(LC_DIS_SW | 0x08);
return 0;
}
//*********** 反顯光標(biāo)設(shè)置(反顯字節(jié)相對當(dāng)前光標(biāo)首位置,反顯字節(jié)個數(shù)) **********//
void RevPos(char head,char num){revfonthead=head;revfontnum=num;}
//**************** 文字顯示 *********************//
// 通過RevPos設(shè)置反顯文字
// 程序調(diào)用vsprintf(),顯示符點(diǎn)數(shù),prinf formatter 應(yīng)設(shè)為large
// 僅用于顯示1行數(shù)據(jù)。
void Dprintf(char disprow,char dispcol,char *fmt, ...)
{
va_list arg_ptr;
signed char c1,c2,stype[22],type;
char tmpBuf[69];
char const *pcstr[22];
char i=0,j,k,uLen,byte;
char temprevnum;
va_start(arg_ptr, fmt);
uLen = (char)vsprintf(tmpBuf, fmt, arg_ptr);
va_end(arg_ptr);
if(uLen>69)while(1);//error
if(uLen>22)uLen=22;//overflow a line
while(i<uLen)
{
c1 = tmpBuf[i];
c2 = tmpBuf[i+1];
stype[i]=c1;
if(c1 >= 0)//字符
{
if(c1 < STARTNUM)pcstr[i] = ASC_MSK;
else pcstr[i]=&ASC_MSK[(c1-STARTNUM)*12];
i++;
}
else //漢字
{
pcstr[i]=ASC_MSK;
pcstr[i+1]=ASC_MSK;
stype[i+1]=0;
for(j=0;j<sizeof(GB_16)/sizeof(GB_16[0]);j++)//查找漢字
{
if(c1 == GB_16[j].Index[0] && c2 == GB_16[j].Index[1])
{
pcstr[i]=GB_16[j].Msk;
pcstr[i+1]=pcstr[i]+12;
break;
}
}
i+=2;
}
}
for(i=0;i<ASC_CHR_HEIGHT;i++)
{
k=0;
temprevnum=revfontnum;
SetPos(disprow,dispcol);
for(j=0;j<uLen;j++)
{
type=stype[j];
byte=*pcstr[j]++;
if( temprevnum && revfonthead <= j+1)
{
byte = ~byte;
temprevnum--;
}
if(type)
{
tmpBuf[k++]=byte & 0xC0; byte <<= 2;
tmpBuf[k++]=byte & 0xC0; byte <<= 2;
tmpBuf[k++]=byte & 0xC0; byte <<= 2;
if(type<0)tmpBuf[k++]=byte & 0xC0;
}
else
{
tmpBuf[k++]=byte & 0xC0; byte <<= 2;
tmpBuf[k++]=byte & 0xC0; byte <<= 2;
}
}
j=k/4;if(k%4)j++;
tmpBuf[k++]=0;tmpBuf[k++]=0;tmpBuf[k]=0;
WrCMD0(LC_AUT_WR);
for(k=0;k<j;k++)
{
byte=tmpBuf[k*4]+tmpBuf[k*4+1]/4+tmpBuf[k*4+2]/16+tmpBuf[k*4+3]/64;
WrData(byte);
}
WrCMD0(LC_AUT_OVR);
disprow++;
}
}
?? 快捷鍵說明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -