#include "lcd1602.h"
#include <string.h>
#define LCD1602_ROW_NUM 2u
#define LCD1602_COLUMN_NUM 16u
#define LCD1602_READ_DATA() (LCD1602_DATAPINS)
#define LCD1602_WRITE_DATA(dat) (LCD1602_DATAPINS = (uint8_t)dat)
#define LCD1602_SET_RS_H() (LCD1602_RS = 1)
#define LCD1602_SET_RS_L() (LCD1602_RS = 0)
#define LCD1602_SET_RW_H() (LCD1602_RW = 1)
#define LCD1602_SET_RW_L() (LCD1602_RW = 0)
#define LCD1602_SET_E_H() (LCD1602_E = 1)
#define LCD1602_SET_E_L() (LCD1602_E = 0)
typedef enum
{
false = 0u,
true,
}Bool;
typedef enum
{
Ce_Sending = 0u,
Ce_SendOK,
}TeLCD1602_SendState;
typedef enum
{
Ce_SendAddr_00 = 0u,
Ce_SendData_00,
Ce_SendAddr_10,
Ce_SendData_10,
}TeLCD1602_SendStep;
typedef enum TeLCD1602_e_writeStateTypeTag
{
Ce_Stay_0 = 0u,
Ce_Stay_1 = 1u,
Ce_Stay_2 = 2u,
} TeLCD1602_e_writeStateType;
typedef struct TsLCD1602_h_RowParaTypeTag
{
const uint8_t* e_p_DisplayStartAddr;
const uint8_t* e_p_DisplayEndAddr;
} TsLCD1602_h_RowParaType;
typedef struct TsLCD1602_h_displayParaTypeTag
{
TeLCD1602_SendStep e_e_SendStep;
TeLCD1602_e_writeStateType e_e_WriteState;
TsLCD1602_h_RowParaType e_h_RowPara[LCD1602_ROW_NUM];
uint8_t* e_p_DisplayNextAddr;
} TsLCD1602_h_displayParaType;
static volatile uint8_t SeLCD1602_u_displayBuffer[LCD1602_ROW_NUM][LCD1602_COLUMN_NUM];
static volatile TsLCD1602_h_displayParaType SsLCD1602_h_displayPara;
static Bool MngLCD1602_IsBusy( void );
static void MngLCD1602_Display();
static TeLCD1602_SendState LcdWriteData( const uint8_t dat );
static TeLCD1602_SendState LcdWriteCom( const uint8_t com ) ;
static Bool MngLCD1602_IsBusy( void )
{
LCD1602_WRITE_DATA(0xff);
LCD1602_SET_RS_L();
LCD1602_SET_RW_H();
if( 0 != (LCD1602_READ_DATA() & 0x80) )
{
LCD1602_SET_E_L();
LCD1602_SET_E_H();
return true;
}
else
{
LCD1602_SET_E_L();
return false;
}
}
static TeLCD1602_SendState LcdWriteCom( const uint8_t com )
{
switch( SsLCD1602_h_displayPara.e_e_WriteState )
{
case Ce_Stay_0:
LCD1602_SET_RS_L();
LCD1602_SET_RW_L();
LCD1602_WRITE_DATA( com );
SsLCD1602_h_displayPara.e_e_WriteState = Ce_Stay_1;
return Ce_Sending;
break;
case Ce_Stay_1:
LCD1602_SET_E_H();
SsLCD1602_h_displayPara.e_e_WriteState = Ce_Stay_2;
return Ce_Sending;
break;
case Ce_Stay_2:
LCD1602_SET_E_L();
SsLCD1602_h_displayPara.e_e_WriteState = Ce_Stay_0;
return Ce_SendOK;
break;
default:
SsLCD1602_h_displayPara.e_e_WriteState = Ce_Stay_0;
return Ce_SendOK;
break;
}
}
static TeLCD1602_SendState LcdWriteData( const uint8_t dat )
{
switch( SsLCD1602_h_displayPara.e_e_WriteState )
{
case Ce_Stay_0:
LCD1602_SET_RS_H();
LCD1602_SET_RW_L();
LCD1602_WRITE_DATA( dat );
SsLCD1602_h_displayPara.e_e_WriteState = Ce_Stay_1;
return Ce_Sending;
break;
case Ce_Stay_1:
LCD1602_SET_E_H();
SsLCD1602_h_displayPara.e_e_WriteState = Ce_Stay_2;
return Ce_Sending;
break;
case Ce_Stay_2:
LCD1602_SET_E_L();
SsLCD1602_h_displayPara.e_e_WriteState = Ce_Stay_0;
return Ce_SendOK;
break;
default:
SsLCD1602_h_displayPara.e_e_WriteState = Ce_Stay_0;
return Ce_SendOK;
break;
}
}
static void MngLCD1602_Display( void )
{
switch(SsLCD1602_h_displayPara.e_e_SendStep)
{
case Ce_SendAddr_00:
if(Ce_Stay_0 == SsLCD1602_h_displayPara.e_e_WriteState)
{
if(false == MngLCD1602_IsBusy())
{
LcdWriteCom(0x80);
}
else
{
/* empty */
}
}
else if(Ce_SendOK == LcdWriteCom(0x80)) /* 第0,0位置开始显示 */
{
SsLCD1602_h_displayPara.e_e_SendStep = Ce_SendData_00;
SsLCD1602_h_displayPara.e_e_WriteState = Ce_Stay_0;
SsLCD1602_h_displayPara.e_p_DisplayNextAddr = SsLCD1602_h_displayPara.e_h_RowPara[0].e_p_DisplayStartAddr;
}
else
{
/* empty */
}
break;
case Ce_SendData_00:
if(Ce_Stay_0 == SsLCD1602_h_displayPara.e_e_WriteState)
{
if(false == MngLCD1602_IsBusy())
{
LcdWriteData(*SsLCD1602_h_displayPara.e_p_DisplayNextAddr);
}
else
{
/* empty */
}
}
else if(Ce_SendOK == LcdWriteData(*SsLCD1602_h_displayPara.e_p_DisplayNextAddr))
{
SsLCD1602_h_displayPara.e_p_DisplayNextAddr++;
if(SsLCD1602_h_displayPara.e_p_DisplayNextAddr > SsLCD1602_h_displayPara.e_h_RowPara[0].e_p_DisplayEndAddr)
{
SsLCD1602_h_displayPara.e_e_SendStep = Ce_SendAddr_10;
SsLCD1602_h_displayPara.e_e_WriteState = Ce_Stay_0;
SsLCD1602_h_displayPara.e_p_DisplayNextAddr = SsLCD1602_h_displayPara.e_h_RowPara[1].e_p_DisplayStartAddr;
}
else
{
/* empty */
}
}
else
{
/* empty */
}
break;
case Ce_SendAddr_10:
if(Ce_Stay_0 == SsLCD1602_h_displayPara.e_e_WriteState)
{
if(false == MngLCD1602_IsBusy())
{
LcdWriteCom(0x80 + 0x40);
}
else
{
/* empty */
}
}
else if(Ce_SendOK == LcdWriteCom(0x80 + 0x40)) /* 第0,1位置开始显示 */
{
SsLCD1602_h_displayPara.e_e_SendStep = Ce_SendData_10;
SsLCD1602_h_displayPara.e_e_WriteState = Ce_Stay_0;
SsLCD1602_h_displayPara.e_p_DisplayNextAddr = SsLCD1602_h_displayPara.e_h_RowPara[1].e_p_DisplayStartAddr;
}
else
{
/* empty */
}
break;
case Ce_SendData_10:
if(Ce_Stay_0 == SsLCD1602_h_displayPara.e_e_WriteState)
{
if(false == MngLCD1602_IsBusy())
{
LcdWriteData(*SsLCD1602_h_displayPara.e_p_DisplayNextAddr);
}
else
{
/* empty */
}
}
else if(Ce_SendOK == LcdWriteData(*SsLCD1602_h_displayPara.e_p_DisplayNextAddr))
{
SsLCD1602_h_displayPara.e_p_DisplayNextAddr++;
if(SsLCD1602_h_displayPara.e_p_DisplayNextAddr > SsLCD1602_h_displayPara.e_h_RowPara[1].e_p_DisplayEndAddr)
{
SsLCD1602_h_displayPara.e_e_SendStep = Ce_SendAddr_00;
SsLCD1602_h_displayPara.e_e_WriteState = Ce_Stay_0;
SsLCD1602_h_displayPara.e_p_DisplayNextAddr = SsLCD1602_h_displayPara.e_h_RowPara[0].e_p_DisplayStartAddr;
}
else
{
没有合适的资源?快使用搜索试试~ 我知道了~
LCD1602非阻塞显示程序51单片机
共21个文件
obj:2个
c:2个
lst:2个
1.该资源内容由用户上传,如若侵权请联系客服进行举报
2.虚拟产品一经售出概不退款(资源遇到问题,请及时私信上传者)
2.虚拟产品一经售出概不退款(资源遇到问题,请及时私信上传者)
版权申诉
0 下载量 103 浏览量
2023-10-16
21:54:57
上传
评论
收藏 137KB ZIP 举报
温馨提示
LCD1602非阻塞显示程序51单片机:这是一个用于51单片机的LCD1602非阻塞显示程序的资源,可以实现在LCD1602液晶屏上显示任意内容,而不影响单片机的其他功能。 LCD1602液晶屏:这是一种常用的字符型液晶显示器,可以显示16行,每行2个字符。它有16个引脚,分别用于电源、对比度调节、数据传输和控制信号。
资源推荐
资源详情
资源评论
收起资源包目录
LCD1602非阻塞显示程序51单片机.zip (21个子文件)
LCD1602非阻塞显示程序51单片机
keil
Objects
template.lnp 123B
template.build_log.htm 1KB
template 26KB
lcd1602.obj 17KB
template.hex 11KB
main.obj 9KB
template.uvgui.Administrator 176KB
Src
lcd1602.c 10KB
main.c 3KB
STARTUP.A51 6KB
Listings
template.m51 22KB
main.lst 5KB
lcd1602.lst 16KB
template.uvproj 14KB
Inc
lcd1602.h 699B
template.uvgui.yuanzhiwen 91KB
template.uvopt 5KB
proteus
proteus.PWI 1KB
Last Loaded proteus.DBK 190KB
proteus.DSN 189KB
template.hex 11KB
共 21 条
- 1
资源评论
风和技术资料库
- 粉丝: 37
- 资源: 925
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功