st7920_12864_8080_example.cpp 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. #include <rthw.h>
  2. #include <rtthread.h>
  3. #include <rtdevice.h>
  4. #include <U8g2lib.h>
  5. // You may reference Drivers/drv_gpio.c for pinout
  6. // In u8x8.h #define U8X8_USE_PINS
  7. #define ST7920_8080_PIN_D0 31 // PB15
  8. #define ST7920_8080_PIN_D1 30 // PB14
  9. #define ST7920_8080_PIN_D2 29 // PB13
  10. #define ST7920_8080_PIN_D3 28 // PB12
  11. #define ST7920_8080_PIN_D4 38 // PC6
  12. #define ST7920_8080_PIN_D5 39 // PC7
  13. #define ST7920_8080_PIN_D6 40 // PC8
  14. #define ST7920_8080_PIN_D7 41 // PC9
  15. #define ST7920_8080_PIN_EN 15 // PA15
  16. #define ST7920_8080_PIN_CS U8X8_PIN_NONE
  17. #define ST7920_8080_PIN_DC 11 // PA11
  18. #define ST7920_8080_PIN_RST 12 // PA12
  19. // Check https://github.com/olikraus/u8g2/wiki/u8g2setupcpp for all supported devices
  20. static U8G2_ST7920_128X64_F_8080 u8g2(U8G2_R0,
  21. ST7920_8080_PIN_D0,
  22. ST7920_8080_PIN_D1,
  23. ST7920_8080_PIN_D2,
  24. ST7920_8080_PIN_D3,
  25. ST7920_8080_PIN_D4,
  26. ST7920_8080_PIN_D5,
  27. ST7920_8080_PIN_D6,
  28. ST7920_8080_PIN_D7,
  29. /*enable=*/ ST7920_8080_PIN_EN,
  30. /*cs=*/ ST7920_8080_PIN_CS,
  31. /*dc=*/ ST7920_8080_PIN_DC,
  32. /*reset=*/ ST7920_8080_PIN_RST);
  33. static void u8g2_st7920_12864_8080_example(int argc,char *argv[])
  34. {
  35. u8g2.begin();
  36. u8g2.clearBuffer(); // clear the internal memory
  37. u8g2.setFont(u8g2_font_6x13_tr); // choose a suitable font
  38. u8g2.drawStr(1, 18, "U8g2 on RT-Thread"); // write something to the internal memory
  39. u8g2.sendBuffer(); // transfer internal memory to the display
  40. u8g2.setFont(u8g2_font_unifont_t_symbols);
  41. u8g2.drawGlyph(112, 56, 0x2603 );
  42. u8g2.sendBuffer();
  43. }
  44. MSH_CMD_EXPORT(u8g2_st7920_12864_8080_example, st7920 12864 LCD sample);