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

📄 lcd.c

📁 PCF8563的驱动程序
💻 C
字号:
/******************************************************************************/
/**
/** 模 块 名: -------------------Virtual_UART.C-----------------------------
/**            -----------------虚拟串口调试------------------------------*/
/** 功能描述: 
/**
/** 创 建 人: huangtiexiong   	日期:2006-11-28   */
/** 修 改 人:                 	日期:2006-11-28   */ 
/** 其他说明: 
/******************************************************************************/

#include "Includes.h"


/*************************************************
    模块级变量申明                 
*************************************************/
static void 	LCD_WriteDat(int8u lcd_dat);
static void 	LCD_WriteCmd(int8u lcd_cmd);
static int8u 	LCD_ReadStatus(void);
static void 	LCD_Goto(int8u x,int8u y);

/*******************************************************************************
*** 函 数 名: void LCD_Init(void)
*** 功能描述: 
*** 全局变量: 
*** 输		入: 
*** 输		出: 
*** 创 建 人:huangtiexiong			  日期:2006-11-28
*** 修 改 人:			 							日期:2006-11-28
*** 函数说明: 字符LCD初始化;
/******************************************************************************/
extern void 	LCD_Init(void)
{
	Delay20ms();
	/*************************************************
	 功能设置:	DB5=1;DB6...=0;
	 						DB4=1:8位接口; 0:4位接口;
	 						DB3=1:双行显示;0:单行显示;
	 						DB3=1:5×10点阵;0:5×7点阵;                
	*************************************************/
  LCD_WriteCmd(0x38);	//8位机接口、双行显示、5×7字符点阵;
	/*************************************************
	  显示控制:DB3=1;DB4...=0;
	  					DB2=1:开启显示;0:关闭LCD显示;
	  					DB1=1:显示光标;0:光标隐藏;
	  					DB0=1:光标闪烁;0:光标闪烁关闭;
	*************************************************/
	LCD_WriteCmd(0x0c);	//显示开启、光标不显示也不闪烁;
	/*************************************************
	  清屏指令:DB0=1;DB1...=0;
	*************************************************/
	LCD_WriteCmd(0x01);	//清屏;
	/****************************************************************
	  访问模式:DB2=1;DB3...=0;
	  					DB1=1:对内部Ram读写后AC自增,否则自减;
	  					DB0=1:与DB1设置有关,对DD RAM写时同时整屏移动1位;
	*****************************************************************/
	LCD_WriteCmd(0x06);	//光标右移一位、整屏不移动;
  
  LCD_Goto(0,0);
	}
static void 	LCD_WriteDat(int8u lcd_dat)
{
	int8u tmp;
	tmp = LCD_ReadStatus();		//读状态;
	while((tmp & 0x80))			//是否忙 ?
		{
			tmp = LCD_ReadStatus();
			}
	#if 0
	LCD_RS = 1;
	LCD_RW = 0;
	LCD_EN = 1;
  _nop_();
  _nop_();
	LCD_DATA = lcd_dat;
  _nop_();
  _nop_();
	LCD_EN = 0;		
	#endif
	LCD_RS = 1;
	LCD_RW = 0;
	LCD_DATA = lcd_dat;
	_nop_();
	LCD_EN = 0;
	_nop_();
	_nop_();
	LCD_EN = 1;
	
	}
static void 	LCD_WriteCmd(int8u lcd_cmd)
{
	int8u tmp;
	tmp = LCD_ReadStatus();
	while((tmp & 0x80))
	{
		tmp = LCD_ReadStatus();
		}
	#if 0
	LCD_RS = 0;
	LCD_RW = 0;
	LCD_EN = 1;
  _nop_();
  _nop_();
	LCD_DATA = lcd_cmd;
  _nop_();
  _nop_();
	LCD_EN = 0;	
	#endif
	LCD_RS = 0;
	LCD_RW = 0;
	LCD_DATA = lcd_cmd;
	_nop_();
	LCD_EN = 0;
	_nop_();
	_nop_();
	LCD_EN = 1;
	}
static int8u 	LCD_ReadStatus(void)
{
	int8u tmp;
	#if 0
	LCD_RS = 0;
	LCD_RW = 1;
	LCD_EN = 1;
	tmp = LCD_DATA;
	LCD_EN = 0;
	#endif
	LCD_DATA = 0xff;
	LCD_RS = 0;
	LCD_RW = 1;
	LCD_EN = 0;
	_nop_();
	_nop_();
	LCD_EN = 1;
	tmp = LCD_DATA;
	return tmp;
	}
static void 	LCD_Goto(int8u x,int8u y)
{
	int8u tmp;
	if(y)				//若是第二行;
		{
			tmp = 0xc0 + x;
			LCD_WriteCmd(tmp);
			}
	else
		{
			tmp = 0x80 + x;
			LCD_WriteCmd(tmp);
			}		
	}

#if 0
extern void LCD_DisplayShiftR(void)				//整屏右移;
{
	LCD_WriteCmd(0x1f);
	}

extern void LCD_DisplayShiftL(void)				//整屏左移;
{
	LCD_WriteCmd(0x18);
	}
#endif	
	
extern void LCD_Display(int8u row,int8u *str)
{
	if(row)
		{
			LCD_Goto(0,1);
			}
  else 
  	{
  		LCD_Goto(0,0);
  		}
  while(*str != '\0')
  {
  	LCD_WriteDat(*str++);
  	}
	}

#if 0
extern void LCD_Display(int8u x,int8u y,int8u disp_dat)
{
	LCD_Goto(x,y);
	LCD_WriteDat(disp_dat);
	}
#endif

#if 0	
extern void 	LCD_Display(int8u disp_dat)
{
	int8u tmp;
	tmp = LCD_ReadStatus();
	tmp &= 0x7f;  
	if(tmp == 0x10)			//第一行显示满则转向第二行;
		{
			LCD_Goto(0,1);
			}
	if(tmp == 0x50)			//全屏显示满则清屏;
		{
			LCD_WriteCmd(0x01);
			}
	LCD_WriteDat(disp_dat);		//将接收字符显示在LCD屏上;
	}
#endif

extern void Delay20ms()   //粗略延时;
{
  int16u tmp = 50000;
  while(tmp--);
  }
/*******************************************************************************
****                              End Of File
*******************************************************************************/

⌨️ 快捷键说明

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