12864液晶屏驱动程序分享
#include《absacc.h》
#include《reg52.h》
#include《stdarg.h》
#include《stdio.h》
#defineulongunsignedlong
#defineuintunsignedint
#defineucharunsignedchar
#defineSTX0x02
#defineETX0x03
#defineEOT0x04
#defineENQ0x05
#defineBS0x08
#defineCR0x0D
#defineLF0x0A
#defineDLE0x10
#defineETB0x17
#defineSPACE0x20
#defineCOMMA0x2C
#defineTRUE1
#defineFALSE0
#defineHIGH1
#defineLOW0
//T6963C端口定义
#defineLCMDWXBYTE[0x5000]//数据口
#defineLCMCWXBYTE[0x5002]//命令口
//T6963C命令定义
#defineLC_CUR_POS0x21//光标位置设置
#defineLC_CGR_POS0x22//CGRAM偏置地址设置
#defineLC_ADD_POS0x24//地址指针位置
#defineLC_TXT_STP0x40//文本区首址
#defineLC_TXT_WID0x41//文本区宽度
#defineLC_GRH_STP0x42//图形区首址
#defineLC_GRH_WID0x43//图形区宽度
#defineLC_MOD_OR0x80//显示方式:逻辑“或”
#defineLC_MOD_XOR0x81//显示方式:逻辑“异或”
#defineLC_MOD_AND0x82//显示方式:逻辑“与”
#defineLC_MOD_TCH0x83//显示方式:文本特征
#defineLC_DIS_SW0x90//显示开关:D0=1/0:光标闪烁启用/禁用;
//D1=1/0:光标显示启用/禁用;
//D2=1/0:文本显示启用/禁用;
//D3=1/0:图形显示启用/禁用;
#defineLC_CUR_SHP0xA0//光标形状选择:0xA0-0xA7表示光标占的行数
#defineLC_AUT_WR0xB0//自动写设置
#defineLC_AUT_RD0xB1//自动读设置
#defineLC_AUT_OVR0xB2//自动读/写结束
#defineLC_INC_WR0xC0//数据一次写,地址加1
#defineLC_INC_RD0xC1//数据一次读,地址加1
#defineLC_DEC_WR0xC2//数据一次写,地址减1
#defineLC_DEC_RD0xC3//数据一次读,地址减1
#defineLC_NOC_WR0xC4//数据一次写,地址不变
#defineLC_NOC_RD0xC5//数据一次读,地址不变
#defineLC_SCN_RD0xE0//屏读
#defineLC_SCN_CP0xE8//屏拷贝
#defineLC_BIT_OP0xF0//位操作:D0-D2:定义D0-D7位;D3:1置位;0:清除
codeucharconstuPowArr[]={0x01,0x02,0x04,0x08,0x10,0x20,0x40,0x80};
//ASCII字模宽度及高度定义
#defineASC_CHR_WIDTH8
#defineASC_CHR_HEIGHT12
//ASCII字模,显示为8*16
charcodeASC_MSK[96*12]={
//Terminal9;此字体下对应的点阵为:宽x高=8x12
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xff,0xff,0xff,0xff,0xff,//《0x20时,打印此字
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,//‘’
0x00,0x0C,0x1E,0x1E,0x1E,0x0C,0x0C,0x00,0x0C,0x0C,0x00,0x00,//‘!’
0x00,0x66,0x66,0x66,0x24,0x00,0x00,0x00,0x00,0x00,0x00,0x00,//‘“’
0x00,0x36,0x36,0x7F,0x36,0x36,0x36,0x7F,0x36,0x36,0x00,0x00,//‘#’
0x0C,0x0C,0x3E,0x03,0x03,0x1E,0x30,0x30,0x1F,0x0C,0x0C,0x00,//‘$’
0x00,0x00,0x00,0x23,0x33,0x18,0x0C,0x06,0x33,0x31,0x00,0x00,//‘%’
0x00,0x0E,0x1B,0x1B,0x0E,0x5F,0x7B,0x33,0x3B,0x6E,0x00,0x00,//‘&’
0x00,0x0C,0x0C,0x0C,0x06,0x00,0x00,0x00,0x00,0x00,0x00,0x00,//‘’‘
0x00,0x30,0x18,0x0C,0x06,0x06,0x06,0x0C,0x18,0x30,0x00,0x00,//’(‘
0x00,0x06,0x0C,0x18,0x30,0x30,0x30,0x18,0x0C,0x06,0x00,0x00,//’)‘
0x00,0x00,0x00,0x66,0x3C,0xFF,0x3C,0x66,0x00,0x00,0x00,0x00,//’*‘
0x00,0x00,0x00,0x18,0x18,0x7E,0x18,0x18,0x00,0x00,0x00,0x00,//’+‘
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x1C,0x1C,0x06,0x00,//’,‘
0x00,0x00,0x00,0x00,0x00,0x7F,0x00,0x00,0x00,0x00,0x00,0x00,//’-‘
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x1C,0x1C,0x00,0x00,//’。‘
0x00,0x00,0x40,0x60,0x30,0x18,0x0C,0x06,0x03,0x01,0x00,0x00,//’/‘
0x00,0x3E,0x63,0x73,0x7B,0x6B,0x6F,0x67,0x63,0x3E,0x00,0x00,//’0‘
0x00,0x08,0x0C,0x0F,0x0C,0x0C,0x0C,0x0C,0x0C,0x3F,0x00,0x00,//’1‘
0x00,0x1E,0x33,0x33,0x30,0x18,0x0C,0x06,0x33,0x3F,0x00,0x00,//’2‘
0x00,0x1E,0x33,0x30,0x30,0x1C,0x30,0x30,0x33,0x1E,0x00,0x00,//’3‘
0x00,0x30,0x38,0x3C,0x36,0x33,0x7F,0x30,0x30,0x78,0x00,0x00,//’4‘
0x00,0x3F,0x03,0x03,0x03,0x1F,0x30,0x30,0x33,0x1E,0x00,0x00,//’5‘
0x00,0x1C,0x06,0x03,0x03,0x1F,0x33,0x33,0x33,0x1E,0x00,0x00,//’6‘
0x00,0x7F,0x63,0x63,0x60,0x30,0x18,0x0C,0x0C,0x0C,0x00,0x00,//’7‘
0x00,0x1E,0x33,0x33,0x37,0x1E,0x3B,0x33,0x33,0x1E,0x00,0x00,//’8‘
0x00,0x1E,0x33,0x33,0x33,0x3E,0x18,0x18,0x0C,0x0E,0x00,0x00,//’9‘
0x00,0x00,0x00,0x1C,0x1C,0x00,0x00,0x1C,0x1C,0x00,0x00,0x00,//’:‘
0x00,0x00,0x00,0x1C,0x1C,0x00,0x00,0x1C,0x1C,0x18,0x0C,0x00,//’;‘
0x00,0x30,0x18,0x0C,0x06,0x03,0x06,0x0C,0x18,0x30,0x00,0x00,//’《‘
0x00,0x00,0x00,0x00,0x7E,0x00,0x7E,0x00,0x00,0x00,0x00,0x00,//’=‘
0x00,0x06,0x0C,0x18,0x30,0x60,0x30,0x18,0x0C,0x06,0x00,0x00,//’》‘
0x00,0x1E,0x33,0x30,0x18,0x0C,0x0C,0x00,0x0C,0x0C,0x00,0x00,//’?‘
0x00,0x3E,0x63,0x63,0x7B,0x7B,0x7B,0x03,0x03,0x3E,0x00,0x00,//’@‘
0x00,0x0C,0x1E,0x33,0x33,0x33,0x3F,0x33,0x33,0x33,0x00,0x00,//’A‘
0x00,0x3F,0x66,0x66,0x66,0x3E,0x66,0x66,0x66,0x3F,0x00,0x00,//’B‘
0x00,0x3C,0x66,0x63,0x03,0x03,0x03,0x63,0x66,0x3C,0x00,0x00,//’C‘
0x00,0x1F,0x36,0x66,0x66,0x66,0x66,0x66,0x36,0x1F,0x00,0x00,//’D‘
0x00,0x7F,0x46,0x06,0x26,0x3E,0x26,0x06,0x46,0x7F,0x00,0x00,//’E‘
0x00,0x7F,0x66,0x46,0x26,0x3E,0x26,0x06,0x06,0x0F,0x00,0x00,//’F‘
0x00,0x3C,0x66,0x63,0x03,0x03,0x73,0x63,0x66,0x7C,0x00,0x00,//’G‘
0x00,0x33,0x33,0x33,0x33,0x3F,0x33,0x33,0x33,0x33,0x00,0x00,//’H‘
0x00,0x1E,0x0C,0x0C,0x0C,0x0C,0x0C,0x0C,0x0C,0x1E,0x00,0x00,//’I‘
0x00,0x78,0x30,0x30,0x30,0x30,0x33,0x33,0x33,0x1E,0x00,0x00,//’J‘
0x00,0x67,0x66,0x36,0x36,0x1E,0x36,0x36,0x66,0x67,0x00,0x00,//’K‘
0x00,0x0F,0x06,0x06,0x06,0x06,0x46,0x66,0x66,0x7F,0x00,0x00,//’L‘
0x00,0x63,0x77,0x7F,0x7F,0x6B,0x63,0x63,0x63,0x63,0x00,0x00,//’M‘
0x00,0x63,0x63,0x67,0x6F,0x7F,0x7B,0x73,0x63,0x63,0x00,0x00,//’N‘
0x00,0x1C,0x36,0x63,0x63,0x63,0x63,0x63,0x36,0x1C,0x00,0x00,//’O‘
0x00,0x3F,0x66,0x66,0x66,0x3E,0x06,0x06,0x06,0x0F,0x00,0x00,//’P‘
0x00,0x1C,0x36,0x63,0x63,0x63,0x73,0x7B,0x3E,0x30,0x78,0x00,//’Q‘
0x00,0x3F,0x66,0x66,0x66,0x3E,0x36,0x66,0x66,0x67,0x00,0x00,//’R‘
0x00,0x1E,0x33,0x33,0x03,0x0E,0x18,0x33,0x33,0x1E,0x00,0x00,//’S‘
0x00,0x3F,0x2D,0x0C,0x0C,0x0C,0x0C,0x0C,0x0C,0x1E,0x00,0x00,//’T‘
0x00,0x33,0x33,0x33,0x33,0x33,0x33,0x33,0x33,0x1E,0x00,0x00,//’U‘
0x00,0x33,0x33,0x33,0x33,0x33,0x33,0x33,0x1E,0x0C,0x00,0x00,//’V‘
0x00,0x63,0x63,0x63,0x63,0x6B,0x6B,0x36,0x36,0x36,0x00,0x00,//’W‘
0x00,0x33,0x33,0x33,0x1E,0x0C,0x1E,0x33,0x33,0x33,0x00,0x00,//’X‘
0x00,0x33,0x33,0x33,0x33,0x1E,0x0C,0x0C,0x0C,0x1E,0x00,0x00,//’Y‘
0x00,0x7F,0x73,0x19,0x18,0x0C,0x06,0x46,0x63,0x7F,0x00,0x00,//’Z‘
0x00,0x3C,0x0C,0x0C,0x0C,0x0C,0x0C,0x0C,0x0C,0x3C,0x00,0x00,//’[‘
0x00,0x00,0x01,0x03,0x06,0x0C,0x18,0x30,0x60,0x40,0x00,0x00,//’\‘
0x00,0x3C,0x30,0x30,0x30,0x30,0x30,0x30,0x30,0x3C,0x00,0x00,//’]‘
0x08,0x1C,0x36,0x63,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,//’^‘
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xFF,0x00,//’_‘
0x0C,0x0C,0x18,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,//’`‘
0x00,0x00,0x00,0x00,0x1E,0x30,0x3E,0x33,0x33,0x6E,0x00,0x00,//’a‘
0x00,0x07,0x06,0x06,0x3E,0x66,0x66,0x66,0x66,0x3B,0x00,0x00,//’b‘
0x00,0x00,0x00,0x00,0x1E,0x33,0x03,0x03,0x33,0x1E,0x00,0x00,//’c‘
0x00,0x38,0x30,0x30,0x3E,0x33,0x33,0x33,0x33,0x6E,0x00,0x00,//’d‘
0x00,0x00,0x00,0x00,0x1E,0x33,0x3F,0x03,0x33,0x1E,0x00,0x00,//’e‘
0x00,0x1C,0x36,0x06,0x06,0x1F,0x06,0x06,0x06,0x0F,0x00,0x00,//’f‘
0x00,0x00,0x00,0x00,0x6E,0x33,0x33,0x33,0x3E,0x30,0x33,0x1E,//’g‘
0x00,0x07,0x06,0x06,0x36,0x6E,0x66,0x66,0x66,0x67,0x00,0x00,//’h‘
0x00,0x18,0x18,0x00,0x1E,0x18,0x18,0x18,0x18,0x7E,0x00,0x00,//’i‘
0x00,0x30,0x30,0x00,0x3C,0x30,0x30,0x30,0x30,0x33,0x33,0x1E,//’j‘
0x00,0x07,0x06,0x06,0x66,0x36,0x1E,0x36,0x66,0x67,0x00,0x00,//’k‘
0x00,0x1E,0x18,0x18,0x18,0x18,0x18,0x18,0x18,0x7E,0x00,0x00,//’l‘
0x00,0x00,0x00,0x00,0x3F,0x6B,0x6B,0x6B,0x6B,0x63,0x00,0x00,//’m‘
0x00,0x00,0x00,0x00,0x1F,0x33,0x33,0x33,0x33,0x33,0x00,0x00,//’n‘
0x00,0x00,0x00,0x00,0x1E,0x33,0x33,0x33,0x33,0x1E,0x00,0x00,//’o‘
0x00,0x00,0x00,0x00,0x3B,0x66,0x66,0x66,0x66,0x3E,0x06,0x0F,//’p‘
0x00,0x00,0x00,0x00,0x6E,0x33,0x33,0x33,0x33,0x3E,0x30,0x78,//’q‘
0x00,0x00,0x00,0x00,0x37,0x76,0x6E,0x06,0x06,0x0F,0x00,0x00,//’r‘
0x00,0x00,0x00,0x00,0x1E,0x33,0x06,0x18,0x33,0x1E,0x00,0x00,//’s‘
0x00,0x00,0x04,0x06,0x3F,0x06,0x06,0x06,0x36,0x1C,0x00,0x00,//’t‘
0x00,0x00,0x00,0x00,0x33,0x33,0x33,0x33,0x33,0x6E,0x00,0x00,//’u‘
0x00,0x00,0x00,0x00,0x33,0x33,0x33,0x33,0x1E,0x0C,0x00,0x00,//’v‘
0x00,0x00,0x00,0x00,0x63,0x63,0x6B,0x6B,0x36,0x36,0x00,0x00,//’w‘
0x00,0x00,0x00,0x00,0x63,0x36,0x1C,0x1C,0x36,0x63,0x00,0x00,//’x‘
0x00,0x00,0x00,0x00,0x66,0x66,0x66,0x66,0x3C,0x30,0x18,0x0F,//’y‘
0x00,0x00,0x00,0x00,0x3F,0x31,0x18,0x06,0x23,0x3F,0x00,0x00,//’z‘
0x00,0x38,0x0C,0x0C,0x06,0x03,0x06,0x0C,0x0C,0x38,0x00,0x00,//’{‘
0x00,0x18,0x18,0x18,0x18,0x00,0x18,0x18,0x18,0x18,0x00,0x00,//’|‘
0x00,0x07,0x0C,0x0C,0x18,0x30,0x18,0x0C,0x0C,0x07,0x00,0x00,//’}‘
0x00,0xCE,0x5B,0x73,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,//’~‘
};
typedefstructtypFNT_GB16//汉字字模显示数据结构
{
charIndex[2];
charMsk[32];
};
structtypFNT_GB16xdataGB_16[]={//显示为16*16
”中“,0x01,0x00,0x01,0x00,0x21,0x08,0x3F,0xFC,0x21,0x08,0x21,0x08,0x21,0x08,0x21,0x08,0x21,0x08,0x3F,0xF8,0x21,0x08,0x01,0x00,0x01,0x00,0x01,0x00,0x01,0x00,0x01,0x00,
”文“,0x02,0x00,0x01,0x00,0x01,0x00,0xFF,0xFE,0x08,0x20,0x08,0x20,0x08,0x20,0x04,0x40,0x04,0x40,0x02,0x80,0x01,0x00,0x02,0x80,0x04,0x60,0x18,0x1E,0xE0,0x08,0x00,0x00,
”测“,0x40,0x02,0x27,0xC2,0x24,0x42,0x84,0x52,0x45,0x52,0x55,0x52,0x15,0x52,0x25,0x52,0x25,0x52,0x25,0x52,0xC5,0x52,0x41,0x02,0x42,0x82,0x42,0x42,0x44,0x4A,0x48,0x04,
”试“,0x00,0x20,0x40,0x28,0x20,0x24,0x30,0x24,0x27,0xFE,0x00,0x20,0xE0,0x20,0x27,0xE0,0x21,0x20,0x21,0x10,0x21,0x10,0x21,0x0A,0x29,0xCA,0x36,0x06,0x20,0x02,0x00,0x00,
};
uchargCurRow,gCurCol;//当前行、列存储,行高16点,列宽8点
ucharfnGetRow(void)
{
returngCurRow;
}
ucharfnGetCol(void)
{
returngCurCol;
}
ucharfnST01(void)//状态位STA1,STA0判断(读写指令和读写数据)
{
uchari;
for(i=10;i》0;i--)
{
if((LCMCW&0x03)==0x03)
break;
}
returni;//若返回零,说明错误
}
ucharfnST2(void)//状态位ST2判断(数据自动读状态)
{
uchari;
for(i=10;i》0;i--)
{
if((LCMCW&0x04)==0x04)
break;
}
returni;//若返回零,说明错误
}
ucharfnST3(void)//状态位ST3判断(数据自动写状态)
{
uchari;
for(i=10;i》0;i--)
{
if((LCMCW&0x08)==0x08)
break;
}
returni;//若返回零,说明错误
}
ucharfnST6(void)//状态位ST6判断(屏读/屏拷贝状态)
{
uchari;
for(i=10;i》0;i--)
{
if((LCMCW&0x40)==0x40)
break;
}
returni;//若返回零,说明错误
}
ucharfnPR1(ucharuCmd,ucharuPar1,ucharuPar2)//写双参数的指令
{
if(fnST01()==0)
return1;
LCMDW=uPar1;
if(fnST01()==0)
return2;
LCMDW=uPar2;
if(fnST01()==0)
return3;
LCMCW=uCmd;
return0;//返回0成功
}
ucharfnPR11(ucharuCmd,ucharuPar1)//写单参数的指令
{
if(fnST01()==0)
return1;
LCMDW=uPar1;
if(fnST01()==0)
return2;
LCMCW=uCmd;
return0;//返回0成功
}
ucharfnPR12(ucharuCmd)//写无参数的指令
{
if(fnST01()==0)
return1;
LCMCW=uCmd;
return0;//返回0成功
}
ucharfnPR13(ucharuData)//写数据
{
if(fnST3()==0)
return1;
LCMDW=uData;
return0;//返回0成功
}
ucharfnPR2(void)//读数据
{
if(fnST01()==0)
return1;
returnLCMDW;
}
//设置当前地址
voidfnSetPos(ucharurow,ucharucol)
{
uintiPos;
iPos=urow*30+ucol;
fnPR1(LC_ADD_POS,iPos&0xFF,iPos/256);
gCurRow=urow;
gCurCol=ucol;
}
//设置当前显示行、列
voidcursor(ucharuRow,ucharuCol)
{
fnSetPos(uRow*16,uCol);
}
//清屏
voidcls(void)
{
uinti;
fnPR1(LC_ADD_POS,0x00,0x00);//置地址指针
fnPR12(LC_AUT_WR);//自动写
for(i=0;i《240*30;i++)
{
fnST3();
fnPR13(0x00);//写数据
}
fnPR12(LC_AUT_OVR);//自动写结束
fnPR1(LC_ADD_POS,0x00,0x00);//重置地址指针
gCurRow=0;//置地址指针存储变量
gCurCol=0;
}
//LCM初始化
charfnLCMInit(void)
{
if(fnPR1(LC_TXT_STP,0x00,0x00)!=0)//文本显示区首地址
return-1;
fnPR1(LC_TXT_WID,0x1E,0x00);//文本显示区宽度
fnPR1(LC_GRH_STP,0x00,0x00);//图形显示区首地址
fnPR1(LC_GRH_WID,0x1E,0x00);//图形显示区宽度
fnPR12(LC_CUR_SHP|0x01);//光标形状
fnPR12(LC_MOD_OR);//显示方式设置
fnPR12(LC_DIS_SW|0x08);//显示开关设置
return0;
}
//ASCII(8*16)及汉字(16*16)显示函数
uchardprintf(char*fmt,。。.)
{
va_listarg_ptr;
charc1,c2,cData;
chartmpBuf[64];//LCD显示数据缓冲区
uchari=0,j,uLen,uRow,uCol;
uintk;
va_start(arg_ptr,fmt);
uLen=(uchar)vsprintf(tmpBuf,fmt,arg_ptr);
va_end(arg_ptr);
while(i《uLen)
{
c1=tmpBuf[i];
c2=tmpBuf[i+1];
uRow=fnGetRow();
uCol=fnGetCol();
if(c1》=0)
{//ASCII
if(c1《0x20)
{
switch(c1)
{
caseCR:
caseLF://回车或换行
i++;
if(uRow《112)
fnSetPos(uRow+16,0);
else
fnSetPos(0,0);
continue;
caseBS://退格
if(uCol》0)
uCol--;
fnSetPos(uRow,uCol);
cData=0x00;
break;
default://其他
c1=0x1f;
}
}
for(j=0;j《16;j++)
{
fnPR12(LC_AUT_WR);//写数据
if(c1》=0x1f)
{
if(j《(16-ASC_CHR_HEIGHT))
fnPR13(0x00);
else
fnPR13(ASC_MSK[(c1-0x1f)*ASC_CHR_HEIGHT+j-(16-ASC_CHR_HEIGHT)]);
}
else
fnPR13(cData);
fnPR12(LC_AUT_OVR);
fnSetPos(uRow+j+1,uCol);
}
if(c1!=BS)//非退格
uCol++;
}
else
{//中文
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])
break;
}
for(k=0;k《sizeof(GB_16[0].Msk)/2;k++)
{
fnSetPos(uRow+k,uCol);
fnPR12(LC_AUT_WR);//写数据
if(j《sizeof(GB_16)/sizeof(GB_16[0]))
{
fnPR13(GB_16[j].Msk[k*2]);
fnPR13(GB_16[j].Msk[k*2+1]);
}
else//未找到该字
{
if(k《sizeof(GB_16[0].Msk)/4)
{
fnPR13(0x00);
fnPR13(0x00);
}
else
{
fnPR13(0xff);
fnPR13(0xff);
}
}
fnPR12(LC_AUT_OVR);
}
uCol+=2;
i++;
}
if(uCol》=30)//光标后移
{
uRow+=16;
if(uRow《0x80)
uCol-=30;
else
{
uRow=0;
uCol=0;
}
}
fnSetPos(uRow,uCol);
i++;
}
returnuLen;
}
voidmain(void)//测试用
{
fnLCMInit();
cls();
cursor(0,0);
dprintf(”%s“,”Thisisatest:中文测试“);
}
评论
查看更多