传感器实验——LCD中文显示
字体之前弄过,就不赘述了。只看如何使用即可
LCD显示小车状态
MR开发板
1.54寸液晶屏st7789 spi
基本用法
属性 | 说明 |
---|---|
lcdinit() | 初始化 |
draw_cn(text,x,y,a) | 字号:16px…text:文字。x:x坐标。y:y坐标。a:间距 |
draw_zh20_str(text,x,y,a) | 字号:20px…text:文字。x:x坐标。y:y坐标。a:间距 |
set_color(color565(R,G,B),color565(R,G,B)) | 前景色,背景色RGB模式 |
别忘了导入zh.py
不会取模的朋友点击下面链接查看取模方法。↓
咸鱼ZTMR实例—LCD中文取模
示例程序
main.py
import time
from pyb import SPI,Pin,Timer,delay
from ztst7789class import ST7789
import tt32
from car import car
from time import sleep_us,ticks_us,sleep
#---------TFT pin 定义
RES = Pin('C4')
BLK = Pin('B10')
DC = Pin('C5')
CS = Pin('B11')
SCL = Pin('A5')
TFT_MISO_PIN = Pin('A6')
SDA = Pin('A7')
bl = Pin(BLK, Pin.OUT)
def lcdinit(): #初始化函数
global LCD
bl.value(1) #屏幕背光打开
spi = SPI(1,SPI.MASTER,baudrate=7800000,polarity=0,phase=0)
LCD = ST7789(spi, cs=Pin(CS), dc=Pin(DC), rst=RES)
def color565(r, g, b): #255 255 255
return (r & 0xf8) << 8 | (g & 0xfc) << 3 | b >> 3
lcdinit() #初始化
def color565(r, g, b): #255 255 255
return (r & 0xf8) << 8 | (g & 0xfc) << 3 | b >> 3
LCD.erase()
while True:
LCD.set_color(0xfe19,0x0) #前景色粉红,背景色黑色
LCD.draw_cn('欢迎',105,80,8)
LCD.set_color(0x4810,0x0) #前景色靛青,背景色黑色
LCD.draw_zh20_str('慧创工场',70,120,8)
zh.py
import time
#16*16
zh = {
0xe6aca2:[0x00,0x80,0x00,0x80,0xFC,0x80,0x04,0xFC,0x05,0x04,0x49,0x08,0x2A,0x40,0x14,0x40,
0x10,0x40,0x28,0xA0,0x24,0xA0,0x45,0x10,0x81,0x10,0x02,0x08,0x04,0x04,0x08,0x02],#"欢",0*/
0xe8bf8e:[0x00,0x00,0x20,0x80,0x13,0x3C,0x12,0x24,0x02,0x24,0x02,0x24,0xF2,0x24,0x12,0x24,
0x12,0x24,0x12,0xB4,0x13,0x28,0x12,0x20,0x10,0x20,0x28,0x20,0x47,0xFE,0x00,0x00],#"迎",1
}
#20*20
zh20 = {
0xe6aca2:
[0x00,0x00,0x00,0x00,0x18,0x00,0x00,0x10,0x00,0x01,0x90,0x00,0x3F,0x10,0x00,0x01,0x3F,0xE0,0x22,0x20,
0x40,0x12,0x44,0x80,0x0A,0x4C,0x00,0x0C,0x0C,0x00,0x04,0x0C,0x00,0x0A,0x0C,0x00,0x0B,0x0A,0x00,0x11,
0x12,0x00,0x21,0x11,0x00,0x20,0x21,0x00,0x40,0x40,0x80,0x00,0x80,0x60,0x03,0x00,0x00,0x00,0x00,0x00],#欢",0
0xe8bf8e:
[0x00,0x00,0x00,0x00,0x10,0x00,0x10,0x20,0x00,0x09,0xC8,0x40,0x09,0x8F,0xC0,0x01,0x8C,0x40,0x01,0x8C,
0x40,0x79,0x8C,0x40,0x09,0x8C,0x40,0x09,0x8C,0x40,0x09,0x9C,0x40,0x09,0xEC,0x40,0x09,0x8F,0xC0,0x08,
0x0C,0x00,0x18,0x0C,0x00,0x66,0x08,0x00,0x41,0xC0,0x60,0x00,0x3F,0xC0,0x00,0x00,0x00,0x00,0x00,0x00],#迎",1
0xe69da5:
[0x00,0x00,0x00,0x00,0x60,0x00,0x00,0x60,0x00,0x00,0x60,0x80,0x1F,0xFF,0xC0,0x08,0x62,0x00,0x06,0x62,
0x00,0x02,0x64,0x00,0x02,0x68,0x40,0x7F,0xFF,0xE0,0x00,0xF0,0x00,0x00,0xF0,0x00,0x01,0x68,0x00,0x03,
0x64,0x00,0x06,0x62,0x00,0x0C,0x61,0x80,0x10,0x60,0xE0,0x20,0x60,0x00,0x00,0x40,0x00,0x00,0x00,0x00],#来",2
0xe588b0:
[0x00,0x00,0x00,0x00,0x20,0x40,0x3F,0xF0,0x40,0x03,0x00,0x40,0x06,0x06,0x40,0x04,0x84,0x40,0x08,0x64,
0x40,0x3F,0xF4,0x40,0x03,0x34,0x40,0x02,0x04,0x40,0x02,0x04,0x40,0x02,0x64,0x40,0x1F,0x84,0x40,0x02,
0x04,0x40,0x02,0x04,0x40,0x02,0x60,0x40,0x1F,0x80,0x40,0x30,0x01,0xC0,0x00,0x00,0x80,0x00,0x00,0x00],#到",3
0xe685a7:
[0x00,0x00,0x00,0x03,0x04,0x00,0x02,0x84,0xC0,0x1F,0x7F,0x00,0x02,0x84,0x80,0x0F,0x7F,0x00,0x02,0xC4,
0x40,0x3F,0x3F,0x80,0x04,0x01,0x00,0x0B,0xFF,0x00,0x00,0x01,0x00,0x07,0xFF,0x00,0x00,0x01,0x00,0x07,
0xFF,0x00,0x03,0x61,0x00,0x12,0x24,0xC0,0x12,0x04,0x40,0x23,0xFE,0x00,0x00,0x00,0x00,0x00,0x00,0x00],#慧",4
0xe5889b:
[0x00,0x00,0x00,0x06,0x00,0x40,0x06,0x00,0x40,0x05,0x80,0x40,0x08,0x60,0x40,0x08,0x24,0x40,0x10,0x04,
0x40,0x30,0x84,0x40,0x5F,0x84,0x40,0x10,0x84,0x40,0x10,0x84,0x40,0x10,0x84,0x40,0x13,0x84,0x40,0x11,
0x00,0x40,0x10,0x20,0x40,0x10,0x20,0x40,0x18,0x30,0x40,0x0F,0xE1,0xC0,0x00,0x00,0x80,0x00,0x00,0x00],#创",5
0xe5b7a5:
[0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x80,0x3F,0xFF,0xC0,0x00,0x60,0x00,0x00,0x60,0x00,0x00,0x60,
0x00,0x00,0x60,0x00,0x00,0x60,0x00,0x00,0x60,0x00,0x00,0x60,0x00,0x00,0x60,0x00,0x00,0x60,0x00,0x00,
0x60,0x00,0x00,0x60,0x00,0x00,0x60,0x00,0x3F,0xFF,0xC0,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00],#工",6
0xe59cba:
[0x00,0x00,0x00,0x08,0x00,0x00,0x08,0xFF,0x00,0x08,0x06,0x00,0x08,0x0C,0x00,0x08,0x18,0x00,0x7F,0x30,
0x00,0x08,0xC0,0x00,0x08,0xFF,0xE0,0x08,0x12,0x40,0x08,0x12,0x40,0x08,0x26,0x40,0x09,0xE4,0x40,0x0E,
0x4C,0x40,0x30,0x88,0xC0,0x63,0x10,0xC0,0x00,0x20,0x80,0x00,0xC7,0x80,0x03,0x01,0x00,0x00,0x00,0x00],#场",7
}