📄 lcmdrv.c
字号:
********************************************************************************************************/
uint8 LCM_ReadByte(uint8 x, uint8 y)
{
uint8 dat=0xff;
uint8 x1;
uint32 iPos;
x1 = x >> 3; // 取Y方向分页地址
iPos = (uint32)y * 0x1e + x1;
LCM_WrParameter(LCM_ADD_POS,iPos&0xff,iPos/256,2);
LCM_WrParameter(LCM_NOC_RD,0,0,0);
/*
if(LCM_STA01() == 0)
{
return 1;
}
*/
IO0DIR = IO0DIR &~(0x000000ff<<BUS_NO);
LCM_UNWRITE();
LCM_DATA();
LCM_READ();
LCM_ENABLE();
//InData();
dat = (uint8)((IO0PIN)>>BUS_NO);
LCM_DISABLE();
return dat;
}
/*********************************************************************************************************
** 函数名称: LCM_DispIni
** 功能描述: LCM硬件初始化
** 输 入: 无
** 输 出: 无
** 全局变量: 无
** 调用模块: 无
**------------------------------------------------------------------------------------------------------
** Created by Rein Lee
** Created date: 2007-12-20
**------------------------------------------------------------------------------------------------------
** Modified by:
** Modified date:
**------------------------------------------------------------------------------------------------------
********************************************************************************************************/
void LCM_DispIni(void)
{
uint32 i;
// 设置引脚连接模块
#if LCM_RD < 16
PINSEL0 &= ~(3 << (2 * LCM_RD));
#else
PINSEL1 &= ~(3 << (2 * (LCM_RD - 16)));
#endif
#if LCM_WR < 16
PINSEL0 &= ~(3 << (2 * LCM_WR));
#else
PINSEL1 &= ~(3 << (2 * (LCM_WR - 16)));
#endif
#if LCM_CD < 16
PINSEL0 &= ~(3 << (2 * LCM_CD));
#else
PINSEL1 &= ~(3 << (2 * (LCM_CD - 16)));
#endif
#if BUS_NO<9
for (i = BUS_NO; i < BUS_NO+8; i++)
{
PINSEL0 &= ~(3 << (2 * i));
}
#else
for (i = BUS_NO; i < 16; i++)
{
PINSEL0 &= ~(3 << (2 * i));
}
for (; i < (BUS_NO+8); i++)
{
PINSEL1 &= ~(3 << (2 * (i-16)));
}
#endif
// 设置I/O为输出方式
IO0DIR = IO0DIR|(1<<LCM_RD)|(1<<LCM_WR)|(1<<LCM_CD)|(1<<LCM_CE);
IO0DIR = IO0DIR|(0xFF<<BUS_NO);
LCM_WrParameter(LCM_TXT_STP,0x00,0x00,2);
LCM_WrParameter(LCM_TXT_WID,0x1E,0x00,2);
LCM_WrParameter(LCM_GRH_STP,0x00,0x00,2);
LCM_WrParameter(LCM_GRH_WID,0x1E,0x00,2);
LCM_WrParameter(LCM_CUR_SHP|0x01,0,0,0);
LCM_WrParameter(LCM_MOD_OR,0,0,0);
LCM_WrParameter(LCM_DIS_SW|0x08,0,0,0);
}
/*********************************************************************************************************
** 函数名称: GUI_FillSCR()
** 功能描述: 全屏填充。直接使用数据填充显示缓冲区。根据LCM的实际情况编写此函数
** 输 入: dat 填充的数据
** 输 出: 无
** 全局变量: 无
** 调用模块: 无
**------------------------------------------------------------------------------------------------------
** Created by Rein Lee
** Created date: 2007-12-20
**------------------------------------------------------------------------------------------------------
** Modified by:
** Modified date:
**------------------------------------------------------------------------------------------------------
********************************************************************************************************/
void GUI_FillSCR(TCOLOR dat)
{
uint32 i;
LCM_WrParameter(LCM_ADD_POS,0x00,0x00,2);
LCM_WrParameter(LCM_AUT_WR,0x00,0x00,0);
for(i=0;i<240*128/8;i++)
{
//LCM_STA3();
LCM_WrData(dat);
}
LCM_WrParameter(LCM_AUT_OVR,0x00,0x00,0);
LCM_WrParameter(LCM_ADD_POS,0x00,0x00,2);
}
/*********************************************************************************************************
** 函数名称: GUI_Initialize
** 功能描述: 初始化GUI,包括初始化显示缓冲区,初始化LCM并清屏
** 输 入: 无
** 输 出: 无
** 全局变量: 无
** 调用模块: 无
**------------------------------------------------------------------------------------------------------
** Created by Rein Lee
** Created date: 2007-12-20
**------------------------------------------------------------------------------------------------------
** Modified by:
** Modified date:
**------------------------------------------------------------------------------------------------------
********************************************************************************************************/
void GUI_Initialize(void)
{
LCM_DispIni(); // 初始化LCM模块工作模式,纯图形模式
GUI_FillSCR(0x00); // 初始化缓冲区为0x00,并输出屏幕(清屏)
}
/*********************************************************************************************************
** 函数名称: GUI_Point
** 功能描述: 在指定位置上画点
** 输 入: x指定点所在列的位置;y指定点所在行的位置;color显示颜色(对于黑白色LCM,为0时灭,为1时显示)
** 输 出: 返回值为1时表示操作成功,为0时表示操作失败
** 全局变量: 无
** 调用模块: 无
**------------------------------------------------------------------------------------------------------
** Created by Rein Lee
** Created date: 2007-12-20
**------------------------------------------------------------------------------------------------------
** Modified by:
** Modified date:
**------------------------------------------------------------------------------------------------------
********************************************************************************************************/
/*另一种实现方式,已验证可行*/
uint8 GUI_Point(uint8 x, uint8 y, TCOLOR color)
{ //方法1,比方法2更快,因为无需等待从T6963C读取数据
uint8 x1;
uint32 iPos;
x1 = x >> 3; // 取Y方向分页地址
iPos = (uint32)y * 0x1e + x1;
LCM_WrParameter(LCM_ADD_POS,iPos&0xff,iPos/256,2);
x1 = turnf[ x & 0x07 ];
color = color <<3;
x1 = LCM_BIT_OP|x1|color; // 字节内位置计算
LCM_WrParameter(x1,0,0,0);;
return 1;
}
/*
uint8 GUI_Point(uint8 x, uint8 y, TCOLOR color)
{ //方法2,速度比方法1慢,因为调用了LCM_ReadByte从T6963C读取点数据
TCOLOR bak;
uint8 x1;
uint32 iPos;
if(x>=GUI_LCM_XMAX) return(0);
if(y>=GUI_LCM_YMAX) return(0);
x1 = x >> 3; // 取Y方向分页地址
iPos = (uint32)y * 0x1e + x1;
LCM_WrParameter(LCM_ADD_POS,iPos&0xff,iPos/256,2);
bak = LCM_ReadByte(x,y);
if(0 == color)
{
bak &= (~DEC_HEX_TAB1[x&0x07]);
}
else
{
bak |= DEC_HEX_TAB1[x&0x07];
}
gui_disp_buf[y][x1] = bak;
LCM_WrParameter(LCM_NOC_WR,bak,0,1);
return 1;
}
*/
/*********************************************************************************************************
** 函数名称: GUI_ReadPoint
** 功能描述: 读取指定点的颜色。对于单色,设置ret的d0位为1或0,4级灰度则为d0、d1有效,8位RGB则d0--d7有效,RGB结构则R、G、B变量有效
** 输 入: x指定点所在列的位置; y指定点所在行的位置;ret保存颜色值的指针
** 输 出: 返回0表示指定地址超出缓冲区范围
** 全局变量: 无
** 调用模块: 无
**------------------------------------------------------------------------------------------------------
** Created by Rein Lee
** Created date: 2007-12-20
**------------------------------------------------------------------------------------------------------
** Modified by:
** Modified date:
**------------------------------------------------------------------------------------------------------
********************************************************************************************************/
uint8 GUI_ReadPoint(uint8 x, uint8 y, TCOLOR *ret)
{
TCOLOR bak;
uint8 x1;
bak = LCM_ReadByte(x,y);
x1 = turnf[ x & 0x07 ];
if( (bak & (DEC_HEX_TAB[x1&0x07]) ) ==0)
*ret = 0x00;
else
*ret = 0x01;
return 1;
}
/*********************************************************************************************************
** 函数名称: GUI_HLine
** 功能描述: 画水平线,操作失败原因是指定地址超出缓冲区范围
** 输 入: x0 水平线起点所在列的位置
* y0 水平线起点所在行的位置
* x1 水平线终点所在列的位置
* color 显示颜色(对于黑白色LCM,为0时灭,为1时显示)
** 输 出: 无
** 全局变量: 无
** 调用模块: 无
**------------------------------------------------------------------------------------------------------
** Created by Rein Lee
** Created date: 2007-12-20
**------------------------------------------------------------------------------------------------------
** Modified by:
** Modified date:
**------------------------------------------------------------------------------------------------------
********************************************************************************************************/
void GUI_HLine(uint8 x0, uint8 y0, uint8 x1, TCOLOR color)
{ uint8 bak;
if(x0>x1) // 对x0、x1大小进行排列,以便画图
{ bak = x1;
x1 = x0;
x0 = bak;
}
do
{ GUI_Point(x0, y0, color); // 逐点显示,描出垂直线
x0++;
}while(x1>=x0);
}
/*********************************************************************************************************
** 函数名称: GUI_RLine
** 功能描述: 画竖直线。
** 输 入: x0 水平线起点所在列的位置
* y0 水平线起点所在行的位置
* x1 水平线终点所在列的位置
* color 显示颜色(对于黑白色LCM,为0时灭,为1时显示)
** 输 出: 无
** 全局变量: 无
** 调用模块: 无
**------------------------------------------------------------------------------------------------------
** Created by Rein Lee
** Created date: 2007-12-20
**------------------------------------------------------------------------------------------------------
** Modified by:
** Modified date:
**------------------------------------------------------------------------------------------------------
********************************************************************************************************/
void GUI_RLine(uint8 x0, uint8 y0, uint8 y1, TCOLOR color)
{ uint8 bak;
if(y0>y1) // 对x0、x1大小进行排列,以便画图
{ bak = y1;
y1 = y0;
y0 = bak;
}
do
{ GUI_Point(x0, y0, color); // 逐点显示,描出垂直线
y0++;
}while(y1>=y0);
}
/*********************************************************************************************************
** End Of File
********************************************************************************************************/
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -