[转]最简 LCD5110 显示程序(ESP32)

ESP32、ESP8266
ESP32-S2、ESP32-S3、ESP32-C3
回复
头像
shaoziyang
帖子: 3917
注册时间: 2019年 10月 21日 13:48

[转]最简 LCD5110 显示程序(ESP32)

#1

帖子 shaoziyang »

原帖作者:不信幼儿

说明:
1.不包括电源总共与显示屏连3根线,需用资源极少(SPI设置中的miso需设置但实际不用的)。
2.不需专用的库函数,且总共33行有效代码(程序简便易懂,字库修改很方便)。
3.SPI方式。

元件:
1.ESP-WROOM-32
2.LCD5110

接线:
RST - 3.3V
CE - GND
DC - D25
DIN - D26
CLK - D27
VCC - 3.3/5V
BL - 3.3/5V

软件:
upycraft 1.0

程序:

代码: 全选

from machine import Pin,SPI
import time
DC = Pin(25, Pin.OUT)

font = bytearray(b'\x00\x00\x00\x00\x00\x00\x00\x5f\x00\x00\x00\x07\x00\x07\x00\x14\x7f\x14\x7f\x14\x24\x2a\x7f\x2a\x12\x23\x13\x08\x64\x62\x36\x49\x55\x22\x50\x00\x05\x03\x00\x00\x00\x1c\x22\x41\x00\x00\x41\x22\x1c\x00\x14\x08\x3e\x08\x14\x08\x08\x3e\x08\x08\x00\x50\x30\x00\x00\x08\x08\x08\x08\x08\x00\x60\x60\x00\x00\x20\x10\x08\x04\x02\x3e\x51\x49\x45\x3e\x00\x42\x7f\x40\x00\x42\x61\x51\x49\x46\x21\x41\x45\x4b\x31\x18\x14\x12\x7f\x10\x27\x45\x45\x45\x39\x3c\x4a\x49\x49\x30\x01\x71\x09\x05\x03\x36\x49\x49\x49\x36\x06\x49\x49\x29\x1e\x00\x36\x36\x00\x00\x00\x56\x36\x00\x00\x08\x14\x22\x41\x00\x14\x14\x14\x14\x14\x00\x41\x22\x14\x08\x02\x01\x51\x09\x06\x32\x49\x79\x41\x3e\x7e\x11\x11\x11\x7e\x7f\x49\x49\x49\x36\x3e\x41\x41\x41\x22\x7f\x41\x41\x22\x1c\x7f\x49\x49\x49\x41\x7f\x09\x09\x09\x01\x3e\x41\x49\x49\x7a\x7f\x08\x08\x08\x7f\x00\x41\x7f\x41\x00\x20\x40\x41\x3f\x01\x7f\x08\x14\x22\x41\x7f\x40\x40\x40\x40\x7f\x02\x0c\x02\x7f\x7f\x04\x08\x10\x7f\x3e\x41\x41\x41\x3e\x7f\x09\x09\x09\x06\x3e\x41\x51\x21\x5e\x7f\x09\x19\x29\x46\x46\x49\x49\x49\x31\x01\x01\x7f\x01\x01\x3f\x40\x40\x40\x3f\x1f\x20\x40\x20\x1f\x3f\x40\x38\x40\x3f\x63\x14\x08\x14\x63\x07\x08\x70\x08\x07\x61\x51\x49\x45\x43\x00\x7f\x41\x41\x00\x02\x04\x08\x10\x20\x00\x41\x41\x7f\x00\x04\x02\x01\x02\x04\x40\x40\x40\x40\x40\x00\x01\x02\x04\x00\x20\x54\x54\x54\x78\x7f\x48\x44\x44\x38\x38\x44\x44\x44\x20\x38\x44\x44\x48\x7f\x38\x54\x54\x54\x18\x08\x7e\x09\x01\x02\x0c\x52\x52\x52\x3e\x7f\x08\x04\x04\x78\x00\x44\x7d\x40\x00\x20\x40\x44\x3d\x00\x7f\x10\x28\x44\x00\x00\x41\x7f\x40\x00\x7c\x04\x18\x04\x78\x7c\x08\x04\x04\x78\x38\x44\x44\x44\x38\x7c\x14\x14\x14\x08\x08\x14\x14\x18\x7c\x7c\x08\x04\x04\x08\x48\x54\x54\x54\x20\x04\x3f\x44\x40\x20\x3c\x40\x40\x20\x7c\x1c\x20\x40\x20\x1c\x3c\x40\x30\x40\x3c\x44\x28\x10\x28\x44\x0c\x50\x50\x50\x3c\x44\x64\x54\x4c\x44\x00\x08\x36\x41\x00\x00\x00\x7f\x00\x00\x00\x41\x36\x08\x00\x10\x08\x08\x10\x08\x00\x00\x00\x00\x00')
#127 character ascii font, 5x8 size characters  #96 chars#print(len(font)) #>>>480
spi = SPI(baudrate=2000000000, polarity=0, phase=0, sck=Pin(27), mosi=Pin(26), miso=Pin(14)) #po,ph != 1,1
def LcdWrite(dc, data):
  DC.value(dc)
  spi.write(data)
  return
  
def LcdSetYX(y,x):
  val = bytearray()
  val.append (0x40 + y)
  val.append (0x80 + x)
  LcdWrite(0,val)
  return
  
def LcdPrint (message):
  for letter in message:
    text = bytearray()
    i = (ord(letter) - 32) * 5
    for b in range (0,5):
      text.append(font[i+b])
    text.append(0x00)
    LcdWrite(1, text)
  return
  
bufInit = bytearray(b'\x21\xc8\x06\x13\x20\x0c')
buf504 = bytearray(504)
while 1:
  LcdWrite(0, bufInit)
  #print('init')
  LcdWrite(1, buf504)
  time.sleep_ms(500)
  #print('clear')  
  LcdSetYX(0,0)
  LcdPrint("ABCDEFGHIJKLMN")
  #LcdPrint("OPQRSTUVWXYZab")
  #LcdPrint("cdefghijklmnop")
  #LcdPrint(qrstuvwxyz0123)
  #LcdPrint("456789~@#$%^&*")
  #LcdPrint( "()_+-=|\{}[]<>")
  time.sleep_ms(3000)
 

回复

  • 随机主题
    回复总数
    阅读次数
    最新文章