mircopython当年搜了一个nokia屏的汉显代码,就是分了两部分
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 = {
- 0xe789a9:[
- [0x40,0x3C,0x10,0xFF,0x10,0x10,0x20,0x10,0x8F,0x78,0x08,0xF8,0x08,0xF8,0x00,0x00],
- [0x02,0x06,0x02,0xFF,0x01,0x01,0x04,0x42,0x21,0x18,0x46,0x81,0x40,0x3F,0x00,0x00]
- ],#物
- 0xe88194:[
- [0x02,0xFE,0x92,0x92,0xFE,0x02,0x00,0x10,0x11,0x16,0xF0,0x14,0x13,0x10,0x00,0x00],
- [0x10,0x1F,0x08,0x08,0xFF,0x04,0x81,0x41,0x31,0x0D,0x03,0x0D,0x31,0x41,0x81,0x00]
- ],#联
- 0xe7bd91:[
- [0x00,0xFE,0x02,0x22,0x42,0x82,0x72,0x02,0x22,0x42,0x82,0x72,0x02,0xFE,0x00,0x00],
- [0x00,0xFF,0x10,0x08,0x06,0x01,0x0E,0x10,0x08,0x06,0x01,0x4E,0x80,0x7F,0x00,0x00]
- ],#网
- }
- #key 汉字的UTF-8码
- #isBottom 确定这次是获取 某个字的 上半部分(0) 还是下半部分(1)
- def get_chinese_utf8(self, key,isBottom = 0):
- values = self.UTF8_CHINESE[key]
- return values[isBottom]
复制代码
upcd8544.py
- import chinese
- def lcd_write_chineses(str,x,y,space = 9):
- # i,j=0,0
- # lsLen = len(str)
- # while (j<lsLen)
- # self.lcd_write_chinese(str[j],x+(i*space),y)
- # i+=1
- # j+=1
- return 0
-
- def lcd_write_chinese(self,data,x,y):
- #获取 字 的UTF8码
- code = 0x00 #赋初值
- data_code = data.encode("UTF-8")
- code |= data_code[0]<<16
- code |= data_code[1]<<8
- code |= data_code[2]
- #获取 字 的UTF8码 END
- self.position(x,y)
- self.data(self.chinese.get_chinese_utf8(code,0))
- self.position(x,y+1)
- self.data(self.chinese.get_chinese_utf8(code,1))
复制代码- # main.py
- import pyb
- import upcd8544
- from machine import SPI,Pin
- def main():
- lcd_5110.lcd_write_string('MicroPython',10,1)
- lcd_5110.lcd_write_chinese("物",18,3)
- lcd_5110.lcd_write_chinese("联",34,3)
- lcd_5110.lcd_write_chinese("网",50,3)
- 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()
复制代码
|