st7920_12864_8080_example.c 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. #include <rthw.h>
  2. #include <rtthread.h>
  3. #include <rtdevice.h>
  4. #include <u8g2_port.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. void u8x8_SetPin_8Bit_8080(u8x8_t *u8x8, uint8_t d0, uint8_t d1, uint8_t d2, uint8_t d3, uint8_t d4, uint8_t d5, uint8_t d6, uint8_t d7, uint8_t wr, uint8_t cs, uint8_t dc, uint8_t reset)
  20. {
  21. u8x8_SetPin(u8x8, U8X8_PIN_D0, d0);
  22. u8x8_SetPin(u8x8, U8X8_PIN_D1, d1);
  23. u8x8_SetPin(u8x8, U8X8_PIN_D2, d2);
  24. u8x8_SetPin(u8x8, U8X8_PIN_D3, d3);
  25. u8x8_SetPin(u8x8, U8X8_PIN_D4, d4);
  26. u8x8_SetPin(u8x8, U8X8_PIN_D5, d5);
  27. u8x8_SetPin(u8x8, U8X8_PIN_D6, d6);
  28. u8x8_SetPin(u8x8, U8X8_PIN_D7, d7);
  29. u8x8_SetPin(u8x8, U8X8_PIN_E, wr);
  30. u8x8_SetPin(u8x8, U8X8_PIN_CS, cs);
  31. u8x8_SetPin(u8x8, U8X8_PIN_DC, dc);
  32. u8x8_SetPin(u8x8, U8X8_PIN_RESET, reset);
  33. }
  34. static void u8g2_st7920_12864_8080_example(int argc,char *argv[])
  35. {
  36. u8g2_t u8g2;
  37. // Initialization
  38. u8g2_Setup_st7920_p_128x64_f(&u8g2, U8G2_R0, u8x8_byte_8bit_8080mode, u8x8_gpio_and_delay_rtthread);
  39. u8x8_SetPin_8Bit_8080(u8g2_GetU8x8(&u8g2),
  40. ST7920_8080_PIN_D0, ST7920_8080_PIN_D1,
  41. ST7920_8080_PIN_D2, ST7920_8080_PIN_D3,
  42. ST7920_8080_PIN_D4, ST7920_8080_PIN_D5,
  43. ST7920_8080_PIN_D6, ST7920_8080_PIN_D7,
  44. ST7920_8080_PIN_EN, ST7920_8080_PIN_CS,
  45. ST7920_8080_PIN_DC, ST7920_8080_PIN_RST);
  46. u8g2_InitDisplay(&u8g2);
  47. u8g2_SetPowerSave(&u8g2, 0);
  48. // Draw Graphics
  49. /* full buffer example, setup procedure ends in _f */
  50. u8g2_ClearBuffer(&u8g2);
  51. u8g2_SetFont(&u8g2, u8g2_font_baby_tf);
  52. u8g2_DrawStr(&u8g2, 1, 18, "U8g2 on RT-Thread");
  53. u8g2_SendBuffer(&u8g2);
  54. u8g2_SetFont(&u8g2, u8g2_font_unifont_t_symbols);
  55. u8g2_DrawGlyph(&u8g2, 112, 56, 0x2603 );
  56. u8g2_SendBuffer(&u8g2);
  57. }
  58. MSH_CMD_EXPORT(u8g2_st7920_12864_8080_example, st7920 12864 LCD sample);