Micropython学习交流群 学习QQ群:786510434 提供多种固件下载和学习交流。

Micropython-扇贝物联 QQ群:31324057 扇贝物联是一个让你与智能设备沟通更方便的物联网云平台

Micropython学习交流群 学习QQ群:468985481 学习交流ESP8266、ESP32、ESP8285、wifi模块开发交流、物联网。

Micropython老哥俩的IT农场分享QQ群:929132891 为喜欢科创制作的小白们分享一些自制的计算机软硬件免费公益课程,由两位多年从事IT研发的中年大叔发起。

Micropython ESP频道

Micropython 合宙ESP32 C3 st7789 使用工具PCtoLCD2002制作字模


一、目的


        这一节我们学习如何使用合宙的ESP32 C3开发板控制1.3寸彩色TFT显示屏模块,分辨率240*240,SPI接口,ST7789驱动芯片。


二、环境


        ESP32  C3 + Thonny + 1.3寸 st7789液晶屏模块 + 几根杜邦线 + Win10


接线方法:

————————————————

532ee8b42b684b8bb92052ac6fe1cb71.png

Micropython开发ESP32开发板之合宙ESP32 C3开发板通过串口SPI控制st7789 TFT液晶屏1.3寸


取模软件PCtoLCD2002.exe,获得“元旦快乐”四个汉字的字模。使用方法大家百度下,或者看我前面文章,也有介绍。

软件下载地址:

链接: https://pan.baidu.com/s/1mHZANIGNZ1a67Plv31_eFQ 提取码: srkp


首先使用工具PCtoLCD2002制作字模,设置如下:

7c9f93827a8d4c0385cc78d0421721c1.png

0d469d3c4c404b72877efbcd3bf11d1b.png

然后将制作好的字模放到下面这个font.py文件中:


font.py


class Chine:

    chine = [

                

                0x00,0x40,0x40,0x40,0x40,0x40,0xC0,0x00,0x00,0xFC,0x00,0x00,0x00,0x00,0x00,0x00,

                0x00,0x04,0x18,0xE0,0xC0,0x3F,0x00,0xE0,0x1F,0x02,0xF2,0x02,0x02,0x1E,0x06,0x00,

                0x00,0x00,0xC0,0x38,0x07,0x78,0xC0,0x00,0x00,0xFC,0x03,0x7C,0x80,0x00,0x00,0x00,

                0x00,0x06,0x01,0x00,0x00,0x20,0x11,0x0C,0x03,0x00,0x00,0x00,0x07,0x1C,0x10,0x00,#欢0#

 

                0x00,0x00,0x18,0xE0,0x00,0x00,0xE0,0x20,0x10,0x1C,0xC0,0x80,0x80,0xC0,0x00,0x00,

                0x00,0x20,0x20,0xF9,0x00,0x00,0xFF,0x00,0x00,0x00,0xFF,0x00,0x00,0xFF,0x00,0x00,

                0x00,0x00,0x00,0xFF,0x00,0x00,0x3F,0x08,0x04,0x02,0xFF,0x10,0x10,0x3F,0x00,0x00,

                0x00,0x0E,0x03,0x00,0x03,0x04,0x08,0x18,0x18,0x18,0x1B,0x18,0x18,0x18,0x08,0x00,#迎1#

 

                0x00,0x00,0x80,0x80,0x80,0x80,0x80,0xFC,0x88,0x80,0x80,0x80,0x80,0xC0,0x00,0x00,

                0x00,0x00,0x00,0x02,0x1C,0x78,0x00,0xFF,0x00,0x80,0x60,0x1C,0x04,0x80,0x80,0x00,

                0x00,0x01,0x01,0x01,0x81,0xE1,0x1D,0xFF,0x01,0x1F,0x61,0x81,0x01,0x01,0x01,0x00,

                0x00,0x20,0x18,0x04,0x03,0x00,0x00,0x7F,0x00,0x00,0x00,0x01,0x07,0x0E,0x0C,0x00,#来2#

 

                0x00,0x10,0x10,0x10,0x90,0xF0,0x10,0x10,0x18,0x00,0x40,0x80,0x00,0xF4,0x08,0x00,

                0x00,0x00,0x70,0x2C,0x23,0xD0,0x10,0x16,0x78,0x00,0xFF,0x00,0x00,0xFF,0x00,0x00,

                0x00,0x08,0x08,0x08,0x08,0xFF,0x08,0x08,0x0C,0x00,0xFF,0x00,0x00,0xFF,0x00,0x00,

                0x00,0x10,0x18,0x18,0x08,0x07,0x04,0x02,0x02,0x00,0x00,0x10,0x30,0x7F,0x00,0x00,#到3#

 

                0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xFC,0x08,0x00,0x00,0x00,0x00,0x00,0x00,0x00,

                0x00,0x00,0xFF,0x02,0x02,0x02,0x02,0xFF,0x02,0x02,0x02,0x02,0x02,0xFF,0x00,0x00,

                0x00,0x00,0x1F,0x04,0x04,0x04,0x04,0xFF,0x04,0x04,0x04,0x04,0x04,0x1F,0x00,0x00,

                0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x7F,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,#中4#

 

                0x00,0x00,0xFC,0x08,0x88,0x88,0x88,0x88,0x88,0x88,0x88,0xC8,0x08,0xFC,0x00,0x00,

                0x00,0x00,0xFF,0x00,0x00,0x40,0x40,0xFF,0x40,0x40,0x60,0x40,0x01,0xFF,0x00,0x00,

                0x00,0x00,0xFF,0x40,0x80,0x80,0x80,0xFF,0x80,0x81,0x9E,0xE0,0x80,0xFF,0x00,0x00,

                0x00,0x00,0x3F,0x08,0x08,0x08,0x08,0x08,0x08,0x08,0x08,0x08,0x08,0x3F,0x00,0x00,#国5#

 

            ]

 

