📄 lcd_driver_user.c
字号:
//========================================================================
// 文件名: LCD_Driver_User.c
// 作 者: kaka.IN Hisense
// sn.kaka@yahoo.com
// 日 期: 2007/01/07
// 描 述: 底层接口驱动扩展程序集
//
// 参 考: 请参考具体显示器的硬件描述说明书或者是DataSheet,并以此来编写底
// 层接口驱动程序,以及LCD的初始化代码
// 版 本:
// 2007/01/09 First version Mz Design
// 注 意: 适用于MzL02-12864 LCD模块,16位无byte操作指令的MCU
//========================================================================
#include "LCD_Config.h"
#include "LCD_PortConfig.h"
#define t_timedelay(a); TimeDelay(1);
void TimeDelay(int Time);
//========================================================================
// 函数: void LCD_DataWrite(unsigned int Data)
// 描述: 写一个字节的显示数据至LCD中的显示缓冲RAM当中
// 参数: Data 写入的数据
// 返回: 无
// 备注: 无
// 版本:
// 2007/01/09 First version
//========================================================================
void LCD_DataWrite(unsigned char Data)
{
LCD_AO_1;
t_timedelay(a);
LCD_RW_0;
t_timedelay(a);
LCD_EP_0; /*一定要把LCD_RW_0放到LCD_CS_0;的前面*/
t_timedelay(a);
LCD_CS_0;
t_timedelay(a);
//TimeDelay(1);
DATA_PORT=Data;
t_timedelay(a);
//TimeDelay(1);
//LCD_EP_0;
LCD_EP_1;
t_timedelay(a);
//LCD_CS_1;
//LCD_RW_1;
//TimeDelay(1);
LCD_CS_1;
t_timedelay(a);
}
//========================================================================
// 函数: void LCD_RegWrite(unsigned int Command)
// 描述: 写一个字节的数据至LCD中的控制寄存器当中
// 参数: Command 写入的数据,低八位有效(byte)
// 返回: 无
// 备注:
// 版本:
// 2007/01/09 First version
//========================================================================
/*
void LCD_RegWrite(unsigned char Command)
{
LCD_AO_0;
LCD_RW_0;
LCD_CS_0;
DATA_PORT = Command;
LCD_EP_0;
LCD_EP_1;
LCD_CS_1;
LCD_AO_1;
LCD_RW_1;
}
*/ /*对时序探索*/
void LCD_RegWrite(unsigned char Command)
{
LCD_AO_0;
t_timedelay(a);
//TimeDelay(10);
LCD_RW_0;
t_timedelay(a);
//TimeDelay(10);
LCD_CS_0;
t_timedelay(a);
//TimeDelay(10);
DATA_PORT = Command;
//TimeDelay(1);
t_timedelay(a);
LCD_EP_0;
t_timedelay(a);
//PDATE=PDATE<<2;
//TimeDelay(10);
LCD_EP_1;
t_timedelay(a);
//TimeDelay(10);
LCD_CS_1;
t_timedelay(a);
//TimeDelay(1);
LCD_AO_1;
t_timedelay(a);
LCD_RW_1;
t_timedelay(a);
}
//========================================================================
// 函数: unsigned int LCD_DataRead(void)
// 描述: 从LCD中的显示缓冲RAM当中读一个字节的显示数据
// 参数: 无
// 返回: 读出的数据,低八位有效(byte)
// 备注:
// 版本:
// 2007/01/09 First version
// 注意:
//========================================================================
unsigned char LCD_DataRead(void)
{
unsigned char Read_Data;
PCOND=0x0; /*set the I/O D is input 0216*/
t_timedelay(a);
//DATA_PORT=0xff; //0216
LCD_AO_1;
t_timedelay(a);
LCD_CS_0;
//TimeDelay(5);
t_timedelay(a);
LCD_RW_1;
t_timedelay(a);
//TimeDelay(5);
//LCD_CS_0;
//TimeDelay(5);
LCD_EP_0;
t_timedelay(a);
//TimeDelay(5);
Read_Data=DATA_PORT;
t_timedelay(a);
LCD_EP_1;/*指令要在后面,不让无法正确读出DATA_PORT*/
t_timedelay(a);
//TimeDelay(5);
//LCD_CS_0;
//TimeDelay(5);
LCD_EP_0;
t_timedelay(a);
Read_Data=DATA_PORT;
t_timedelay(a);
//TimeDelay(1);
LCD_EP_1;/*指令要在后面,不让无法正确读出DATA_PORT*/
t_timedelay(a);
//TimeDelay(1);
LCD_CS_1;
t_timedelay(a);
PCOND = ((1<<14)+(1<<12)+(1<<10)+(1<<8)+(1<<6)+(1<<4)+(1<<2)+1); /*set the I/O D is output 0216*/
t_timedelay(a);
return Read_Data;
t_timedelay(a);t_timedelay(a);
}
//========================================================================
// 函数: void Write_Dot_LCD(int x,int y,unsigned int i)
// 描述: 在LCD的真实坐标系上的X、Y点绘制填充色为i的点
// 参数: x X轴坐标
// y Y轴坐标
// i 要填充的点的颜色
// 返回: 无
// 备注:
// 版本:
// 2006/10/15 First version
// 2007/01/09 V1.2
//========================================================================
void Write_Dot_LCD(int x,int y,unsigned int i)
{
unsigned int x_low,x_hight; //定义列地址的高低位指令
unsigned int Dot_Mask_Buf=0x0001;
unsigned int y_Page; //用于存放要画点的位置所在的byte数据位置
x = x+1;
x_low = (x&0x000f); //定位列地址设置的低位指令
x_hight = ((x>>4)&0x000f)+0x10; //定位列地址设置的高位指令
// y_Page = y&0x07; //取低三位
switch(y&0x07)
{
case 0: Dot_Mask_Buf = 0x0001;break;
case 1: Dot_Mask_Buf = 0x0002;break;
case 2: Dot_Mask_Buf = 0x0004;break;
case 3: Dot_Mask_Buf = 0x0008;break;
case 4: Dot_Mask_Buf = 0x0010;break;
case 5: Dot_Mask_Buf = 0x0020;break;
case 6: Dot_Mask_Buf = 0x0040;break;
case 7: Dot_Mask_Buf = 0x0080;break;
}
y_Page = (y>>3)+0x00b0; //Get the page of the byte
LCD_RegWrite(y_Page);
LCD_RegWrite(x_low);
LCD_RegWrite(x_hight);
// LCD_RegWrite(0xe0); //设置为读写改模式
y_Page = LCD_DataRead(); //
if(i) y_Page |= Dot_Mask_Buf;
else y_Page &= ~Dot_Mask_Buf;
LCD_DataWrite(y_Page); //
// LCD_RegWrite(0xee); //读写改模式结束
}
//========================================================================
// 函数: void LCD_PortInit(void)
// 描述: 与LCD连接的端口初始化代码
// 参数: 无
// 返回: 无
// 备注:
// 版本:
// 2007/01/09 First version
// 注意:
//========================================================================
void LCD_PortInit(void)
{
LCD_RS_0;
TimeDelay(500);
LCD_RS_1; /*because the portinit has been init in the boot loader ,so we can let it reset here */
}
//========================================================================
// 函数: void Clear_Dot_LCD(int x,int y)
// 描述: 清除在LCD的真实坐标系上的X、Y点
// 参数: x X轴坐标
// y Y轴坐标
// 返回: 无
// 备注: 暂不使用该函数
// 版本:
// 2006/10/15 First version
//========================================================================
void Clear_Dot_LCD(int x,int y)
{
//可根据自己的需要填写代码
}
//========================================================================
// 函数: unsigned int Get_Dot_LCD(int x,int y)
// 描述: 获取在LCD的真实坐标系上的X、Y点上的当前填充色数据
// 参数: x X轴坐标
// y Y轴坐标
// 返回: 该点的颜色
// 备注: 暂不使用该函数
// 版本:
// 2006/10/15 First version
//========================================================================
unsigned int Get_Dot_LCD(int x,int y)
{
unsigned int Read_Data;
//可根据自己的需要填写代码
return Read_Data;
}
//========================================================================
// 函数: void Set_Dot_Addr_LCD(int x,int y)
// 描述: 设置在LCD的真实坐标系上的X、Y点对应的RAM地址
// 参数: x X轴坐标
// y Y轴坐标
// 返回: 无
// 备注: 仅设置当前操作地址,为后面的连续操作作好准备
// 版本:
// 2006/10/15 First version
// 2007/01/09 V1.2
//========================================================================
void Set_Dot_Addr_LCD(int x,int y)
{
unsigned int x_low,x_hight; //定义列地址的高低位指令
unsigned int y_Page; //用于存放要画点的位置所在的byte数据位置
x = x+1;
x_low = (x&0x000f); //定位列地址设置的低位指令
x_hight = ((x>>4)&0x000f)+0x10; //定位列地址设置的高位指令
y_Page = (y>>3)+0x00b0; //Get the page of the byte
LCD_RegWrite(y_Page);
LCD_RegWrite(x_low);
LCD_RegWrite(x_hight);
}
//========================================================================
// 函数: void LCD_Fill(unsigned int Data)
// 描述: 会屏填充以Data的数据至各点中
// 参数: Data 要填充的颜色数据
// 返回: 无
// 备注: 仅在LCD初始化程序当中调用
// 版本:
// 2006/10/15 First version
// 2007/01/09 V1.2
//========================================================================
void LCD_Fill(unsigned int Data)
{
unsigned int i,j;
unsigned int uiTemp;
uiTemp = (unsigned int)Dis_Y_MAX;
uiTemp = uiTemp>>3;
for(i=0;i<=uiTemp;i++) //往LCD中填充初始化的显示数据
{
LCD_RegWrite(0xb0+i);
LCD_RegWrite(0x01);
LCD_RegWrite(0x10);
for(j=0;j<=Dis_X_MAX;j++)
{
/*TimeDelay(100);
TimeDelay(100);
TimeDelay(100);
TimeDelay(100);
TimeDelay(100);
TimeDelay(100);
TimeDelay(100);
TimeDelay(100);
TimeDelay(100);
TimeDelay(100);
TimeDelay(100);
TimeDelay(100);
TimeDelay(100);
TimeDelay(100);*/
LCD_DataWrite(Data);
}
TimeDelay(10);
}
}
//========================================================================
// 函数: void LCD_Fill_s(unsigned int Number,unsigned int Color)
// 描述: 连续填充以Color色调的Number个点
// 参数: Number 填充的数量 Color 像素点的颜色
// 返回:
// 备注: 该函数可能会使用到
// 版本:
// 2006/10/15 First version
// 2007/01/09 V1.2
//========================================================================
void LCD_Fill_s(unsigned int Number,unsigned int Color)
{
while(Number!=0)
{
LCD_DataWrite(Color); //
Number--;
}
}
//========================================================================
// 函数: void LCD_Init(void)
// 描述: LCD初始化程序,在里面会完成LCD初始所需要设置的许多寄存器,具体如果
// 用户想了解,建议查看DataSheet当中各个寄存器的意义
// 参数: 无
// 返回: 无
// 备注:
// 版本:
// 2006/10/15 First version
// 2007/01/09 V1.2
// 2007/06/27 V1.21
//========================================================================
//延时程序
void TimeDelay(int Time)
{
long i;
int a=0;
while(Time > 0)
{
for(i = 0;i <2;i++)
{
a++;
//PDATE=a>>4;
}
Time --;
}
}
void TimeDelay_led(int Time)
{
long i;
int a=0;
while(Time > 0)
{
for(i = 0;i < 10;i++)
{
a++;
//PDATE=a>>4;
}
Time --;
}
}
void STOP (void)
{ long a=0;
long b=0;
while(1)
{
b=0x59999;
while(b>0)
{b--;
}
a++;
PDATE=-a;
}
/*int a=0;
int b;
for(a=1;a<15;a++)
{
b++;
a=2;
}*/
}
void LCD_Init(void)
{
//LCD驱动所使用到的端口的初始化
LCD_PortInit(); //LCD的复位也在该函数中完成
LCD_RegWrite(M_LCD_ON); //LCD On
LCD_RegWrite(M_LCD_POWER_ALL); //设置上电控制模式
//LCD_RegWrite(M_LCD_ELE_VOL); //电量设置模式(显示亮度)
//LCD_RegWrite(0x1f); //指令数据0x0000~0x003f
//现将其注释掉,利用他的默认值
LCD_RegWrite(M_LCD_VDD_SET); //V5内部电压调节电阻设置
LCD_RegWrite(M_LCD_VDD); //LCD偏压设置,V3时选
LCD_RegWrite(M_LCD_COM_REV); //Com 扫描方式设置
LCD_RegWrite(M_LCD_SEG_NOR); //Segment方向选择
LCD_RegWrite(M_LCD_ALL_LOW);
LCD_RegWrite(M_LCD_ALL_LIGNT); //全屏点亮/变暗指令
LCD_RegWrite(M_LCD_ALL_LOW);
LCD_RegWrite(M_LCD_ALL_NOR); //正向反向显示控制指令
//STOP( );
LCD_RegWrite(M_LCD_STATIC_OFF); //关闭静态指示器
LCD_RegWrite(0x00); //指令数据
LCD_RegWrite(0xe0); //设置读写改模式
LCD_RegWrite(M_LCD_BEGIN_LINE+0); //设置显示起始行对应RAM
LCD_Fill(0x0);
LCD_Fill(LCD_INITIAL_COLOR);
LCD_Fill(0x0); //clear the screen
//STOP();
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -