Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include "freertos/FreeRTOS.h"
- #include "freertos/portmacro.h"
- #include "freertos/task.h"
- #include "freertos/queue.h"
- #include "driver/periph_ctrl.h"
- #include "driver/gpio.h"
- #include "esp_attr.h"
- #include "sdkconfig.h"
- #include <string.h>
- #include "hd44780.h"
- #include "pcf8574.h"
- #define SDA_GPIO 16 // GPIO I2C SDA para o LCD
- #define SCL_GPIO 17 // GPIO I2C SCL para o LCD
- #define I2C_ADDR 0x38 // Endereco I2C do PCF8574
- static i2c_dev_t pcf8574; // Instancia PCF8574
- //----------------------------------------------------------------------------------------
- static esp_err_t write_lcd_data(const hd44780_t *lcd, uint8_t data)
- {
- return pcf8574_port_write(&pcf8574, data); // Grava dados no PCF8574
- }
- //----------------------------------------------------------------------------------------
- void lcd_test()
- {
- hd44780_t lcd = {
- .write_cb = write_lcd_data, // use callback to send data to LCD by I2C GPIO expander
- .font = HD44780_FONT_5X8,
- .lines = 2,
- .pins = {
- .rs = 0,
- .e = 2,
- .d4 = 4,
- .d5 = 5,
- .d6 = 6,
- .d7 = 7,
- .bl = 3
- }
- };
- memset(&pcf8574, 0, sizeof(i2c_dev_t));
- ESP_ERROR_CHECK(pcf8574_init_desc(&pcf8574, 0, I2C_ADDR, SDA_GPIO, SCL_GPIO));
- ESP_ERROR_CHECK(hd44780_init(&lcd));
- hd44780_switch_backlight(&lcd, true);
- hd44780_gotoxy(&lcd, 0, 0);
- hd44780_puts(&lcd, "\x08 Hello world!");
- hd44780_gotoxy(&lcd, 0, 1);
- hd44780_puts(&lcd, "\x09 ");
- }
- //----------------------------------------------------------------------------------------
- void app_main(void)
- {
- ESP_ERROR_CHECK(i2cdev_init()); // LCD I2C
- lcd_test();
- while(1)
- {
- vTaskDelay(500);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement