赞
踩
一、目的
这一节我们学习如何使用合宙的ESP32 C3开发板控制2寸彩色TFT显示屏模块,分辨率240*320,SPI接口,ST7789v驱动芯片。
二、环境
ESP32 C3 + Thonny + 2寸 ST7789v 显示屏模块 + 几根杜邦线 + Win10
接线方法:
三、st7789驱动、字库、字模制作
st7789py.py,font.py,vga2_bold_16x32.py和字模制作方法请从下文获取,谢谢!
- from machine import Pin,SPI,PWM
- import vga2_bold_16x32 as font
- from font import Chine
- import st7789py
-
- blk = PWM(Pin(8),duty = (600),freq = 1000)
-
- cs = Pin(7,Pin.OUT) # CS片选信号单独列出来,点亮屏幕前需要先拉低
-
- spi = SPI(1,baudrate = 60_000_000,polarity = 1,sck = Pin(2),mosi = Pin(3),miso = None)
- tft = st7789py.ST7789(spi,320,240, reset=Pin(10,Pin.OUT), dc = Pin(6,Pin.OUT),cs = None,backlight=None, rotation=0) #0-3
-
- #16*32字体函数
- def ByteOpera16x32(num,dat):
- byte= [0x01,0x02,0x04,0x8,0x10,0x20,0x40,0x80]
- if dat&byte[num]:
- return 1
- else:
- return 0
-
- def LcdShowCh_16x32(n, x_axis, y_axis):
- for i in range(4):
- for a in range(16):
- for b in range(8):
- if(ByteOpera16x32(b,Chine.chine[n*64+i*16+a])):
- tft.pixel(x_axis+a,y_axis+i*8+b,st7789py.color565(1,255,1))
- else:
- tft.pixel(x_axis+a,y_axis+i*8+b,st7789py.color565(0,0,0))
-
- def main():
- cs.off() # CS片选信号需要先拉低
- #tft.fill(0xfff0)
- tft.text(font,"Welcome China",0,10,st7789py.color565(0,0,255), st7789py.color565(255,0,0))
-
- for i in range(6):
- LcdShowCh_16x32(i,i*16,42)
-
- while True:
- pass
-
- if __name__ == "__main__":
- main()
![](https://csdnimg.cn/release/blogv2/dist/pc/img/newCodeMoreWhite.png)
五、演示效果
六、屏幕购买
某宝链接:
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。