本文主要是介绍液晶模块LCD1602+PCF8574P在ESP8266 (RTOS3.2)上调试的驱动,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
液晶模块LCD1602+PCF8574P在ESP8266 (RTOS3.2)上调试的驱动
- 模块简介
- 硬件原理图
- 软件部分
- 显示效果
模块简介
直接用lcd1602的话,至少占用8个gpio口,所以用的PCF8574P模块,只需要用I2C控制即可;
硬件原理图
手边只有一个5v的LCD1602,VDDIO口也要5V,我在处理I2C5v和3v的VDDIO电平连接时,使用n-mos管,稍微稳定一些,当然也可以上专门的电平互转IC;
软件部分
- main.c
- lcd1602_pcf8574.h
- lcd1602_pcf8574.c
- my_iic.h
- my_iic.c
- main.c部分:
/* mainThis example code is in the Public Domain (or CC0 licensed, at your option.)Unless required by applicable law or agreed to in writing, thissoftware is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES ORCONDITIONS OF ANY KIND, either express or implied.
*/#include <stdio.h>
#include <string.h>
#include <stdlib.h>#include "freertos/FreeRTOS.h"
#include "freertos/task.h"
#include "freertos/queue.h"
#include "esp_log.h"
#include "esp_system.h"
#include "esp_err.h"#include "driver/i2c.h"
#include "lcd1602_pcf8574.h"void app_main(void)
{char str1[41] = "Show text..";i2c_master_init();clear();lcd_init_chip(I2C_EXAMPLE_MASTER_NUM);isBacklight(1); //open BacklightLCD_Write_String(0,0,str1);//从第一行第一个位置开始显示i2c_driver_delete(I2C_EXAMPLE_MASTER_NUM);
}
- lcd1602_pcf8574.h:
/* lcd1602+pcf8574 display modelThis example code is in the Public Domain (or CC0 licensed, at your option.)Unless required by applicable law or agreed to in writing, thissoftware is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES ORCONDITIONS OF ANY KIND, either express or implied.
*/
#include <stdio.h>
#include <string.h>
#include <stdlib.h>#include "freertos/FreeRTOS.h"
#include "freertos/task.h"
#include "esp_log.h"
#include "esp_system.h"
#include "esp_err.h"#include "my_iic.h"#include "my_iic.h"/*
pcf8574 | lcd1602p0 -> RSp1 -> RWp2 -> CSp3 -> LED-K by PNPp4 -> P4p5 -> P5p6 -> P6p7 -> P7VDD -> LED-A
*/#define Rs 0x1 // Register select bit
#define Rw 0x2 // Read/Write bit
#define En 0x4 // Enable bit// flags for backlight control
#define LCD_BACKLIGHT 0x01<<3
#define LCD_NOBACKLIGHT 0x00// flags for function set
#define LCD_8BITMODE 0x10
#define LCD_4BITMODE 0x00
#define LCD_2LINE 0x08
#define LCD_1LINE 0x00
#define LCD_5x10DOTS 0x04
#define LCD_5x8DOTS 0x00// commands
#define LCD_CLEARDISPLAY 0x01
#define LCD_RETURNHOME 0x02
#define LCD_ENTRYMODESET 0x04
#define LCD_DISPLAYCONTROL 0x08
#define LCD_CURSORSHIFT 0x10
#define LCD_FUNCTIONSET 0x20
#define LCD_SETCGRAMADDR 0x40
#define LCD_SETDDRAMADDR 0x80// flags for display on/off control
#define LCD_DISPLAYON 0x04
#define LCD_DISPLAYOFF 0x00
#define LCD_CURSORON 0x02
#define LCD_CURSOROFF
这篇关于液晶模块LCD1602+PCF8574P在ESP8266 (RTOS3.2)上调试的驱动的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!