📄 rd_lcd12864.h
字号:
/********************************************************
* 函数库说明:12864LCD显示基本驱动函数库 *
* 版本: v1.0 *
* 作者: 王卓然 *
* 日期: 2005年10月7日 *
* 修改: 王卓然 *
* 修改日期: 2006年2月16日 *
* *
* 说明: *
* 1、提供基本的现实函数。 *
* 2、支持小组编程规范0.9版的要求。 *
* 3、对外提供接口,支持位操作。 *
* 4、注意,这里的X/Y是屏幕竖方时候的坐标轴, *
* 如果使用字库,要使用转制过后竖向扫描的 *
* 字库。 *
* 5、为了兼容串行扫描方式,所以使用宏定义接口 *
* 的方法。同时也支持非位操作的方式。 *
********************************************************/
#ifndef _Use_LCD12864
# define _Use_LCD12864
/***********************
* 系 统 宏 定 义 *
***********************/
/*---------------------*
* 常 量 宏 定 义 *
*---------------------*/
#ifndef True
# define True 0x01
#endif
#ifndef False
# define False 0x00
#endif
#ifndef High
# define High 0x01
#endif
#ifndef Low
# define Low 0x00
#endif
#ifndef NULL
# define NULL 0x00
#endif
# define LCD12864_BUSY 7
# define LCD12864_ON_OFF 5
# define LCD12864_RESET 4
# define LCD12864_ON 0x3f
# define LCD12864_OFF 0x3e
#ifdef _LCD12864_WriteOnly
#ifndef LCD12864_WaitTime
# define LCD12864_WaitTime 5
#endif
#endif
/*---------------------*
* 动 作 宏 定 义 *
*---------------------*/
# define LCD12864_SetModel_Data SETBIT_RS;
# define LCD12864_SetModel_Command CLRBIT_RS;
# define LCD12864_SetModel_Read SETBIT_RW;SetDataPORTDirection_READ;
# define LCD12864_SetModel_Write CLRBIT_RW;SetDataPORTDirection_WRITE;
# define LCD12864_SetEnable SETBIT_E;
# define LCD12864_SetDisable CLRBIT_E;
# define LCD12864_ChooseCS1 SETBIT_CS1;CLRBIT_CS2;
# define LCD12864_ChooseCS2 SETBIT_CS2;CLRBIT_CS1;
# define LCD12864_ChooseBoth SETBIT_CS1;SETBIT_CS2;
# define LCD12864_Start CLRBIT_RST;
# define LCD12864_Reset SETBIT_RST;
# define LCD12864_SetLCD_ON setLCDOnOFF(LCD12864_ON);
# define LCD12864_SetLCD_OFF setLCDOnOFF(LCD12864_OFF);
/***********************
* 全局变量声明区 *
***********************/
/***********************
* 系统函数声明区 *
***********************/
void sendDataToLCD(char Data);
void sendCommandToLCD(char Command);
void waitForLCDReady(void);
void setLCDOnOFF(char State);
void setX(char X);
void setStartLine(char Y);
void setY(char Y);
void ClearLCD(void);
void LCDDraw(char X,char Y,char Data);
void LCD12864DispPicture(flash char *PIC,char Width,char Height,char Top,char Left);
/********************************************************
* 函数说明:检测LCD状态函数 *
********************************************************/
void waitForLCDReady(void)
{
#ifndef _LCD12864_WriteOnly
LCD12864_SetModel_Command;
LCD12864_SetModel_Read;
do
{
LCD12864_SetEnable;
}
while ((ReadDataPORT & (1<<LCD12864_BUSY)));
#else
char a = 0;
for (a=0;a<LCD12864_WaitTime;a++)
{
asm("nop");
}
#endif
}
/********************************************************
* 函数说明:发送数据函数 *
* 输入: 需要发送的数据 *
********************************************************/
void sendDataToLCD(char Data)
{
waitForLCDReady();
LCD12864_SetModel_Data;
LCD12864_SetModel_Write;
//DataPORT = Data;
LCD12864_DataTransfer(Data);
LCD12864_SetEnable;
LCD12864_SetDisable;
}
/********************************************************
* 函数说明:发送指令函数 *
* 输入: 需要发送的指令 *
********************************************************/
void sendCommandToLCD(char Command)
{
waitForLCDReady();
LCD12864_SetModel_Command;
LCD12864_SetModel_Write;
//DataPORT = Command;
LCD12864_DataTransfer(Command);
LCD12864_SetEnable;
LCD12864_SetDisable;
}
/********************************************************
* 函数说明:设置显示列(竖向) *
* 输入: 列号(0~7) *
********************************************************/
void setX(char X)
{
X &= 0x07;
X |= 0xb8;
sendCommandToLCD(X);
}
/********************************************************
* 函数说明:设置显示行(竖向) *
* 输入: 行号(0~127) *
********************************************************/
void setY(char Y)
{
Y &= 0x3f;
Y |= 0x40;
sendCommandToLCD(Y);
}
/********************************************************
* 函数说明:设置起始扫描行(竖向) *
* 输入: 行号(0~63) *
********************************************************/
void setStartLine(char Y)
{
Y &= 0x07;
Y |= 0xc0;
sendCommandToLCD(Y);
}
/********************************************************
* 函数说明:设置LCD开关状态 *
* 输入: 开关状态控制字 *
********************************************************/
void setLCDOnOFF(char State)
{
State |= 0x3e;
sendCommandToLCD(State);
}
/********************************************************
* 函数说明:LCD写屏函数 *
* 输入: 坐标(竖向),数据 *
********************************************************/
void LCDDraw(char X,char Y,char Data)
{
setX(X);
if (Y > 63)
{
LCD12864_ChooseCS2;
setY(Y-64);
}
else
{
LCD12864_ChooseCS1;
setY(Y);
}
sendDataToLCD(Data);
}
/********************************************************
* 函数说明:清屏函数 *
********************************************************/
void ClearLCD(void)
{
char a = 0,b = 0;
LCD12864_ChooseBoth;
setX(0);
setY(0);
for (a=0;a<8;a++)
{
setX(a);
for (b=0;b<64;b++)
{
sendDataToLCD(NULL);
}
}
}
/********************************************************
* 函数说明:12864初始化函数 *
********************************************************/
void LCD12864Init(void)
{
LCD12864_Start;
LCD12864_Reset;
LCD12864_ChooseBoth;
LCD12864_SetLCD_OFF;
setX(0);
setStartLine(0);
setY(0);
LCD12864_SetLCD_ON;
ClearLCD();
}
/********************************************************
* 函数说明:图片显示函数 *
* 输入: 图片数组,尺寸,显示位置 *
********************************************************/
void LCD12864DispPicture(flash char *PIC,char Width,char Height,char Top,char Left)
{
char X = 0,Y = 0;
for (Y = 0;Y < (Height >>3);Y ++)
{
LCD12864_ChooseBoth;
setX(Y);
for (X = 0;X < Width;X ++)
{
if (X <64)
{
LCD12864_ChooseCS1;
setY(X);
}
else
{
LCD12864_ChooseCS2;
setY(X - 64);
}
sendDataToLCD(PIC[Y*Width+X]);
}
}
}
#endif
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -