📄 hy333hy.c
字号:
/*========================================
1602lcd模块驱动程序
==========================================
说明: 1.晶体:11.0592MHz
2.1602驱动:ks0066
******************************************/
#include <At89s51.h>
#include <string.h>
//#include <intrins.h>
sbit LCM_RS = P3^3; /*寄存器选择*/
sbit LCM_RW = P3^4; /*读/ 写控制*/
sbit LCM_E = P3^5; /*读/ 写使能*/
//bit flag =0;
#define LCM_Data P1
//函数声明
void Delay5ms(void);
void Delay400ms(void);
void LCM_Write_Command(unsigned char WC_LCM,bit Busy_C);
/***********************************
//函数名称: void LCM_Initial(void)
//传递参数: 无
//返 回 值: 无
//函数功能: LCM初始化
//函数说明:
***********************************/
void LCM_Initial(void)
{
LCM_Data = 0;
LCM_Write_Command(0x38,0); //16*2显示,5*7点阵,8位数据接口,不检测忙
Delay5ms();
LCM_Write_Command(0x38,0); //规定这个过程不能检测忙,否则无法正常工作
Delay5ms();
LCM_Write_Command(0x38,0); //三次显示模式, 不检测忙
Delay5ms();
LCM_Write_Command(0x38,1); //16*2显示,5*7点阵,8位数据接口,需要检测忙
LCM_Write_Command(0x80,1); //关闭显示
LCM_Write_Command(0x01,1); //清显示
LCM_Write_Command(0x06,1); //指针和光标+1,不滚屏
LCM_Write_Command(0x0c,1); //开显示,不显示光标
}
/***********************************
//函数名称: unsigned char LCM_Read_Status(void)
//传递参数: 无
//返 回 值: unsigned char
//函数功能: 读LCM状态,等待LCM空闲
//函数说明: DB7=1,忙
***********************************/
void LCM_Read_Status(void)
{
LCM_Data= 0xff;
//LCM_E = 0;
LCM_RS = 0;
LCM_RW = 1;
LCM_E = 1;
while(LCM_Data & 0x80);
LCM_E = 0;
//return LCM_Data;
}
/***********************************
//函数名称: void LCM_Write_Data(unsigned char WD_LCM)
//传递参数: unsigned char WD_LCM
//返 回 值: 无
//函数功能: LCM写数据
//函数说明:
***********************************/
void LCM_Write_Data(unsigned char WD_LCM)
{
LCM_Read_Status(); //判断LCM忙标志
//LCM_E = 0;
LCM_RS = 1;
LCM_RW = 0;
LCM_E = 1;
LCM_Data= WD_LCM;
LCM_E = 0;
}
/***********************************
//函数名称: void LCM_Write_Command(unsigned char WC_LCM, Busy_C)
//传递参数: unsigned char WC_LCM, Busy_C
//返 回 值: 无
//函数功能: LCM写命令
//函数说明: Busy_C=0是,不用检测忙信号
***********************************/
void LCM_Write_Command(unsigned char WC_LCM,bit Busy_C)
{
if (Busy_C)
{
LCM_Read_Status();
}
//LCM_E = 0;
LCM_RS = 0;
LCM_RW = 0;
LCM_E = 1;
LCM_Data= WC_LCM;
LCM_E = 0;
}
/***********************************
//函数名称: void disp_one_char(unsigned char x, unsigned char y,unsigned char disp_data)
//传递参数: unsigned char x, unsigned char y,unsigned char disp_data
//返 回 值: 无
//函数功能: 指定位置显示一个字符
//函数说明:
***********************************/
void disp_one_char(unsigned char x,unsigned char y,unsigned disp_data)
{
//y = y&0x01; //限制2 行
//x = x&0x0f; //每行15 个字
if (y)
{
x = x + 0x40; //算RAM 地址
}
x = x + 0x80;
/*if(flag==0)
{
LCM_Write_Command(x,1);
flag = 1;
}*/
LCM_Write_Command(x,1);
LCM_Write_Data(disp_data);
}
/***********************************
//函数名称: void disp_one_char(unsigned char x, unsigned char y,unsigned char *disp_data)
//传递参数: unsigned char x, unsigned char y,unsigned char *disp_data
//返 回 值: 无
//函数功能: 指定位置显示一串字符
//函数说明:
***********************************/
void Disp_List_Char(unsigned char x,unsigned char y,unsigned char *disp_data)
{
unsigned char char_length,j;
char_length = strlen(disp_data);
y = y&0x1; //限制2 行
x = x&0x0f;
//_nop_(); //每行15 个字
//flag = 0;
for (j=0;j<char_length;j++)
{
disp_one_char(x,y,*(disp_data+j)); //显示一个字符
x++;
}
}
/***********************************
//函数名称: void Delay5ms(void)
//传递参数: 无
//返 回 值: 无
//函数功能: 延时5MS
//函数说明:
***********************************/
void Delay5ms(void)
{
unsigned int TempCyc = 5552;
while(TempCyc--);
}
/***********************************
//函数名称: void Delay400ms(void)
//传递参数: 无
//返 回 值: 无
//函数功能: L延时400MS
//函数说明: LCM开机延时
***********************************/
void Delay400ms(void)
{
unsigned char TempCycA = 5;
unsigned int TempCycB;
while(TempCycA--)
{
TempCycB=7269;
while(TempCycB--);
};
}
/*****d******************************
//函数名称: void main(void)
//传递参数: 无
//返 回 值: 无
//函数功能: 主函数
//函数说明:
************************************/
void main(void)
{
int i = 0;
Delay400ms(); //延时至少15ms 等待电源稳定
LCM_Initial(); //LCM初始化
Disp_List_Char(4,0,"HY333HY");
Disp_List_Char(4,1,"LY333LY");
// char *disp_data; //或者char *disp_data ="HY333HY";
// disp_data ="HY333HY"; //等价程序形式用字符串代替指针
// Disp_List_Char(unsigned char x, unsigned char y, unsigned char * disp_data);
for(i=0;i<5;i++)
{
LCM_Write_Command(0x18, 1);
Delay400ms();
}
while(1)
{
for(i=0;i<9;i++)
{
LCM_Write_Command(0x1c, 1);
Delay400ms();
}
for(i=0;i<9;i++)
{
LCM_Write_Command(0x18, 1);
Delay400ms();
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -