资源简介
STM32F3的 LCD1602的驱动代码,用c语言,下载后修改成自己的I2C接口号就能用。
代码片段和文件信息
/** to control the LCD1602 **/
#include “i2c-lcd.h“
extern I2C_HandleTypeDef hi2c1; // choose the i2c1
#define SLAVE_ADDRESS_LCD 0x4E // change this according to a0 a1 a2 from PCF8574
void lcd_send_cmd (char cmd)
{
char data_u data_l;
uint8_t data_t[4];
data_u = (cmd&0xf0);
data_l = ((cmd<<4)&0xf0);
data_t[0] = data_u|0x0C; //en=1 rs=0
data_t[1] = data_u|0x08; //en=0 rs=0
data_t[2] = data_l|0x0C; //en=1 rs=0
data_t[3] = data_l|0x08; //en=0 rs=0
HAL_I2C_Master_Transmit (&hi2c1 SLAVE_ADDRESS_LCD(uint8_t *) data_t 4 100);
}
void lcd_send_data (char data)
{
char data_u data_l;
uint8_t data_t[4];
data_u = (data&0xf0);
data_l = ((data<<4)&0xf0);
data_t[0] = data_u|0x0D; //en=1 rs=0
data_t[1] = data_u|0x09; //en=0 rs=0
data_t[2] = data_l|0x0D; //en=1 rs=0
data_t[3] = data_l|0x09; //en=0 rs=0
HAL_I2C_Master_Transmit (&hi2c1 SLAVE_ADDRESS_LCD(uint8_t *) data_t 4 100);
}
void lcd_init (void)
{
uint8_t i=0;
HAL_Delay(100);
for(i=0;i<3;i++)//sending 3 times: select 4-bit mode
{
lcd_send_cmd(0x03);
HAL_Delay(45);
}
lcd_send_cmd (0x02);
HAL_Delay(100);
lcd_send_cmd (0x28);
HAL_Delay(1);
lcd_send_cmd (0x0c);
HAL_Delay(1);
lcd_send_cmd (0x80);
HAL_Delay(1);
}
void lcd_send_string (char *str)
{
while (*str) lcd_send_data (*str++);
}
/************************ chen ziang *****END OF FILE****/
属性 大小 日期 时间 名称
----------- --------- ---------- ----- ----
文件 258 2018-08-04 17:12 i2c-lcd.h
文件 1409 2018-08-04 17:48 i2c-lcd.c
- 上一篇:图的深度遍历和广度遍历
- 下一篇:MFC Afxcmn.h
相关资源
-
Jli
nk 命令行自动程序 - stm32f103的TCS34725驱动分享
- 昆仑通态屏做主机与STM32单片机从机之
- MAX30102心率血氧显程-STM32F103C8T6-C语言
- STM32的TM1650程序.zip
- HAL基础实验源码09 stm32cubemx-F429IGT6扩展
- 51单片机与液晶显示LCD1602接口、C语言
- RA8875 STM32F407 C++驱动
- STM32驱动TMP75 C语言程序
- STM32开发板实验指导1
- I0操作_LED流水灯xws
- stm32f303休眠
- STM32游戏手柄实验
- 非阻塞式AT指令发送接收工程,可驱动
- STM32F103输出相位可变方波
- 超声波测距(LCD1602显示)
- 485实验(RS485总线的使用,基于阿波罗
- CS5532 的 STM32 驱动程序
- C876模板(基于战舰STM32F103开发板)
- STM32 GPIO输入输出
- 基于stm32f103的AD7091源码
- STM32F0硬件IIC
- stm32 低电平捕获
- stm32控制W5500收发
- STM32F103 串口环形队列应用程序
- 基于STM32F407的AD7616代码
- stm32遥控
- stm32 can bootloader
- ALIENTEK MiniSTM32开发板入门资料
- AD7276驱动程序 STM32
评论
共有 条评论