本帖最后由 浴火的一片冰芯 于 2017-1-31 20:42 编辑
转载请注明:@浴火的一片冰芯
一、本次实验所需器材
1、TPYboard V102板 一块
2、DS3231模块 一块
3、NOKIA 5110 LCD 屏 一块
4、杜邦线:若干
二、Nokia 5110 LCD屏使用方法
1、什么是Nokia 5110 LCD?
Nokia 5110 LCD是NOKIA 公司生产的可用于其5110、6150,6100 等系列移动电话的液晶显示模块,国内厂家也生产有类似的兼容产品。该产品除应用于移动电话外,也可广泛应用于各类便携式设备的显示系统。与其它类型的产品相比,该模块具有以下特点:
●84x48 的点阵LCD,可以显示4 行汉字,
●采用串行接口与主处理器进行通信,接口信号线数量大幅度减少,包括电源和地在内的信号线仅有9 条。支持多种串行通信协议(如AVR 单片机的SPI、MCS51 的串口模式0等),传输速率高达4Mbps,可全速写入显示数据,无等待时间。
●可通过导电胶连接模块与印制版
●LCD 控制器/驱动器芯片已绑定到LCD 晶片上,模块的体积很小。
●采用低电压供电,正常显示时的工作电流在200μA 以下,且具有掉电模式。
2、Nokia 5110 LCD 引脚说明
Nokia 5110 LCD共有8个引脚,不同的板子可能标注的英文略有不同,具体含义如下:
3、Tpyboard V102连接5110的方法
这里使用的是SPI连接方法,如果你对什么是SPI连接还不是很清楚,你可以百度一下,这样有利于你从原理上搞明白为什么这么连接。具体针脚对应如下:(由于tpyboard v102有两个spi接口,这里我们选用x1对应接口)
4、5110 LCD字模的获取
(1)英文及数据的显示
本节提供了font.py文件,已经将英文、数字及符号的字模做好,可以直接调用。具体下载见**最后的下载地址。
(2)汉字取模
汉字取模需要用到字模提取工具,该工具在**后面的下载地址中可以下载。这里以“欢”为例具体说明使用方法如下:
第一步,打开工具:
第二步,点击新建图像,宽度与高度均为16,点击确定。如图:
第三步,在文字输入区写入要取模的汉字“欢”,按下ctrl+enter。
第四步,点左边菜单里的取模方式,点c51格式,于是得到:
0x04,0x24,0x44,0x84,0x64,0x9C,0x40,0x30,0x0F,0xC8,0x08,0x08,0x28,0x18,0x00,0x00,
0x10,0x08,0x06,0x01,0x82,0x4C,0x20,0x18,0x06,0x01,0x06,0x18,0x20,0x40,0x80,0x00,
第五步,对应填写到chinese.py文件中(该文件可从**后面的网址下载),如下:
class CN_UTF8:
"""docstring for CN_UTF8"""
#key:values
#key: 使用汉字的UTF-8码
#values: 16*16
# [0] 8*16 上半部分
# [1] 8*16 下半部分
UTF8_CHINESE = {
0xe6aca2:[
[0x04,0x24,0x44,0x84,0x64,0x9C,0x40,0x30,0x0F,0xC8,0x08,0x08,0x28,0x18,0x00,0x00],
[0x10,0x08,0x06,0x01,0x82,0x4C,0x20,0x18,0x06,0x01,0x06,0x18,0x20,0x40,0x80,0x00]
],#欢
0xe8bf8e:[
[0x40,0x40,0x42,0xCC,0x00,0x00,0xFC,0x04,0x02,0x00,0xFC,0x04,0x04,0xFC,0x00,0x00],
[0x00,0x40,0x20,0x1F,0x20,0x40,0x4F,0x44,0x42,0x40,0x7F,0x42,0x44,0x43,0x40,0x00]
],#迎
0xe4bdbf:[
[0x80,0x60,0xF8,0x07,0x04,0xE4,0x24,0x24,0x24,0xFF,0x24,0x24,0x24,0xE4,0x04,0x00],
[0x00,0x00,0xFF,0x00,0x80,0x81,0x45,0x29,0x11,0x2F,0x41,0x41,0x81,0x81,0x80,0x00]
],#使
0xe794a8:[
[0x00,0x00,0xFE,0x22,0x22,0x22,0x22,0xFE,0x22,0x22,0x22,0x22,0xFE,0x00,0x00,0x00],
[0x80,0x60,0x1F,0x02,0x02,0x02,0x02,0x7F,0x02,0x02,0x42,0x82,0x7F,0x00,0x00,0x00]
],#用
0xe78eb0:[
[0x04,0x84,0x84,0xFC,0x84,0x84,0x00,0xFE,0x02,0x02,0xF2,0x02,0x02,0xFE,0x00,0x00],
[0x20,0x60,0x20,0x1F,0x10,0x90,0x40,0x23,0x18,0x06,0x01,0x7E,0x80,0x83,0xE0,0x00]
],#现
0xe59ca8:[
[0x08,0x08,0x88,0xC8,0x38,0x0C,0x0B,0x08,0x08,0xE8,0x08,0x08,0x08,0x08,0x08,0x00],
[0x02,0x01,0x00,0xFF,0x40,0x41,0x41,0x41,0x41,0x7F,0x41,0x41,0x41,0x41,0x40,0x00]
],#在
0xe697b6:[
[0x00,0xFC,0x84,0x84,0x84,0xFC,0x00,0x10,0x10,0x10,0x10,0x10,0xFF,0x10,0x10,0x00],
[0x00,0x3F,0x10,0x10,0x10,0x3F,0x00,0x00,0x01,0x06,0x40,0x80,0x7F,0x00,0x00,0x00]
],#时
0xe997b4:[
[0x00,0xF8,0x01,0x06,0x00,0xF0,0x12,0x12,0x12,0xF2,0x02,0x02,0x02,0xFE,0x00,0x00],
[0x00,0xFF,0x00,0x00,0x00,0x1F,0x11,0x11,0x11,0x1F,0x00,0x40,0x80,0x7F,0x00,0x00]
], #间
0xe68891:[
[0x20,0x24,0x24,0x24,0xFE,0x23,0x22,0x20,0x20,0xFF,0x20,0x22,0x2C,0xA0,0x20,0x00],
[0x00,0x08,0x48,0x84,0x7F,0x02,0x41,0x40,0x20,0x13,0x0C,0x14,0x22,0x41,0xF8,0x00]
], #我
0xe8909d:[
[0x02,0x02,0xF2,0x92,0x97,0xF2,0x92,0x92,0x92,0xF2,0x97,0x92,0xF2,0x02,0x02,0x00],
[0x00,0x80,0x88,0x88,0x44,0x4A,0x53,0x22,0x22,0x12,0x0A,0x06,0x00,0x00,0x00,0x00]
], #萝
0xe58d9c:[
[0x00,0x00,0x00,0x00,0x00,0x00,0xFF,0x00,0x20,0x40,0x80,0x00,0x00,0x00,0x00,0x00],
[0x00,0x00,0x00,0x00,0x00,0x00,0xFF,0x00,0x00,0x00,0x00,0x03,0x00,0x00,0x00,0x00]
], #卜
0xe699ba:[
[0x10,0x94,0x53,0x32,0x1E,0x32,0x52,0x10,0x00,0x7E,0x42,0x42,0x42,0x7E,0x00,0x00],
[0x00,0x00,0x00,0xFF,0x49,0x49,0x49,0x49,0x49,0x49,0x49,0xFF,0x00,0x00,0x00,0x00]
], #智
0xe883bd:[
[0x08,0xCC,0x4A,0x49,0x48,0x4A,0xCC,0x18,0x00,0x7F,0x88,0x88,0x84,0x82,0xE0,0x00],
[0x00,0xFF,0x12,0x12,0x52,0x92,0x7F,0x00,0x00,0x7E,0x88,0x88,0x84,0x82,0xE0,0x00]
],#能
0xe682a8:[
[0x20,0x10,0x08,0xFC,0x23,0x10,0x88,0x67,0x04,0xF4,0x04,0x24,0x54,0x8C,0x00,0x00],
[0x40,0x30,0x00,0x77,0x80,0x81,0x88,0xB2,0x84,0x83,0x80,0xE0,0x00,0x11,0x60,0x00]
],#您
0xe5bd93:[
[0x00,0x40,0x42,0x44,0x58,0x40,0x40,0x7F,0x40,0x40,0x50,0x48,0xC6,0x00,0x00,0x00],
[0x00,0x40,0x44,0x44,0x44,0x44,0x44,0x44,0x44,0x44,0x44,0x44,0xFF,0x00,0x00,0x00]
],#当
0xE5898D:[
[0x08,0x08,0xE8,0x29,0x2E,0x28,0xE8,0x08,0x08,0xC8,0x0C,0x0B,0xE8,0x08,0x08,0x00],
[0x00,0x00,0xFF,0x09,0x49,0x89,0x7F,0x00,0x00,0x0F,0x40,0x80,0x7F,0x00,0x00,0x00]
]#前
}
#key 汉字的UTF-8码
#isBottom 确定这次是获取 某个字的 上半部分(0) 还是下半部分(1)
def get_chinese_utf8(self, key,isBottom = 0):
values = self.UTF8_CHINESE[key]
return values[isBottom]
三、显示“萝卜智能”的小实例
按照上面连接后,将tpyboard v102插入电脑usb,在TPFLASH内建立以下文件(可从**后地址下载):
#font.py
class FONT6_8:
"""docstring for FONT6_8"""
FONTTYPE6_8 = [
[0x00, 0x00, 0x00, 0x00, 0x00, 0x00] # 20
,[0x00, 0x00, 0x00, 0x5f, 0x00, 0x00] # 21 !
,[0x00, 0x00, 0x07, 0x00, 0x07, 0x00] # 22 "
,[0x00, 0x14, 0x7f, 0x14, 0x7f, 0x14] # 23 #
,[0x00, 0x24, 0x2a, 0x7f, 0x2a, 0x12] # 24 $
,[0x00, 0x23, 0x13, 0x08, 0x64, 0x62] # 25 %
,[0x00, 0x36, 0x49, 0x55, 0x22, 0x50] # 26 &
,[0x00, 0x00, 0x05, 0x03, 0x00, 0x00] # 27 '
,[0x00, 0x00, 0x1c, 0x22, 0x41, 0x00] # 28 (
,[0x00, 0x00, 0x41, 0x22, 0x1c, 0x00] # 29 )
,[0x00, 0x14, 0x08, 0x3e, 0x08, 0x14] # 2a *
,[0x00, 0x08, 0x08, 0x3e, 0x08, 0x08] # 2b +
,[0x00, 0x00, 0x50, 0x30, 0x00, 0x00] # 2c ,
,[0x00, 0x08, 0x08, 0x08, 0x08, 0x08] # 2d -
,[0x00, 0x00, 0x60, 0x60, 0x00, 0x00] # 2e .
,[0x00, 0x20, 0x10, 0x08, 0x04, 0x02] # 2f /
,[0x00, 0x3e, 0x51, 0x49, 0x45, 0x3e] # 30 0
,[0x00, 0x00, 0x42, 0x7f, 0x40, 0x00] # 31 1
,[0x00, 0x42, 0x61, 0x51, 0x49, 0x46] # 32 2
,[0x00, 0x21, 0x41, 0x45, 0x4b, 0x31] # 33 3
,[0x00, 0x18, 0x14, 0x12, 0x7f, 0x10] # 34 4
,[0x00, 0x27, 0x45, 0x45, 0x45, 0x39] # 35 5
,[0x00, 0x3c, 0x4a, 0x49, 0x49, 0x30] # 36 6
,[0x00, 0x01, 0x71, 0x09, 0x05, 0x03] # 37 7
,[0x00, 0x36, 0x49, 0x49, 0x49, 0x36] # 38 8
,[0x00, 0x06, 0x49, 0x49, 0x29, 0x1e] # 39 9
,[0x00, 0x00, 0x36, 0x36, 0x00, 0x00] # 3a :
,[0x00, 0x00, 0x56, 0x36, 0x00, 0x00] # 3b ;
,[0x00, 0x08, 0x14, 0x22, 0x41, 0x00] # 3c <
,[0x00, 0x14, 0x14, 0x14, 0x14, 0x14] # 3d =
,[0x00, 0x00, 0x41, 0x22, 0x14, 0x08] # 3e >
,[0x00, 0x02, 0x01, 0x51, 0x09, 0x06] # 3f ?
,[0x00, 0x32, 0x49, 0x79, 0x41, 0x3e] # 40 @
,[0x00, 0x7e, 0x11, 0x11, 0x11, 0x7e] # 41 A
,[0x00, 0x7f, 0x49, 0x49, 0x49, 0x36] # 42 B
,[0x00, 0x3e, 0x41, 0x41, 0x41, 0x22] # 43 C
,[0x00, 0x7f, 0x41, 0x41, 0x22, 0x1c] # 44 D
,[0x00, 0x7f, 0x49, 0x49, 0x49, 0x41] # 45 E
,[0x00, 0x7f, 0x09, 0x09, 0x09, 0x01] # 46 F
,[0x00, 0x3e, 0x41, 0x49, 0x49, 0x7a] # 47 G
,[0x00, 0x7f, 0x08, 0x08, 0x08, 0x7f] # 48 H
,[0x00, 0x00, 0x41, 0x7f, 0x41, 0x00] # 49 I
,[0x00, 0x20, 0x40, 0x41, 0x3f, 0x01] # 4a J
,[0x00, 0x7f, 0x08, 0x14, 0x22, 0x41] # 4b K
,[0x00, 0x7f, 0x40, 0x40, 0x40, 0x40] # 4c L
,[0x00, 0x7f, 0x02, 0x0c, 0x02, 0x7f] # 4d M
,[0x00, 0x7f, 0x04, 0x08, 0x10, 0x7f] # 4e N
,[0x00, 0x3e, 0x41, 0x41, 0x41, 0x3e] # 4f O
,[0x00, 0x7f, 0x09, 0x09, 0x09, 0x06] # 50 P
,[0x00, 0x3e, 0x41, 0x51, 0x21, 0x5e] # 51 Q
,[0x00, 0x7f, 0x09, 0x19, 0x29, 0x46] # 52 R
,[0x00, 0x46, 0x49, 0x49, 0x49, 0x31] # 53 S
,[0x00, 0x01, 0x01, 0x7f, 0x01, 0x01] # 54 T
,[0x00, 0x3f, 0x40, 0x40, 0x40, 0x3f] # 55 U
,[0x00, 0x1f, 0x20, 0x40, 0x20, 0x1f] # 56 V
,[0x00, 0x3f, 0x40, 0x38, 0x40, 0x3f] # 57 W
,[0x00, 0x63, 0x14, 0x08, 0x14, 0x63] # 58 X
,[0x00, 0x07, 0x08, 0x70, 0x08, 0x07] # 59 Y
,[0x00, 0x61, 0x51, 0x49, 0x45, 0x43] # 5a Z
,[0x00, 0x00, 0x7f, 0x41, 0x41, 0x00] # 5b [
,[0x00, 0x02, 0x04, 0x08, 0x10, 0x20] # 5c \
,[0x00, 0x00, 0x41, 0x41, 0x7f, 0x00] # 5d ]
,[0x00, 0x04, 0x02, 0x01, 0x02, 0x04] # 5e ^
,[0x00, 0x40, 0x40, 0x40, 0x40, 0x40] # 5f _
,[0x00, 0x00, 0x01, 0x02, 0x04, 0x00] # 60 `
,[0x00, 0x20, 0x54, 0x54, 0x54, 0x78] # 61 a
,[0x00, 0x7f, 0x48, 0x44, 0x44, 0x38] # 62 b
,[0x00, 0x38, 0x44, 0x44, 0x44, 0x20] # 63 c
,[0x00, 0x38, 0x44, 0x44, 0x48, 0x7f] # 64 d
,[0x00, 0x38, 0x54, 0x54, 0x54, 0x18] # 65 e
,[0x00, 0x08, 0x7e, 0x09, 0x01, 0x02] # 66 f
,[0x00, 0x0c, 0x52, 0x52, 0x52, 0x3e] # 67 g
,[0x00, 0x7f, 0x08, 0x04, 0x04, 0x78] # 68 h
,[0x00, 0x00, 0x44, 0x7d, 0x40, 0x00] # 69 i
,[0x00, 0x20, 0x40, 0x44, 0x3d, 0x00] # 6a j
,[0x00, 0x7f, 0x10, 0x28, 0x44, 0x00] # 6b k
,[0x00, 0x00, 0x41, 0x7f, 0x40, 0x00] # 6c l
,[0x00, 0x7c, 0x04, 0x18, 0x04, 0x78] # 6d m
,[0x00, 0x7c, 0x08, 0x04, 0x04, 0x78] # 6e n
,[0x00, 0x38, 0x44, 0x44, 0x44, 0x38] # 6f o
,[0x00, 0x7c, 0x14, 0x14, 0x14, 0x08] # 70 p
,[0x00, 0x08, 0x14, 0x14, 0x18, 0x7c] # 71 q
,[0x00, 0x7c, 0x08, 0x04, 0x04, 0x08] # 72 r
,[0x00, 0x48, 0x54, 0x54, 0x54, 0x20] # 73 s
,[0x00, 0x04, 0x3f, 0x44, 0x40, 0x20] # 74 t
,[0x00, 0x3c, 0x40, 0x40, 0x20, 0x7c] # 75 u
,[0x00, 0x1c, 0x20, 0x40, 0x20, 0x1c] # 76 v
,[0x00, 0x3c, 0x40, 0x30, 0x40, 0x3c] # 77 w
,[0x00, 0x44, 0x28, 0x10, 0x28, 0x44] # 78 x
,[0x00, 0x0c, 0x50, 0x50, 0x50, 0x3c] # 79 y
,[0x00, 0x44, 0x64, 0x54, 0x4c, 0x44] # 7a z
,[0x00, 0x00, 0x08, 0x36, 0x41, 0x00] # 7b [
,[0x00, 0x00, 0x00, 0x7f, 0x00, 0x00] # 7c |
,[0x00, 0x00, 0x41, 0x36, 0x08, 0x00] # 7d ]
,[0x00, 0x10, 0x08, 0x08, 0x10, 0x08] # 7e ~
,[0x00, 0x78, 0x46, 0x41, 0x46, 0x78] # 7f (delete)
]
def get_font6_8(self, data):
return self.FONTTYPE6_8[bytearray(data)[0] - 0x20]
#upcd8544.py
//转载请注明:@浴火的一片冰芯
>>发帖长度限制,详见**末附件
#boot.py
//转载请注明:@浴火的一片冰芯
>>发帖长度限制,详见详见**末附件
#main.py
# main.py -- put your code here!
import pyb
import upcd8544
from machine import SPI,Pin
def main():
lcd_5110.lcd_write_chinese('萝',14,0)
lcd_5110.lcd_write_chinese('卜',30,0)
lcd_5110.lcd_write_chinese('智',46,0)
lcd_5110.lcd_write_chinese('能',62,0)
pyb.delay(1000)
if __name__ == '__main__':
SPI = pyb.SPI(1) #DIN=>X8-MOSI/CLK=>X6-SCK
RST = pyb.Pin('X1')
CE = pyb.Pin('X2')
DC = pyb.Pin('X3')
LIGHT = pyb.Pin('X4')
lcd_5110 = upcd8544.PCD8544(SPI, RST, CE, DC, LIGHT)
while(1):
main()
实现效果如图:
TPYBoardV102控制5110显示屏.rar
(6.96 KB)
|