⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 lcddrive.c

📁 ADS环境下的LCD程序
💻 C
字号:
/****************************************Copyright (c) ****************************************
**                               Guangzhou ZHIYUAN electronics Co.,LTD.
**                                     
**                                 http://www.embedtools.com
**
**―――File Info――――――――――――――――――――――――――――――――――――――
** File name:			LCDDRIVE.C
** Last modified Date:  
** Last Version:		
** Descriptions:		图形液晶240*128驱动(型号为SMG240128A)。32K显示存,0000H-7FFFH地址。显示
*                       是横向字节,高位在前。
**                		图形液晶采用T6963C为LCD控制芯片,内带负压产生器,单5伏供电,并行接口。
**――――――――――――――――――――――――――――――――――――――――――――――
** Created by:			
** Created date:		
** Version:				
** Descriptions:		
**
**――――――――――――――――――――――――――――――――――――――――――――――
** Modified by:			
** Modified date:		
** Version:		        
** Descriptions:		
**
*******************************************************************************************/

#include "main.h"

uint8  	gui_disp_buf[GUI_LCM_YMAX][GUI_LCM_XMAX/8];				// 声明显示缓冲区


/*******************************************************************************************
**函数名称:LCD_TestStaBit01()
**函数功能:判断读写指令和读写数据是否允许。
**入口参数:无
**返 回 值:返回0表示禁止,否则表示允许
**说    明:
*******************************************************************************************/
uint8  LCD_TestStaBit01(void)
{  uint8 i;

   for(i=100; i>0; i--)
   {  if( (LCD_ReadState()&0x03)==0x03 ) break;
   }
   
   return(i);
}

/*******************************************************************************************
**函数名称:LCD_TestStaBit3()
**函数功能:数据自动写状态是否允许。
**入口参数:无
**返 回 值:返回0表示禁止,否则表示允许
**说    明:
*******************************************************************************************/
uint8  LCD_TestStaBit3(void)
{  uint8 i;

   for(i=100; i>0; i--)
   {  if( (LCD_ReadState()&0x08)==0x08 ) break;
   }
   
   return(i);
}

/*******************************************************************************************
**函数名称:LCD_WriteTCommand1()
**函数功能:写无参数命令子程序。会先判断LCM状态字。
**入口参数:command  		要写入LCM的命令字
**返 回 值:操作出错返回0,否则返回1
**说    明:
*******************************************************************************************/
uint8  LCD_WriteTCommand1(uint8 command)
{  if( LCD_TestStaBit01()==0 ) return(0);
   LCD_WriteCommand(command);		// 发送命令字
   
   return(1);
}

/*******************************************************************************************
**函数名称:LCD_WriteTCommand3()
**函数功能:写双参数命令子程序。会先判断LCM状态字。
**入口参数:command  	要写入LCM的命令字
*           dat1		参数1
*           dat2		参数2
**返 回 值:操作出错返回0,否则返回1
**说    明:先发送两字节参数据数据,再发送命令字
*******************************************************************************************/
uint8  LCD_WriteTCommand3(uint8 command, uint8 dat1, uint8 dat2)
{  if( LCD_TestStaBit01()==0 ) return(0);
   LCD_WriteData(dat1);				// 发送数据1
   
   if( LCD_TestStaBit01()==0 ) return(0);
   LCD_WriteData(dat2);				// 发送数据2
   
   if( LCD_TestStaBit01()==0 ) return(0);
   LCD_WriteCommand(command);		// 发送命令字
   
   return(1);
}

/*******************************************************************************************
**函数名称:LCD_WriteTCommand2()
**函数功能:写单参数命令子程序。会先判断LCM状态字。
**入口参数:command  	要写入LCM的命令字
*           dat1		参数1
**返 回 值:操作出错返回0,否则返回1
**说    明:先发送参数据数据,再发送命令字
*******************************************************************************************/
uint8  LCD_WriteTCommand2(uint8 command, uint8 dat1)
{  if( LCD_TestStaBit01()==0 ) return(0);
   LCD_WriteData(dat1);				// 发送数据1
   
   if( LCD_TestStaBit01()==0 ) return(0);
   LCD_WriteCommand(command);		// 发送命令字
   
   return(1);
}

/*******************************************************************************************
**函数名称:LCD_WriteTData1()
**函数功能:写1字节数据子程序。会先判断状态字。
**入口参数:dat  		要写入LCM的数据
**返 回 值:操作出错返回0,否则返回1
**说    明:
*******************************************************************************************/
uint8  LCD_WriteTData(uint8 dat)
{  if( LCD_TestStaBit3()==0 ) return(0);
   LCD_WriteData(dat);				// 发送命令字
   
   return(1);
}


/* 以下为LCM的用户接口层,主要负责解释用户命令,并发送到LCM,为用户编程提供接口 */

/*******************************************************************************************
**函数名称:LCD_Initialize()
**函数功能:LCM初始化,将LCM初始化为纯图形模式,显示起始地址为0x0000,。
**入口参数:无
**返 回 值:无
**说    明:函数会设置LCM数据总线为输出方式
*******************************************************************************************/
void  LCD_Initialize(void)
{  LCD_WriteTCommand3(LCD_TXT_STP, 0x00, 0x00);			// 设置文本方式RAM起始地址
   LCD_WriteTCommand3(LCD_TXT_WID, 30, 0x00);			// 设置文本模式的宽度,宽度为N/6或N/8,N为宽度点数,如240
   LCD_WriteTCommand3(LCD_GRH_STP, 0x00, 0x00);			// 设置图形方式RAM起始地址
   LCD_WriteTCommand3(LCD_GRH_WID, 30, 0x00);			// 设置图形模式的宽度,宽度为N/6或N/8,N为宽度点数,如240
   LCD_WriteTCommand1(LCD_MOD_OR);						// 设置显示方式为"或"
   LCD_WriteTCommand1(LCD_DIS_SW|0x08);					// 设置纯图形显示模式
}

/*******************************************************************************************
**函数名称:LCD_FillAll()
**函数功能:LCD填充。以图形方式进行填充,起始地址为0x0000。
**入口参数:dat		要填充的数据
**返 回 值:无
**说    明:
*******************************************************************************************/
void  LCD_FillAll(uint8 dat)
{  uint32  i;

   LCD_WriteTCommand3(LCD_ADR_POS, 0x00, 0x00);			// 置地址指针
   LCD_WriteTCommand1(LCD_AUT_WR);						// 自动写
   for(i=0;i<128*30;i++)
   {  LCD_WriteTData(dat);								// 写数据
   }
   LCD_WriteTCommand1(LCD_AUT_OVR);						// 自动写结束
   LCD_WriteTCommand3(LCD_ADR_POS,0x00,0x00);			// 重置地址指针
}

/*******************************************************************************************
**函数名称:LCD_UpdatePoint()
**函数功能:在指定位置上画点,刷新某一点。
**入口参数:x		指定点所在列的位置
*           y		指定点所在行的位置
**返 回 值:返回值为1时表示操作成功,为0时表示操作失败。
**说    明:操作失败原因是指定地址超出缓冲区范围。
*******************************************************************************************/
void  LCD_UpdatePoint(uint32 x, uint32 y)
{  uint32  addr; 
 
   /* 找出目标地址 */
   addr = y*(GUI_LCM_XMAX>>3) + (x>>3);
   LCD_WriteTCommand3(LCD_ADR_POS, addr&0xFF, addr>>8);	// 置地址指针
   
   /* 输出数据 */
   LCD_WriteTCommand2(LCD_INC_WR, gui_disp_buf[y][x>>3]);
}













⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -