咸鱼ZTMR实例—LCD中文取模

咸鱼ZTMR实例—LCD中文取模

之前写过咸鱼ZTMR实例—LCD中文https://xymgf.blog.csdn.net/article/details/107764538最近小伙伴告诉我取模的时候有些问题,特此整理一下


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模式

我们本次使用20px的文字来做取模
文字取模:
字模提取工具运行PCtoLCD2002.exe。CSDN下载地址
在这里插入图片描述
顶端菜单栏,点击[选项]按下方图片设置,设置完毕后点击[确定]保存设置。

1.54寸LCD取模设置如下

选择字体设置如下面红框所示
在这里插入图片描述
点击选项面板,设置如下
在这里插入图片描述
因为我们用micropython所以里面要改成python所认的格式,格式如下:
在这里插入图片描述
点击确认。
打出要生成的字,点击生成字模
在这里插入图片描述

生成字模如下,
在这里插入图片描述
复制到记事本或者其他编辑器修改一下格式(自己修改完格式和下面的对照一下哦)
在这里插入图片描述

打开在线工具:http://tool.lu/hexstr/输入取模汉字(单个字输入)

在这里插入图片描述
点击十六进制(HEX)生成16进制字符
在这里插入图片描述
复制添加0x开头就OK了
在这里插入图片描述

参照以上方法,我依次添加了“欢迎来到,慧创工场”这8个汉字的字模。存放至zh.py(名字可以定位font.py)

zh.py

import time


#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

}

示例代码
main.py

import time
import ustruct
import framebuf
import tt14
import bauhs93
from utime import sleep_us
from micropython import const
from machine import Pin
from pyb import SPI
from ztst7789class import ST7789

#---------TFT pin 定义
TFT_RST_PIN = Pin('C4')
TFT_LED_PIN = Pin('B10')
TFT_DC_PIN = Pin('C5')
TFT_CS_PIN = Pin('B11')
TFT_CLK_PIN = Pin('A5')
TFT_MISO_PIN = Pin('A6')
TFT_MOSI_PIN = Pin('A7')


bl = Pin(TFT_LED_PIN, Pin.OUT)
LCD = None


#按键默认是1,按下是0
sw2=Pin('C13',Pin.IN,Pin.PULL_UP)
sw5=Pin('B3',Pin.IN,Pin.PULL_UP)

def lcdinit():   #初始化函数
	global LCD
	bl.value(1)  #屏幕背光打开
	
	spi = SPI(1,SPI.MASTER,baudrate=7800000,polarity=0,phase=0)
	LCD = ST7789(spi, cs=Pin(TFT_CS_PIN), dc=Pin(TFT_DC_PIN), rst=TFT_RST_PIN)
	
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(color565(255,255,0),color565(0,0,0)) #前景色,背景色
	LCD.draw_zh20_str('欢迎来到',70,80,8) #str ,x坐标,y轴坐标,间距
	LCD.draw_zh20_str('慧创工场',70,120,8)

效果图

在这里插入图片描述

相关推荐
©️2020 CSDN 皮肤主题: 鲸 设计师:meimeiellie 返回首页