mono_lcd_spi_SH1108.lua 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. --- 模块功能:SH1108驱动芯片LCD命令配置
  2. -- @author openLuat
  3. -- @module ui.mono_std_spi_SH1108
  4. -- @license MIT
  5. -- @copyright openLuat
  6. -- @release 2022.06.06
  7. --[[
  8. 注意:disp库目前支持I2C接口和SPI接口的屏,此文件的配置,硬件上使用的是724 LCD专用的SPI引脚
  9. 硬件连线图如下:
  10. Air模块 LCD
  11. GND -- GND
  12. V_LCD -- VCC
  13. LCD_CLK -- SCL
  14. LCD_DIO -- SDA
  15. LCD_RST -- RES
  16. LCD_RS -- DC
  17. LCD_CS -- CS
  18. ]] module(..., package.seeall)
  19. --[[
  20. 函数名:init
  21. 功能 :初始化LCD参数
  22. 参数 :无
  23. 返回值:无
  24. ]]
  25. local function init()
  26. local para = {
  27. width = 128, -- 分辨率宽度,128像素;用户根据屏的参数自行修改
  28. height = 160, -- 分辨率高度,64像素;用户根据屏的参数自行修改
  29. bpp = 1, -- 位深度,1表示单色。单色屏就设置为1,不可修改
  30. bus = disp.BUS_SPI4LINE, -- led位标准SPI接口,不可修改
  31. yoffset = 0, -- Y轴偏移
  32. hwfillcolor = 0x0, -- 填充色,黑色
  33. pinrst = pio.P0_6, -- reset,复位引脚
  34. pinrs = pio.P0_1, -- rs,命令/数据选择引脚
  35. -- 初始化命令
  36. initcmd = {0x000200AE, -- display off
  37. 0x00020081, -- Set Contrast Control
  38. 0x000200D0, 0x000200A0, -- Set Segment Re-map
  39. 0x000200A4, -- Set Entire Display OFF/ON
  40. 0x000200A6, -- Set Normal/Reverse Display
  41. 0x000200A9, -- Display Resolution Control
  42. 0x00020002, 0x000200AD, -- DC-DC Control Mode Set
  43. 0x00020080, -- set start line address
  44. 0x000200C0, -- Set Common Output Scan Direction
  45. 0x000200A0, --
  46. 0x000200D5, -- Set Display Clock Divide Ratio/Oscillator Frequency
  47. 0x00020040, 0x000200D9, -- Dis-charge/Pre-charge Period Mode Set
  48. 0x0002002F, 0x000200DB, -- Set VCOM Deselect Level
  49. 0x0002003F, 0x00020020, -- Page addressing mode
  50. 0x000200DC, -- VSEGM Deselect Level Mode Set
  51. 0x00020035, 0x00020030, -- Set Discharge VSL Level
  52. 0x000200AF -- turn on oled panel
  53. },
  54. -- 休眠命令
  55. sleepcmd = {0x000200AE},
  56. -- 唤醒命令
  57. wakecmd = {0x000200AF}
  58. }
  59. disp.init(para)
  60. disp.clear()
  61. disp.update()
  62. end
  63. disp.update = function()
  64. local pic = disp.getframe()
  65. local size = 0
  66. for i = 0, 19 do
  67. disp.write(0x000200b0)
  68. disp.write(0x00020000 + i)
  69. disp.write(0x00020000)
  70. disp.write(0x00020011)
  71. local data = pic:sub((i * 128) + 1, (i + 1) * 128)
  72. for i = 1, data:len() do
  73. disp.write(tonumber(string.toHex(data:sub(i, i)), 16) + 0x00030000)
  74. end
  75. end
  76. end
  77. -- 控制SPI引脚的电压域
  78. pmd.ldoset(15, pmd.LDO_VLCD)
  79. init()