普誠創智(成都)科技有限公司-论坛

 找回密码
 立即注册
搜索
热搜: PT32 BLDCM Motor USB
查看: 13417|回复: 0

LCD1602A驱动源码

[复制链接]

161

主题

185

帖子

1527

积分

管理员

Rank: 9Rank: 9Rank: 9

积分
1527
发表于 2017-8-1 09:57:14 | 显示全部楼层 |阅读模式
LCD1602A驱动源码,下载链接:LCD1602A驱动源码.rar

部分举例:
#include "lcd1602a.h"
//-------------------------------------
uCHAR g_DataTable[]={0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37, 0x38 , 0x39}; // 0~~9
uCHAR g_AlphabetTable[]={
0x41, 0x42, 0x43, 0x44, 0x45, 0x46,   //A B C D E F
0x47, 0x48, 0x49, 0x4A, 0x4B, 0x4C,   //G H I J K L
0x4D, 0x4E, 0x4F, 0x50, 0x51, 0x52,   //M N O P Q R
0x53, 0x54, 0x55, 0x56, 0x57, 0x58,   //S T U V W X
0x59, 0x5A,                           //Y Z
};

//---------------driver function definition-------------------------------------------
void LCD_WriteCMD(uCHAR  command)
{
GPIODir(GPIOC,0x0);  //output
M_EN_OFF;
M_RS_OFF;
M_RW_OFF;
M_DATAOUT(command);
//
M_EN_ON;
TICKWaitus(2,10);
M_EN_OFF;
TICKWaitus(8,10);
}

//-------------------------------------
uCHAR LCD_ReadCMD(void)
{
GPIODir(GPIOC,0xFFFF); //input
M_EN_OFF;
M_RS_OFF;
M_RW_ON;
//
M_EN_ON;
TICKWaitus(2,10);
M_EN_OFF;
TICKWaitus(8,10);
//
return  (uCHAR)M_DATAIN;
}

//-------------------------------------
void  LCD_WriteData(uCHAR  data)
{
GPIODir(GPIOC,0x0);  //output
M_EN_OFF;
M_RS_ON;
M_RW_OFF;
M_DATAOUT(data);
//
M_EN_ON;
TICKWaitus(2,10);
M_EN_OFF;
TICKWaitus(8,10);
}

//-------------------------------------
uCHAR LCD_ReadData(void)
{
GPIODir(GPIOC,0xFFFF); //input
M_EN_OFF;
M_RS_ON;
M_RW_ON;
//
M_EN_ON;
TICKWaitus(2,10);
M_EN_OFF;
TICKWaitus(8,10);
//
return (uCHAR)M_DATAIN;
}

//-------------------------------------
void LCD1602_DisplayOFF_Fist_Raw(void)
{uCHAR  cnt=0;
LCD_WriteCMD(CMD_SetDDRAM_Addr| 0x00);
for(cnt=0;cnt<16;cnt++)
{
  LCD_WriteData(0xFE);
}
}

//------------------------
void LCD1602_DisplayOFF_Second_Raw(void)
{uCHAR cnt=0;
LCD_WriteCMD(CMD_SetDDRAM_Addr | 0x40);
for(cnt=0;cnt<16;cnt++)
{
  LCD_WriteData(0xFE);
}
}


//-------------------------------------
void LCD1602_Init(void)
{
LCD_WriteCMD(CMD_Function_Set_2);
TICKWaitms(1,5);
LCD_WriteCMD(CMD_ClearDisplay);
TICKWaitms(1,5);
LCD_WriteCMD(CMD_ReturnHome);
TICKWaitms(1,5);
LCD_WriteCMD(CMD_EntryMode_Set_2);
TICKWaitms(1,5);
LCD_WriteCMD(CMD_DisplayOn_Ctrl_0);
TICKWaitms(1,5);
LCD_WriteCMD(CMD_CursorOrDisplay_Shift_1);;
TICKWaitms(1,5);
LCD_WriteCMD(CMD_Function_Set_2);
TICKWaitms(1,5);
//
LCD1602_DisplayOFF_Fist_Raw();
LCD1602_DisplayOFF_Second_Raw();
LCD1602_DisplayON_Erase();
}


回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

蜀ICP备16008743号-1|普诚科技公司|小黑屋|普誠創智(成都)科技有限公司-论坛  

GMT+8, 2022-5-23 03:18 , Processed in 0.155214 second(s), 23 queries .

快速回复 返回顶部 返回列表