驱动测试代码如下:(实现对1602液晶的显示) //lcd1602.c代码
#include "lcd1602.h"
sbit rs = P2^7;
sbit rw = P2^6;
sbit en = P2^5;
#define Lcd_Date P3
/*****************************************************
*函数名称:Lcd1602_Delay(unsigned int c)
*函数功能:lcd1602延时函数
*入口参数:unsigned int c
*出口参数:void
*****************************************************/
void Lcd1602_Delay(unsigned int c)
{
unsigned char a,b;
for (; c>0; c--)
{
for (b=199;b>0;b--)
for(a=4;a>0;a--);
}
}
/*****************************************************
*函数名称:void LcdWriteCom(unsigned char cmd)
*函数功能:lcd1602写指令函数
*入口参数:unsigned char cmd
*出口参数:void
*****************************************************/
void LcdWriteCom(unsigned char cmd)
{
rs = 0;
rw = 0;
en = 0;
Lcd_Date = cmd;
Lcd1602_Delay(1);
en = 1;
Lcd1602_Delay(5);
en = 0;
}
/*****************************************************
*函数名称:void LcdWriteData(unsigned char date)
*函数功能:lcd1602写数据函数
*入口参数:unsigned char date
*出口参数:void
*****************************************************/
void LcdWriteData(unsigned char date)
{
rs = 1;
rw = 0;
en = 0;
Lcd_Date = date;
Lcd1602_Delay(1);
en = 1;
Lcd1602_Delay(5);
en = 0;
}
/*****************************************************
*函数名称:void LcdInit(void)
*函数功能:lcd1602初始化函数
*入口参数:void
*出口参数:void
*****************************************************/
void LcdInit(void)
{
LcdWriteCom(0x38); //开显示
Lcd1602_Delay(5);
LcdWriteCom(0x0c); //不显示光标
Lcd1602_Delay(5);
LcdWriteCom(0x06); //写1个指针加1
Lcd1602_Delay(5);
LcdWriteCom(0x01); //清屏
Lcd1602_Delay(5);
LcdWriteCom(0x80); //设置数据指针起点
Lcd1602_Delay(5);
}
/*****************************************************
*函数名称:void DisplayOneChar(unsigned char X, unsigned char Y, unsigned char DData)
*函数功能:按指定位置显示一个字符
*入口参数:unsigned char X, unsigned char Y, unsigned char DData,限制X不能大于15,Y不能大于1
*出口参数:void
*****************************************************/
void DisplayOneChar(unsigned char X, unsigned char Y, unsigned char DData)
{
Y &= 0x1;
X &= 0xF; //限制X不能大于15,Y不能大于1
if (Y) X |= 0x40; //当要显示第二行时地址码+0x40;
X |= 0x80; // 算出指令码
LcdWriteCom(X); //这里不检测忙信号,发送地址码
LcdWriteData(DData);
}
/*****************************************************
*函数名称:void DisplayListChar(unsigned char X, unsigned char Y, unsigned char code *DData)
*函数功能:按指定位置显示一个字符串
*入口参数:unsigned char X, unsigned char Y, unsigned char code *DData,限制X不能大于15,Y不能大于1
*出口参数:void
*****************************************************/
void DisplayListChar(unsigned char X, unsigned char Y, unsigned char code *DData)
{
unsigned char ListLength;
ListLength = 0;
Y &= 0x1;
X &= 0xF; //限制X不能大于15,Y不能大于1
while (DData[ListLength]>=0x20) //若到达字串尾则退出
{
if (X <= 0xF) //X坐标应小于0xF
{
DisplayOneChar(X, Y, DData[ListLength]); //显示单个字符
ListLength++;
X++;
}
}
}
|