求助代码修改,使LCD12864能显示中文
<p>我是小白,现有一块带字库的LCD12864屏,外接ESP32、DHT11,能正常显示temp、humi及其值。<br />现在想把屏上第一行字符改成汉字“四川成都”,并将“temp”、“humi”分别换成汉字“温度”、“湿度”,但不知如何修改,<br />
现附上代码求助,望高手不吝赐教,谢谢!</p>
<p>from machine import Pin<br />
import time<br />
from dht import DHT11<br />
dht11=DHT11(Pin(27)) <br />
cs = Pin(12,Pin.OUT) # LCD12864采用的是串行数据传输方式<br />
sid = Pin(18,Pin.OUT)<br />
clk = Pin(19,Pin.OUT)<br />
psb = Pin(13,Pin.OUT)<br />
def Lcd12864_Write_Byte(byte):<br />
cs.value(1)<br />
for i in range(0,8,1):<br />
sid.value(1 if(byte<<i)&0x80 else 0)<br />
clk.value(0)<br />
clk.value(1)<br />
cs.value(0)<br />
def Lcd12864_Write(cmd,data):<br />
Lcd12864_Write_Byte(cmd)<br />
Lcd12864_Write_Byte(data&0xf0)<br />
Lcd12864_Write_Byte((data<<4)&0xf0)<br />
def Lcd12864_Init():<br />
psb.value(0) <br />
Lcd12864_Write(0xf8,0x30)<br />
Lcd12864_Write(0xf8,0x06)<br />
Lcd12864_Write(0xf8,0x0c)<br />
Lcd12864_Write(0xf8,0x01)<br />
Lcd12864_Write(0xf8,0x80)<br />
def Lcd12864_Write_Text(addr,data):<br />
Lcd12864_Write(0xf8,addr) <br />
for i in range(len(data)):<br />
Lcd12864_Write(0xfa,ord(data)) <br />
def DHT11_Read_Data():<br />
time.sleep(1)<br />
dht11.measure()<br />
temp = dht11.temperature()<br />
humi = dht11.humidity()<br />
Lcd12864_Write_Text(0x88,str("humi = %d%%"%humi))<br />
Lcd12864_Write_Text(0x98,str("temp = %.1f"%temp)) <br />
time.sleep(2) <br />
def main(): <br />
Lcd12864_Init()<br />
Lcd12864_Write_Text(0x81,str("SC_CD_ZZ_XXX"))<br />
Lcd12864_Write_Text(0x90,str("----------------")) <br />
while True:<br />
DHT11_Read_Data() <br />
if __name__ == "__main__":<br />
main() </p>
<p>建议单个汉字返送,不要以为可以发送一串汉字或词组,很头疼的!</p>
<p>如果需要通用,就要一个字库,通过字库获取汉字点阵进行显示。如果只是几个汉字,可以先取模,存放到文件或数组。</p>
用汉字取模,然后发送, <p>自己弄就是取模,毕竟没有几个字 </p>
<p>带字库的,你找找显示汉字的例程,就知道怎么用了。</p>
<div class='shownolgin' data-isdigest='no'><p>就以把”temp“换成汉字“温度“为例,那又怎么修改原代码呢?烦请版主与各位高手再详细赐教,谢谢!<img height="48" src="https://bbs.eeworld.com.cn/static/editor/plugins/hkemoji/sticker/facebook/congra.gif" width="48" /></p>
</div><script>showreplylogin();</script><script type="text/javascript">(function(d,c){var a=d.createElement("script"),m=d.getElementsByTagName("script"),eewurl="//counter.eeworld.com.cn/pv/count/";a.src=eewurl+c;m.parentNode.insertBefore(a,m)})(document,523)</script>
页:
[1]