mono_lcd_spi_ssd1306.lua 2.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. --- 模块功能:SSD 1306驱动芯片LCD命令配置
  2. -- @author openLuat
  3. -- @module ui.mono_std_spi_ssd1306
  4. -- @license MIT
  5. -- @copyright openLuat
  6. -- @release 2018.03.27
  7. --[[
  8. 注意:disp库目前支持I2C接口和SPI接口的屏,此文件的配置,硬件上使用的是LCD专用的SPI引脚,不是标准的SPI引脚
  9. 硬件连线图如下:
  10. Air模块 LCD
  11. GND--地
  12. SPI_CS--片选
  13. SPI_CLK--时钟
  14. SPI_DO--数据
  15. SPI_DI--数据/命令选择
  16. VDDIO--电源
  17. UART1_CTS--复位
  18. 注意:Air202早期的开发板,UART1的CTS和RTS的丝印反了
  19. ]]
  20. module(...,package.seeall)
  21. --[[
  22. 函数名:init
  23. 功能 :初始化LCD参数
  24. 参数 :无
  25. 返回值:无
  26. ]]
  27. local function init()
  28. local para =
  29. {
  30. width = 128, --分辨率宽度,128像素;用户根据屏的参数自行修改
  31. height = 64, --分辨率高度,64像素;用户根据屏的参数自行修改
  32. bpp = 1, --位深度,1表示单色。单色屏就设置为1,不可修改
  33. bus = disp.BUS_SPI4LINE, --led位标准SPI接口,不可修改
  34. yoffset = 32, --Y轴偏移
  35. hwfillcolor = 0x0, --填充色,黑色
  36. pinrst = pio.P0_6, --reset,复位引脚
  37. pinrs = pio.P0_1, --rs,命令/数据选择引脚
  38. --初始化命令
  39. initcmd =
  40. {
  41. 0xAE, --display off
  42. 0x20, --Set Memory Addressing Mode
  43. 0x10, --00,Horizontal Addressing Mode;01,Vertical Addressing Mode;10,Page Addressing Mode (RESET);11,Invalid
  44. 0xb0, --Set Page Start Address for Page Addressing Mode,0-7
  45. 0xc8, --Set COM Output Scan Direction
  46. 0x00, --set low column address
  47. 0x10, --set high column address
  48. 0x60, --set start line address
  49. 0x81, --set contrast control register
  50. 0xdf, --
  51. 0xa1, --set segment re-map 0 to 127
  52. 0xa6, --set normal display
  53. 0xa8, --set multiplex ratio(1 to 64)
  54. 0x3f, --
  55. 0xa4, --0xa4,Output follows RAM content;0xa5,Output ignores RAM content
  56. 0xd3, --set display offset
  57. 0x20, --not offset
  58. 0xd5, --set display clock divide ratio/oscillator frequency
  59. 0xf0, --set divide ratio
  60. 0xd9, --set pre-charge period
  61. 0x22, --
  62. 0xda, --set com pins hardware configuration
  63. 0x12, --
  64. 0xdb, --set vcomh
  65. 0x20, --0x20,0.77xVcc
  66. 0x8d, --set DC-DC enable
  67. 0x14, --
  68. 0xaf, --turn on oled panel
  69. },
  70. --休眠命令
  71. sleepcmd = {
  72. 0xAE,
  73. },
  74. --唤醒命令
  75. wakecmd = {
  76. 0xAF,
  77. }
  78. }
  79. disp.init(para)
  80. disp.clear()
  81. disp.update()
  82. end
  83. --控制SPI引脚的电压域
  84. pmd.ldoset(15,pmd.LDO_VLCD)
  85. init()