/************************************************************************************
FILE NAME : LCD.C
DESCRIPTION : LCD Module utility functions.
Written for KS0066u compatible LCD Module.
(8 characters by 2 lines)
Copyright : 2006 Renesas Technology Europe Ltd.
Copyright : 2006 Renesas Technology Corporation.
All Rights Reserved
***********************************************************************************/
/***********************************************************************************
Revision History
DD.MM.YYYY OSO-UID Description
27.03.2006 RTE-NPS First Release
***********************************************************************************/
/**********************************************************************************
System Includes
***********************************************************************************/
/**********************************************************************************
User Includes
***********************************************************************************/
/* sfr26a.h provides a structure to access all of the device registers. */
#include "sfr26a.h"
/* RSKM16C26Adef.h provides common defines for widely used items. */
#include "rskM16C26Adef.h"
#include "lcd.h"
/**********************************************************************************
Global variables
***********************************************************************************/
/**********************************************************************************
User Program Code
***********************************************************************************/
/*****************************************************************************
Name: InitDisplay
Parameters: none
Returns: none
Description: Intializes the LCD display.
*****************************************************************************/
void InitialiseDisplay( void )
{
/* Power Up Delay for LCD Module */
EN_PIN = SET_BIT_HIGH;
DisplayDelay(7000);
EN_PIN = SET_BIT_LOW;
/* Display initialises in 8 bit mode - so send one write (seen as 8 bit)
to set to 4 bit mode. */
/* Function Set */
LCD_nibble_write(CTRL_WR,0x03);
LCD_nibble_write(CTRL_WR,0x03);
DisplayDelay(39);
/* Configure display */
LCD_nibble_write(CTRL_WR,0x03);
LCD_nibble_write(CTRL_WR,0x02);
LCD_nibble_write(CTRL_WR,(LCD_DISPLAY_ON | LCD_TWO_LINE ));
LCD_nibble_write(CTRL_WR,(LCD_DISPLAY_ON | LCD_TWO_LINE ));
DisplayDelay(39);
/* Display ON/OFF control */
LCD_write(CTRL_WR,LCD_CURSOR_OFF);
DisplayDelay(39);
/* Display Clear */
LCD_write(CTRL_WR,LCD_CLEAR);
DisplayDelay(1530);
/* Entry Mode Set */
LCD_write(CTRL_WR,0x06);
LCD_write(CTRL_WR,LCD_HOME_L1);
}
/*****************************************************************************
Name: DisplayString
Parameters: position Line number of display
string Pointer to data to be written to display.
Last character should be null.
Returns: none
Description: This function controls LCD writes to line 1 or 2 of the LCD.
You need to use the defines LCD_LINE1 and LCD_LINE2 in order
to specify the starting position.
For example, to start at the 2nd position on line 1...
DisplayString(LCD_LINE1 + 1, "Hello")
*****************************************************************************/
void DisplayString(unsigned char position, _far char * string)
{
static unsigned char next_pos = 0xFF;
/* Set line position if needed. We don't want to if we don't need
to because LCD control operations take longer than LCD data
operations. */
if( next_pos != position)
{
if(position < LCD_LINE2)
{
/* Display on Line 1 */
LCD_write(CTRL_WR, (unsigned char)(LCD_HOME_L1 + position) );
}
else
{
/* Display on Line 2 */
LCD_write(CTRL_WR, (unsigned char)(LCD_HOME_L2 + position - LCD_LINE2) );
}
/* set position index to known value */
next_pos = position;
}
do
{
LCD_write(DATA_WR,*string++);
/* increment position index */
next_pos++;
}
while(*string);
}
/*****************************************************************************
Name: LCD_write
Parameters: value - the value to write
data_or_ctrl - To write value as DATA or CONTROL
1 = DATA
0 = CONTROL
Returns: none
Description: Writes data to display. Sends command to display.
*****************************************************************************/
void LCD_write(unsigned char data_or_ctrl, unsigned char value)
{
/* Write upper nibble first */
LCD_nibble_write(data_or_ctrl, (value & 0xF0) >> 4);
/* Write lower nibble second */
LCD_nibble_write(data_or_ctrl, (value & 0x0F));
}
/*****************************************************************************
Name: LCD_nibble_write
Parameters: value - the value to write
data_or_ctrl - To write value as DATA or CONTROL
1 = DATA
0 = CONTROL
Returns: none
Description: Writes data to display. Sends command to display.
*****************************************************************************/
void LCD_nibble_write(unsigned char data_or_ctrl, unsigned char value)
{
unsigned char ucStore;
/* Set Register Select pin high for Data */
if (data_or_ctrl == DATA_WR)
{
RS_PIN = SET_BIT_HIGH;
}
else
{
RS_PIN = SET_BIT_LOW;
}
/* There must be 40ns between RS write and EN write */
DisplayDelay(1);
/* EN enable chip (HIGH) */
EN_PIN = SET_BIT_HIGH;
/* Tiny delay */
DisplayDelay(1);
/* Clear port bits used */
ucStore = DATA_PORT;
ucStore &= ~DATA_PORT_MASK;
/* OR in data */
ucStore |= ((value << DATA_PORT_SHIFT) & DATA_PORT_MASK );
/* Write data to port */
DATA_PORT = ucStore;
/* write delay while En High */
DisplayDelay(20);
/* Latch data by dropping EN */
EN_PIN = SET_BIT_LOW;
/* Data hold delay */
DisplayDelay(20);
if (data_or_ctrl == CTRL_WR)
{
/* Extra delay needed for control writes */
DisplayDelay(0x7FF);
}
}
/*****************************************************************************
Name: DisplayDelay
Parameters: units - Approximately in microseconds
Returns: none
Description: Delay routine for LCD display.
*****************************************************************************/
void DisplayDelay(unsigned long int units)
{
unsigned long counter = units * DELAY_TIMING;
while(counter--)
{
asm("nop");
}
}
steve_duyiling
- 粉丝: 0
- 资源: 2
最新资源
- 社交网络引流副业的简易实施策略及收益分析
- 西门子消防图层显示软件
- 基于Node.js和Express框架的租房系统房屋出租管理后端设计源码
- VideoSpeed_87621.zip
- 基于Typescript和CSS的八电极指标报告PDF设计源码
- 短视频游戏推广副业快速获利-通过快手小游戏合伙人计划轻松入行
- MATLAB仿真均匀光纤布拉格光栅 传输矩阵法 可以仿真得到其透射谱与反射谱
- 基于Vue框架的快递代取后台管理新版本设计源码
- Linux驱动开发环境Ubuntu,已经制作好网络文件系统和zImage内核,已经交叉编译好Qt5.6.2 1.安装好交叉编译工具链 2.制作好网络文件系统 3.已经编译好Linux内核源码树(版本
- 基于广西忻城红渡初中22班的HTML, JavaScript, CSS同学录设计源码
- MATLAB环境下一种时间序列信号的基线消除算法 算法运行环境为MATLAB r2018a 1.所有代码均经过运行测试,没有问题 2.前请仔细阅读作品简介,这非常重要,因为涉及到不同的编程语言
- 基于Mql5语言的MT5客户端直连期货公司CTP柜台的期货程序化交易软件设计源码
- containerd源码1.7.22 tag
- 基于Java语言的Swing游戏引擎设计源码
- MATLAB环境下一种基于粒子群优化算法神经网络非线性函数拟合方法 算法运行环境为MATLAB R2018a,执行基于粒子群优化算法神经网络非线性函数拟合,并与其他改进的粒子群算法进行对比,结果如下
- 图像处理实验、图像分割 1打开计算机,安装和启动MATLAB程序;程序组中“work”文件夹中应有待处理的图像文件; 2对于血细胞图像 a).对图像进行去噪、增强处理; b)运用
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