中文显示代码:


from machine import Pin,SPI,PWM

from font import Chine

import st7789py

import time

import vga2_bold_16x32 as font

 

blk = PWM(Pin(8),duty = 500,freq = 1024) #PWM设置背光灯亮度 duty = 0-1024

 

spi = SPI(1,baudrate = 80_000_000,polarity = 1,sck = Pin(2),mosi = Pin(3),miso = None)

tft = st7789py.ST7789(spi,240,240,reset = Pin(10,Pin.OUT),dc = Pin(6,Pin.OUT),cs = None,backlight = None,rotation = 0)#rotation 方向0-4方位

tft.fill(st7789py.color565(0,0,0))

 

#16*32字体显示函数 

def ByteOpera16x32(num,dat):

  byte= [0x01,0x02,0x04,0x8,0x10,0x20,0x40,0x80]

  if dat&byte[num]:

    return 1

  else:

    return 0       #n字符,x宽度,y高度,r,g,b 565编码颜色

 

def LcdShowCh_16x32(n, x_axis, y_axis,r,g,b):

  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(r,g,b)) #改变括号里数值可以改变字体颜色

        else:

          tft.pixel(x_axis+a,y_axis+i*8+b,st7789py.color565(0,0,0))

 

#主函数          

def main():

    for i in range(6):

        LcdShowCh_16x32(i,72+16*i,0,255,0,255)

    

    tft.hline(0,40,240,st7789py.color565(0,255,0))

    tft.hline(0,45,240,st7789py.color565(255,0,0))

    

    tft.text(font,"Welcome China!",0,72,st7789py.color565(0,255,255),st7789py.color565(0,0,0))

    tft.text(font,"ST7789",0,104,st7789py.color565(255,0,255),st7789py.color565(0,0,0))

    tft.text(font,"TFT - 240*240",0,136,st7789py.color565(255,255,0),st7789py.color565(0,0,0))

    

    while True:

        for i in range(10000000):   

            #1/字体选择,2/字符,3/宽度,4/高度,5/字体颜色,6/背景色

            tft.text(font,"%.8d"%i,100,208,st7789py.color565(255,255,255),st7789py.color565(0,0,0))

            time.sleep_ms(50)

 

 

if __name__ == "__main__":

    main()

显示效果:

f900729ab3bd42e7bde691c68472afc0.png


来源:https://blog.csdn.net/zhusongziye/article/details/129347036?spm=1001.2014.3001.5501


推荐分享
图文皆来源于网络,内容仅做公益性分享,版权归原作者所有,如有侵权请告知删除!
 

Copyright © 2014 ESP56.com All Rights Reserved

执行时间: 0.0075058937072754 seconds