📄 lcm.c
字号:
for (x=0; x<LCMLIMIT; x++) // 128 rows for every page.
{
Lcm_WriteDot(x, posX/8+y, dotBuf2[x+y*LCMLIMIT]);
}
}
//LcmBlOn();
Lcm_Cs(LCD_CS_OFF);
}
/*
ttl -- 当前菜单的总数.
num -- 每屏能显示的菜单数.
cursor -- 当前的菜单序号.
posX -- 滚动条的起始位置.(以点为单位,暂要求是8的倍数)
len -- 滚动条的长度(以点为单位).
posY -- 滚动条的列位置(点单位,靠右对齐,即右边界).
set -- 设置/清除.
*/
void Lcm_ScrollBarEx(byte ttl, byte num, byte cursor, byte posX, byte len, byte posY, byte set)
{
byte top, bottom, dot, inc;
dot = 5;
if (cursor >= (ttl - 1))
{
top = posX + (len - 2) - dot;
}
else if (cursor == 0)
{
top = posX + 1;
}
else
{
top = posX + (len - 2) * cursor / ttl;
}
bottom = top + dot;
Lcm_ScrollBar(posX, len, top, bottom, posY, set);
}
/*
posX -- 滚动条的起始行位置.(以点为单位,暂要求是8的倍数)
len -- 滚动条的长度(以点为单位).
top --
bottom --
posY -- 滚动条的列位置(点单位,靠右对齐,即右边界).
set -- 设置/清除.
*/
void Lcm_ScrollBar(byte posX, byte len, byte top, byte bottom, byte posY, byte set)
{
byte i, j, k, temp;
#if LCM == LCM_12864
const byte posYoffset = 7;
#elif LCM == LCM_19264
const byte posYoffset = 6;
#endif
if (set == FALSE) // only Clear!
{
for (j=posX/8; j<((posX + len)/8); j++)
{
for (i=posY-posYoffset; i<posY; i++)
{
Lcm_WriteDot(i, j, 0);
}
}
if ((len % 8) != 0) // 在弹出窗口显示滚动条时,底端有一空行,填之.
{
for (i=posY-posYoffset; i<posY-1; i++)
{
Lcm_WriteDot(i, (posX + len)/8, Lcm_mirror[(posX + len)/8][i]);
}
}
return;
}
for (j=posX/8; j<((posX + len)/8); j++)
{
Lcm_WriteDot(posY-posYoffset, j, 0xff);
for (i=posY-posYoffset+1; i<posY-1; i++)
{
temp = 0;
for (k=0; k<8; k++)
{
if ((top <= (j*8+k)) && (bottom >= (j*8+k)))
{
// if (((top == (j*8+k)) || (bottom == (j*8+k))) &&
// ((i == posY-posYoffset+1) || (i == posY-2)))
// {}
// else
temp |= (0x01 << k);
}
}
if (j == posX/8)
{
temp |= 0x01;
}
//else if (j == (START_LINE+SCREEN_LINE-1))
else if (j == (((posX + len)/8)-1))
{
temp |= 0x80;
}
Lcm_WriteDot(i, j, temp);
}
Lcm_WriteDot(posY-1, j, 0xff);
}
if ((len % 8) != 0) // 在弹出窗口显示滚动条时,底端有一空行,填之.
{
for (i=posY-posYoffset; i<posY-1; i++)
{
Lcm_WriteDot(i, (posX + len)/8, Lcm_mirror[(posX + len)/8][i] | 0x01);
}
}
}
/*
posX --- 行 起始位置 点为单位,
posY --- 列 起始位置 点为单位,
*/
void Lcm_Cursor(byte posX, byte posY, byte format, byte set)
{
byte i;
if (set == TRUE)
{
DisCursorFlushInt();
lcmCursorPosX = posX;
lcmCursorPosY = posY;
lcmCursorFormat = format;
lcmCursor = TRUE;
memcpy(lcmCursorBack, &Lcm_mirror[lcmCursorPosX/8][lcmCursorPosY], 8);
if (format == 1)
{
memcpy(&lcmCursorBack[8], &Lcm_mirror[lcmCursorPosX/8+1][lcmCursorPosY], 8);
}
Lcm_CursorDisp(TRUE);
// if (lcmCursorFormat == 0)
// {
// for (i=0; i<6-1; i++)
// {
// Lcm_WriteDot(lcmCursorPosX+i, lcmCursorPosY, 0xfe);
// }
// }
// else
// {
// for (i=0; i<8-1; i++)
// {
// Lcm_WriteDot(lcmCursorPosX+i, lcmCursorPosY, 0xfe);
// }
// for (i=0; i<8-1; i++)
// {
// Lcm_WriteDot(lcmCursorPosX+i, lcmCursorPosY+1, 0xff);
// }
// }
EnCursorFlushInt();
}
else
{
DisCursorFlushInt();
lcmCursor = FALSE;
EnCursorFlushInt();
Lcm_CursorDisp(FALSE);
// if (lcmCursorFormat == 0)
// {
// for (i=0; i<6; i++)
// {
// Lcm_WriteDot(lcmCursorPosX+i, lcmCursorPosY, 0);
// }
// }
// else
// {
// for (i=0; i<8; i++)
// {
// Lcm_WriteDot(lcmCursorPosX+i, lcmCursorPosY, 0);
// }
// for (i=0; i<8; i++)
// {
// Lcm_WriteDot(lcmCursorPosX+i, lcmCursorPosY+1, 0);
// }
// }
}
}
/********************************************************************************
* 弹出窗口,显示窗框.
* 注意: 弹出窗口边沿需小于LCM限制方可,不然可能出现错误.
* posX -- 行,以点为单位,暂只支持8的倍数.
* posY -- 列,以点为单位,暂只支持6的倍数.
* width -- 宽度.以点为单位,暂只支持6的倍数.. 最大19个字符.(20个字符不佳)
* height -- 高度.以点为单位,暂只支持8的倍数.,其图框上下边沿在其外.
* type -- 类型,暂保留.
* op -- 设置(TRUE), 恢复(FALSE).
* 注意: 此函数的作用仅仅显示窗框,并不保存原来显示内容.
*********************************************************************************/
void Lcm_PopFrame(byte posX, byte posY, byte height, byte width, byte type, byte op)
{
byte i, j, temp, posXRear;
posX /= 8;
posY /= 6;
height /= 8;
width /= 6;
posXRear = (width + posY) * 6 + 1;
posY = posY * 6 - 2;
// 显示弹出窗口框.
for (i=posX; i<posX+height; i++)
{
for (j=posY; j<posXRear; j++)
{
Lcm_WriteDot(j, i, 0x00);
}
Lcm_WriteDot(posY-1, i, 0x00);
Lcm_WriteDot(posY, i, 0xff);
Lcm_WriteDot(posXRear-1, i, 0xff);
Lcm_WriteDot(posXRear, i, 0xff);
Lcm_WriteDot(posXRear+1, i, 0x00);
}
for (j=posY; j<posXRear; j++)
{
temp = Lcm_mirror[posX-1][j] | 0x80;
temp &= 0xBF;
Lcm_WriteDot(j, posX-1, temp);
}
for (j=posY; j<(posXRear+1); j++)
{
temp = Lcm_mirror[posX+height][j] | 0x06;
temp &= 0xF6;
if (j == posY)
{
temp &= 0xf2;
temp |= 0x01;
}
else if (j >= (posXRear-1))
{
temp |= 0x01;
}
Lcm_WriteDot(j, posX+height, temp);
}
}
/********************************************************************************
* 弹出窗口,其作用是让用户选择,或让用户输入.
* 注意: 弹出窗口边沿需小于LCM限制方可,不然可能出现错误.
* posX -- 行,以点为单位,暂只支持8的倍数.
* posY -- 列,以点为单位,暂只支持6的倍数.
* height -- 高度.以点为单位,暂只支持8的倍数.,其图框上下边沿在其外.
* width -- 宽度.以点为单位,暂只支持6的倍数.. 最大19个字符.(20个字符不佳)
* type -- 类型,暂保留.
* op -- 设置(TRUE), 恢复(FALSE).
*********************************************************************************/
void Lcm_PopUp(byte posX, byte posY, byte height, byte width, byte type, byte op)
{
byte i, j, temp, posXRear;
// 恢复原窗口.
if (op == FALSE)
{
lcmPopStX = 0;
lcmPopStY = 0;
lcmPopHeight = 0;
lcmPopWidth = 0;
memcpy(Lcm_mirror[0], Lcm_mirrorOld[0], LCMLIMIT*8);
Lcm_Flush(Lcm_mirror[0]);
return;
}
// 设置窗体位置坐标,用于限制窗体显示.以点为单位.
lcmPopStX = posX;
lcmPopStY = posY;
lcmPopHeight = height;
lcmPopWidth = width;
// 保存显示内容.
memcpy(Lcm_mirrorOld[0], Lcm_mirror[0], LCMLIMIT*8);
Lcm_ClrLine(0, 8, 0);
Lcm_PopFrame(posX, posY, height, width, type, op);
}
/*
简易弹出窗口,仅保存原显示,并清除显示. 待用户完成弹出窗口后,调用Lcm_ReCall()恢复.
请谨慎使用此函数。尽量保证每次调用后都会调用Lcm_ReCall()恢复.
*/
void Lcm_Pop(void)
{
memcpy(Lcm_mirrorOld[0], Lcm_mirror[0], LCMLIMIT*8);
Lcm_ClrLine(0, 8, FALSE);
}
/*
简易弹出窗口,仅保存第四行原显示,并清除显示. 待用户完成弹出窗口后,调用Lcm_ReCallEx()恢复.
*/
void Lcm_PopEx(void)
{
// memcpy(Lcm_mirrorOld[6], Lcm_mirror[6], LCMLIMIT*2);
Lcm_ClrLine(0, 6, FALSE);
}
// 用于恢复原显示,全屏刷新.
void Lcm_Flush(const byte *ptr)
{
byte i, j;
for (i=0; i<8; i++)
{
for (j=0; j<LCMLIMIT; j++)
{
// Lcm_WriteDot(j, i, *ptr++);
if ((j % 64) == 0)
Lcm_WriteDot(j, i, *ptr++);
else
{
Lcm_mirror[i][j] = *ptr;
Lcm_Write(*ptr++, LCD_DATA);
}
}
}
}
// 保存当前显示区.
void Lcm_SaveDisplay(void)
{
memcpy(Lcm_mirrorOld[0], Lcm_mirror[0], LCMLIMIT*8);
}
// 回复保存的当前显示区.
void Lcm_ReCall(void)
{
memcpy(Lcm_mirror[0], Lcm_mirrorOld[0], LCMLIMIT*8);
Lcm_Flush(Lcm_mirrorOld[0]);
}
// 仅回复保存的第四行显示区.
void Lcm_ReCallEx(void)
{
byte i, j;
byte *ptr;
// Lcm_ClrLine(0, 6, FALSE);
return;
memcpy(Lcm_mirror[6], Lcm_mirrorOld[6], LCMLIMIT*2);
ptr = Lcm_mirror[6];
for (i=6; i<8; i++)
{
for (j=0; j<LCMLIMIT; j++)
{
if ((j % 64) == 0)
Lcm_WriteDot(j, i, *ptr++);
else
{
//Lcm_mirror[i][j] = *ptr;
Lcm_Write(*ptr++, LCD_DATA);
}
//Lcm_WriteDot(j, i, *ptr++);
}
}
}
// 设置或关闭光标显示.
void Lcm_CursorDisp(byte set)
{
byte temp = 0;
byte i;
if (set == TRUE)
{
temp = 0xff;
}
if (lcmCursorFormat == 0)
{
for (i=0; i<6; i++)
{
Lcm_WriteDot(lcmCursorPosY+i, lcmCursorPosX/8, temp);
}
}
else
{
for (i=0; i<8; i++)
{
Lcm_WriteDot(lcmCursorPosY+i, lcmCursorPosX/8, temp);
}
for (i=0; i<8; i++)
{
Lcm_WriteDot(lcmCursorPosY+i, lcmCursorPosX/8+1, temp);
}
}
}
/*
posX --- 行, 以点为单位,
posY --- 列, 以点为单位,
*/
void Lcm_CursorPop(byte posX, byte posY, byte format, byte set)
{
byte i;
if (set == TRUE)
{
// 首先保存主菜单光标设置,然后设置弹出窗体光标.
DisCursorFlushInt();
lcmCursorPosXBak = lcmCursorPosX;
lcmCursorPosYBak = lcmCursorPosY;
lcmCursorFormatBak = lcmCursorFormat;
lcmCursorBak = lcmCursor;
posX += lcmPopStX;
posY += lcmPopStY;
lcmCursorPosX = posX;
lcmCursorPosY = posY;
lcmCursorFormat = format;
lcmCursor = TRUE;
memcpy(lcmCursorPopBak, &Lcm_mirror[lcmCursorPosX/8][lcmCursorPosY], 8);
if (format == 1)
{
memcpy(&lcmCursorPopBak[8], &Lcm_mirror[lcmCursorPosX/8+1][lcmCursorPosY], 8);
}
Lcm_CursorDisp(TRUE);
EnCursorFlushInt();
}
else
{
// 首先关闭弹出窗体光标,然后恢复主菜单光标.
DisCursorFlushInt();
lcmCursor = FALSE;
Lcm_CursorDisp(FALSE);
lcmCursorPosX = lcmCursorPosXBak;
lcmCursorPosY = lcmCursorPosYBak;
lcmCursorFormat = lcmCursorFormatBak;
lcmCursor = lcmCursorBak;
EnCursorFlushInt();
}
}
// 指定位置,指定格式显示日期.
void Lcm_DispDate(byte posX, byte posY, byte year, byte month, byte day, byte format, byte font, byte pop)
{
byte temp[20];
Str_DateTo(temp, year, month, day, format);
Lcm_Disp(temp, posX, posY, 10, font, FALSE, pop);
}
/********************************************************************************
* 函数说明: 将long型数据转换成字符串,指定小数点.不保留符号,若小数点为零,则不加入小数点.
* 输入参数: ltmp, dots.
* 输出参数: *str, 注意此数组最大为12字节.
* 返回值: void
********************************************************************************/
void Str_LongTo(byte *str, dword ltmp, byte dots)
{
long tmpSum;
byte i;
byte temp[15];
tmpSum = ltmp;
if (tmpSum < 0)
{
tmpSum = - tmpSum;
}
memset(temp, ' ', 15);
for (i=0; i<10; i++)
{
if ((dots != 0) && (i == dots))
{
temp[10-i] = '.';
continue;
}
temp[10-i] = tmpSum % 10 + '0';
tmpSum /= 10;
if (tmpSum == 0)
{
if ((dots == 0) || (i > dots))
{
break;
}
}
}
temp[11] = 0;
for (i=0; i<10; i++)
{
if (temp[i] != ' ')
{
break;
}
}
memcpy(str, &temp[i], 12-i);
}
/********************************************************************************
* 函数说明: 将数量转化成指定字节数的字符串
* 输入参数: void
* 输出参数: void
* 返回值: void
********************************************************************************/
void Str_LongToEx(byte *str, dword ltmp, byte cnt, byte fill)
{
byte i;
memset(str, fill, cnt);
for (i=0; i<cnt; i++)
{
str[cnt-1-i] = ltmp % 10 + '0';
ltmp /= 10;
if (ltmp == 0)
{
break;
}
}
str[cnt] = 0;
}
/********************************************************************************
* 函数说明: 将long型数据转换成字符串,指定小数点.不保留符号,若小数点为零,则不加入小数点.
* 输入参数: ltmp, dots.
* 输出参数: *str, 注意此数组最大为12字节.
* 返回值: 字符串长度.
********************************************************************************/
byte Str_LongTolen(byte *str, long ltmp, byte dots, byte len)
{
long tmpSum;
byte i;
byte temp[20];
byte flag = 0;
tmpSum = ltmp;
if (tmpSum < 0)
{
tmpSum = - tmpSum;
flag = 1;
// str[0] = '-';
// if (len != 0)
// {
// len -= 1;
// }
}
memset(temp, ' ', 15);
for (i=0; i<10; i++)
{
if ((dots != 0) && (i == dots))
{
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -