Advertisement
RuiViana

Q_ueiju.c

Jul 27th, 2020
2,244
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 2.02 KB | None | 0 0
  1. #include <stdio.h>
  2. #include "freertos/FreeRTOS.h"
  3. #include "freertos/portmacro.h"
  4. #include "freertos/task.h"
  5. #include "freertos/queue.h"
  6. #include "driver/periph_ctrl.h"
  7. #include "driver/gpio.h"
  8. #include "esp_attr.h"
  9. #include "sdkconfig.h"
  10. #include <string.h>
  11.  
  12. #include "hd44780.h"
  13. #include "pcf8574.h"
  14.  
  15. #define SDA_GPIO 16                                           // GPIO I2C SDA para o LCD
  16. #define SCL_GPIO 17                                           // GPIO I2C SCL para o LCD
  17. #define I2C_ADDR 0x38                                                     // Endereco I2C do PCF8574
  18. static i2c_dev_t pcf8574;                                                 // Instancia PCF8574
  19.  
  20. //----------------------------------------------------------------------------------------
  21. static esp_err_t write_lcd_data(const hd44780_t *lcd, uint8_t data)
  22. {
  23.     return pcf8574_port_write(&pcf8574, data);                              // Grava dados no PCF8574
  24. }
  25. //----------------------------------------------------------------------------------------
  26. void lcd_test()
  27. {
  28.     hd44780_t lcd = {
  29.         .write_cb = write_lcd_data, // use callback to send data to LCD by I2C GPIO expander
  30.         .font = HD44780_FONT_5X8,
  31.         .lines = 2,
  32.         .pins = {
  33.             .rs = 0,
  34.             .e  = 2,
  35.             .d4 = 4,
  36.             .d5 = 5,
  37.             .d6 = 6,
  38.             .d7 = 7,
  39.             .bl = 3
  40.         }
  41.     };
  42.  
  43.     memset(&pcf8574, 0, sizeof(i2c_dev_t));
  44.     ESP_ERROR_CHECK(pcf8574_init_desc(&pcf8574, 0, I2C_ADDR, SDA_GPIO, SCL_GPIO));
  45.  
  46.     ESP_ERROR_CHECK(hd44780_init(&lcd));
  47.  
  48.     hd44780_switch_backlight(&lcd, true);
  49.  
  50.     hd44780_gotoxy(&lcd, 0, 0);
  51.     hd44780_puts(&lcd, "\x08 Hello world!");
  52.     hd44780_gotoxy(&lcd, 0, 1);
  53.     hd44780_puts(&lcd, "\x09 ");
  54. }
  55. //----------------------------------------------------------------------------------------
  56. void app_main(void)
  57. {
  58.     ESP_ERROR_CHECK(i2cdev_init());                                         // LCD  I2C
  59.     lcd_test();
  60.  
  61.     while(1)
  62.     {
  63.         vTaskDelay(500);
  64.     }
  65. }
  66.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement