仿电子墨水屏ST7302

Posted 卓晴

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了仿电子墨水屏ST7302相关的知识,希望对你有一定的参考价值。

 

§01 ST7302电子屏


一、背景介绍

这款 ST7302 是从TB购买到的, 下面对它的特性进行测试, 为之后应用积累经验。

  
测试平台采用 ESP32模块转接板  利用它的SPI接口来测试电子屏的功能。 这个模块转接板具有硬件和软件SPI接口。 应用HSPI1, 对应测试模块上的GPIO12,13,14, 另外再给复位和数据分配IO, 这是对应的分配方案。

  

二、搭建测试电路

在面包板上搭建测试电路。 这是器件数据手册给出的管脚功能描述。

  

三、测试程序

from machine                import Pin,SPI
import time

lcd_spi = SPI(1, 1000000)
lcd_dc = Pin(15, Pin.OUT)
lcd_cs = Pin(2, Pin.OUT)
lcd_res = Pin(27, Pin.OUT)

lcd_cs.on()
lcd_dc.on()
lcd_res.on()

def LCDWriteBus(dat):
   lcd_cs.off()
   lcd_spi.write(bytes([dat]))
   lcd_cs.on()

def LCDWriteData8(dat):
   LCDWriteBus(dat)

def LCDWriteData(dat):
   datbyte = dat.to_bytes(2, 1)
   LCDWriteData8(datbyte[0])
   LCDWriteData8(datbyte[1])

def LCDWriteReg(dat):
   lcd_dc.off()
   LCDWriteBus(dat)
   lcd_dc.on()

def LCDAddressSet(x1,y1,x2,y2):
   LCDWriteReg(0x2a)
   LCDWriteData8(x1+0x19)
   LCDWriteData8(x2+0x19)
   LCDWriteReg(0x2b)
   LCDWriteData8(y1)
   LCDWriteData8(y2)
   LCDWriteReg(0x2c)

def LCDInit():
   lcd_res.off()
   time.sleep_ms(100)
   lcd_res.on()
   time.sleep_ms(400)

   LCDWriteReg(0x38)
   LCDWriteReg(0xeb)
   LCDWriteData8(0x02)
   LCDWriteReg(0xd7)

   LCDWriteData8(0x68)
   LCDWriteReg(0xd1)
   LCDWriteData8(0x01)
   LCDWriteReg(0xc0)
   LCDWriteData8(0x80)
   LCDWriteReg(0xc1)

   LCDWriteData8(0x28)
   LCDWriteData8(0x28)
   LCDWriteData8(0x28)
   LCDWriteData8(0x28)
   LCDWriteData8(0x14)
   LCDWriteData8(0x00)

   LCDWriteReg(0xc2)
   LCDWriteData8(0x00)
   LCDWriteData8(0x00)
   LCDWriteData8(0x00)
   LCDWriteData8(0x00)

   LCDWriteReg(0xcb)
   LCDWriteData8(0x14)
   LCDWriteReg(0xb4)
   LCDWriteData8(0xe5)
   LCDWriteData8(0x77)
   LCDWriteData8(0xf1)
   LCDWriteData8(0xff)
   LCDWriteData8(0xff)
   LCDWriteData8(0x4f)
   LCDWriteData8(0xf1)
   LCDWriteData8(0xff)
   LCDWriteData8(0xff)
   LCDWriteData8(0x4f)

   LCDWriteReg(0x11)
   time.sleep_ms(100)

   LCDWriteReg(0xc7)
   LCDWriteData8(0xa6)
   LCDWriteData8(0xe9)

   LCDWriteReg(0xb0)
   LCDWriteData8(0x64)
   LCDWriteReg(0x36)
   LCDWriteData8(0x00)
   LCDWriteReg(0x3a)
   LCDWriteData8(0x11)
   LCDWriteReg(0xb9)
   LCDWriteData8(0x23)
   LCDWriteReg(0xb8)
   LCDWriteData8(0x09)
   LCDWriteReg(0x2a)
   LCDWriteData8(0x05)
   LCDWriteData8(0x36)

   LCDWriteReg(0x2b)
   LCDWriteData8(0x00)
   LCDWriteData8(0xc7)
   LCDWriteReg(0xd0)
   LCDWriteData8(0x1f)

   LCDWriteReg(0x29)
   LCDWriteReg(0xb9)
   LCDWriteData8(0xe3)
   time.sleep_ms(100)

   LCDWriteReg(0xb9)
   LCDWriteData8(0x23)
   LCDWriteReg(0x72)
   LCDWriteData8(0x00)

   LCDWriteReg(0x39)
   LCDWriteReg(0x2a)
   LCDWriteReg(0x19)
   LCDWriteData8(0x23)

   LCDWriteReg(0x2b)
   LCDWriteData8(0)
   LCDWriteData8(0x7c)
   LCDWriteData8(0x2c)

   time.sleep_ms(120)

def LCDFill(xsta, ysta, xend, yend, color):
   LCDAddressSet(xsta, ysta, xend-1, yend-1)

   for _ in range(5000):
       LCDWriteData8(color)

LCDInit()
LCDFill(0,0,10,0x7c, 0xf0)

buf = bytes([0x55, 0xa0])

count = 0
while True:

   count += 1
   time.sleep_ms(100)


■ 相关文献链接:

以上是关于仿电子墨水屏ST7302的主要内容,如果未能解决你的问题,请参考以下文章

解析电子墨水屏技术(工作原理与LCD的区别)

GIBIT墨水屏电子桌牌,外观时尚,品质出众

Arduino框架下ESP32+合宙1.54“ 电子墨水屏(e-paper)驱动显示示例

颠覆传统显示方式,电子墨水屏落地场景迎爆发式增长

基于涂鸦智能开发板的墨水屏座位管理器——1.电路设计篇

Arduino框架下通过TFT_eSPI库驱动ESP32+合宙1.54“ 电子墨水屏(e-paper)显示