📄 lcddrv.c
字号:
return 0; // 返回0成功
}
uchar fnPR12(uchar uCmd) // 写无参数的指令
{
if(fnST01() == 0)
return 1;
WriteCmd;
LCMCW = uCmd;
WriteOK;
return 0; // 返回0成功
}
uchar fnPR13(uchar uData) // 写数据
{
if(fnST3() == 0)
return 1;
WriteData;
LCMDW = uData;
WriteOK;
return 0; // 返回0成功
}
uchar fnPR14(uchar uData) // 写数据
{
if(fnST01() == 0)
return 1;
WriteData;
LCMDW = uData;
WriteOK;
return 0; // 返回0成功
}
uchar fnPR2(void) // 读数据
{
uchar data;
if(fnST01() == 0)
return 1;
ReadData;
data = LCMDW;
ReadOK;
return data;
}
// 设置当前地址
void fnSetPos(uchar urow, uchar ucol)
{
uint iPos;
iPos = urow * 30 + ucol;
fnPR1(LC_ADD_POS,iPos & 0xFF,iPos / 256);
gCurRow = urow;
gCurCol = ucol;
}
// 设置当前显示行、列
void cursor(uchar uRow, uchar uCol)
{
fnSetPos(uRow * 16, uCol);
}
// 清屏
void cls(void)
{
uint i;
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 初始化
char fnLCMInit(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_MOD_XOR); // 显示方式设置
fnPR12(LC_DIS_SW | 0x08); // 显示开关设置
return 0;
}
*/
// 设置当前显示行、列
void cursor(uchar uLayer,uchar uRow, uchar uCol)
{
//fnSetPos(uRow * 16, uCol);
uint16 Position_H,Address = 0;
if (uLayer == 1)
{
//Address = 40*uRow + uCol>>3;
//Address = 40*uRow + uCol>>3 + 0x2600;
Address = 40*uRow + uCol>>3;
gCursor[0].xx = uCol;
gCursor[0].yy = uRow;
Position_H = 0x00;
//Position_H = 0x26;
}
else
{
Address = 40*uRow + uCol>>3 + 0x2600;
//Address = 40*uRow + uCol>>3;
gCursor[1].xx = uCol;
gCursor[1].yy = uRow;
Position_H = 0x26;
//Position_H = 0x00;
}
LCDWriteCmd(LC_CSRW); // CURSOR WRITE COMMAND
LCDWriteData(0x00); // Cursor position low byte
LCDWriteData(Position_H); // Cursor position high byte
}
/*
//在指定位置显示反白的块
void FunBlock(uchar X,uchar Y,uchar width,uchar height)
{
uchar j,k,uLen,uRow,uCol,data;
//uRow = fnGetRow();
//uCol = fnGetCol();
X = X>>3;
width = width>>3;
uCol = X;
uRow = Y;
for(k=0;k<height;k++)
{
for (j=0;j<width;j++)
{
fnSetPos(uRow+k,uCol+j);
fnPR12(LC_AUT_RD); // 写数据
data = fnPR2();
fnPR12(LC_AUT_OVR);
//SendByte(data);
fnSetPos(uRow+k,uCol+j);
fnPR12(LC_AUT_WR); // 写数据
fnPR13(~data);
fnPR12(LC_AUT_OVR);
}
}
fnPR1(LC_ADD_POS,0x00,0x00); // 重置地址指针
gCurRow = 0; // 置地址指针存储变量
gCurCol = 0;
}
*/
/*--------------
//在指定位置显示反白的块
void FunBlock(uchar X,uchar Y,uchar width,uchar height)
{
uchar j,k,uLen,uRow,uCol,data;
uchar xmax;
//uRow = fnGetRow();
//uCol = fnGetCol();
xmax = X+width;
//X = X>>3;
width = width>>3;
uCol = 0;
uRow = Y;
for(k=0;k<height;k++)
{
for (j=X;j<=xmax;j+=8)
{
fnSetPos(uRow+k,uCol+j/8);
fnPR12(LC_AUT_RD); // 写数据
data = fnPR2();
fnPR12(LC_AUT_OVR);
//SendByte(data);
fnSetPos(uRow+k,uCol+j/8);
fnPR12(LC_AUT_WR); // 写数据
data ^= (0xff>>(j%8));
fnPR13(data);
fnPR12(LC_AUT_OVR);
if(j==X)
j=(j>>3)<<3;
}
fnSetPos(uRow+k,uCol+j/8);
fnPR12(LC_AUT_RD); // 写数据
data = fnPR2();
fnPR12(LC_AUT_OVR);
//SendByte(data);
fnSetPos(uRow+k,uCol+j/8);
fnPR12(LC_AUT_WR); // 写数据
data ^= ~(0xff>>(xmax%8));
fnPR13(data);
fnPR12(LC_AUT_OVR);
}
fnPR1(LC_ADD_POS,0x00,0x00); // 重置地址指针
gCurRow = 0; // 置地址指针存储变量
gCurCol = 0;
}
// ASCII(8*16) 及 汉字(16*16) 显示函数
uchar dprintf(char *fmt, ...)
{
va_list arg_ptr;
uchar c1,c2,cData;
char tmpBuf[64]; // LCD显示数据缓冲区
uchar i=0,j,uLen,uRow,uCol;
uint k;
va_start(arg_ptr, fmt);
uLen = (uchar)vsprintf(tmpBuf, fmt, arg_ptr);
// uLen = 512;
va_end(arg_ptr);
while(i<uLen)
{
c1 = tmpBuf[i];
c2 = tmpBuf[i+1];
uRow = fnGetRow();
uCol = fnGetCol();
if((c1 >= 0) && (c1 <0xa0))
{ // ASCII
if(c1 < 0x20)
{
switch(c1)
{
case CR:
case LF: // 回车或换行
i++;
if(uRow < 112)
fnSetPos(uRow+16,0);
else
fnSetPos(0,0);
continue;
case BS: // 退格
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 if(c1 >= 0xa0)
{ // 中文
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]))
{
//fnSetPos(uRow+k,uCol);
fnPR13(GB_16[j].Msk[k*2]);
//fnSetPos(uRow+k,(uCol+1));
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++;
}
return uLen;
}
void ReadLcd(void)
{
uchar j,k,uLen,uRow,uCol,data;
//uRow = fnGetRow();
//uCol = fnGetCol();
uCol = 0;
uRow = 0;
for(k=0;k<128;k++)
{
//fnSetPos(uRow+k,uCol);
//BMPdata = BMPdata + k*Xw;
//fnPR12(LC_AUT_RD); // 写数据
for (j=0;j<30;j++)
{
fnSetPos(uRow+k,uCol+j);
fnPR12(LC_AUT_RD); // 写数据
data = fnPR2();
fnPR12(LC_AUT_OVR);
//SendByte(data);
fnSetPos(uRow+k,uCol+j);
fnPR12(LC_AUT_WR); // 写数据
fnPR13(~data);
fnPR12(LC_AUT_OVR);
}
//fnPR12(LC_AUT_OVR);
}
fnPR1(LC_ADD_POS,0x00,0x00); // 重置地址指针
gCurRow = 0; // 置地址指针存储变量
gCurCol = 0;
}
void DispBMP(uchar Xs, uchar Ys, uchar Xw, uchar Yh,const uchar *BMPdata)
{
uchar j,k,uLen,uRow,uCol;
//uRow = fnGetRow();
//uCol = fnGetCol();
Xs = Xs>>3;
Xw = Xw>>3;
uCol = Xs;
uRow = Ys;
for(k=0;k<Yh;k++)
{
fnSetPos(uRow+k,uCol);
//BMPdata = BMPdata + k*Xw;
fnPR12(LC_AUT_WR); // 写数据
for (j=0;j<Xw;j++)
{
fnST3();
fnPR13(*(BMPdata+j+k*Xw));
}
fnPR12(LC_AUT_OVR);
}
fnPR1(LC_ADD_POS,0x00,0x00); // 重置地址指针
gCurRow = 0; // 置地址指针存储变量
gCurCol = 0;
}
// ASCII(8*16)显示函数
uchar cprintf(uchar *fmt)
{
uchar c1,c2,cData;
//char tmpBuf[64]; // LCD显示数据缓冲区
uchar j,uLen,uRow,uCol;
uchar i=0;
uint k;
while(*fmt != 0)
{
//c1 = tmpBuf[i];
//c2 = tmpBuf[i+1];
c1 = *fmt;
uRow = fnGetRow();
uCol = fnGetCol();
if(c1 < 0x20)
{
switch(c1)
{
case CR:
i++;
fmt++;
if(uRow < 112)
fnSetPos(uRow+16,0);
else
fnSetPos(0,0);
continue;
case LF: // 回车或换行
i++;
fmt++;
if(uRow < 112)
fnSetPos(uRow+16,0);
else
fnSetPos(0,0);
continue;
////break;
case BS: // 退格
if(uCol > 0)
uCol--;
fnSetPos(uRow,uCol);
cData = 0x00;
break;
default: // 其他
c1 = 0x1f;
}
}
for(j=0;j<16;j++)
{
fnSetPos(uRow+j,uCol);
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);
}
if(c1 != BS) // 非退格
uCol++;
if(uCol >= 30) // 光标后移
{
uRow += 16;
if(uRow < 0x80)
uCol -= 30;
else
{
uRow = 0;
uCol = 0;
}
}
fnSetPos(uRow,uCol);
i++;
fmt++;
}
return i;
}
------------*/
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -