硬件链接:
Air101-LCD外形及引脚说明
接线说明,开始使用官网demo中的Hspi接线方法,LCD接到MCU的SPI1口后实验显示正常。
Air101-LCD管脚 | Air105Hspi管脚 | 实验成功spi1口管脚 |
GND | GND | GND |
VCC | 3.3V | 3.3V |
SCL | (PC15/SPI0_SCK) | SP1_CK/PA06/GPIO6 |
SDA | (PC13/SPI0_MOSI) | SP1_MOSI/PA08/GPIO8 |
RES | (PC12) | SP1_MISO/PA09/GPIO9 |
DC | (PE8) | U3_RX/PE08 |
CS | (PC14) | SP1_CSN/PA07/GPIO7 |
BL | (PE9) | U3_TX/PE09 |
Lua脚本:大部分功能参考官网demo代码,端口时钟速率和偏移量做了修改。
--- 模块功能:LCDtest -- @module lcd -- @author -- @release -- LuaTools需要PROJECT和VERSION这两个信息 PROJECT = "lcdtest" VERSION = "1.0.0" log.info("main", PROJECT, VERSION) -- sys库是标配 _G.sys = require("sys") --[[ -- LCD接法示例, 以Air105开发板的HSPI为例 LCD管脚 Air105管脚 spi1口管教 GND GND GND VCC 3.3V 3.3V SCL (PC15/SPI0_SCK) SP1_CK/PA06/GPIO6 SDA (PC13/SPI0_MOSI) SP1_MOSI/PA08/GPIO8 RES (PC12) SP1_MISO/PA09/GPIO9 DC (PE8) U3_RX/PE08 CS (PC14) SP1_CSN/PA07/GPIO7 BL (PE9) U3_TX/PE09
提示: 1. 只使用SPI的时钟线(SCK)和数据输出线(MOSI), 其他均为GPIO脚 2. 数据输入(MISO)和片选(CS), 虽然是SPI, 但已复用为GPIO, 并非固定,是可以自由修改成其他脚 ]] --添加硬狗防止程序卡死 wdt.init(15000)--初始化watchdog设置为15s sys.timerLoopStart(wdt.feed, 10000)--10s喂一次狗 log.info("hello luatos") spi_lcd = spi.deviceSetup(1,pin.PA07,0,0,8,20*1000*1000,spi.MSB,1,1) log.info("lcd.init", lcd.init("st7735s",{port = "device",pin_dc = pin.PE8,pin_rst = pin.PA09,pin_pwr = pin.PE9,direction = 2,w = 160,h = 80,xoffset = 0,yoffset = 24},spi_lcd))
sys.taskInit(function() -- sys.wait(1000) -- API 文档 https://wiki.luatos.com/api/lcd.html log.info("lcd.drawLine", lcd.drawLine(20,20,150,20,0x001F)) log.info("lcd.drawRectangle", lcd.drawRectangle(20,40,120,70,0xF800)) log.info("lcd.drawCircle", lcd.drawCircle(50,50,20,0x0CE0)) log.info("lcd.data", lcd.data(0x31)) end)
-- 用户代码已结束--------------------------------------------- -- 结尾总是这一句 sys.run() -- sys.run()之后后面不要加任何语句!!!!! |
LCD偏移量测试显示效果:
lcd.init("st7735s",{port = "device",pin_dc = pin.PE8,pin_rst = pin.PA09,pin_pwr = pin.PE9,direction = 2,w = 160,h = 80,xoffset = 0,yoffset = 24},spi_lcd)