相信未来999 发表于 2024-3-18 15:51

求助代码修改,使LCD12864能显示中文

<p>我是小白,现有一块带字库的LCD12864屏,外接ESP32、DHT11,能正常显示temp、humi及其值。<br />
现在想把屏上第一行字符改成汉字&ldquo;四川成都&rdquo;,并将&ldquo;temp&rdquo;、&ldquo;humi&rdquo;分别换成汉字&ldquo;温度&rdquo;、&ldquo;湿度&rdquo;,但不知如何修改,<br />
现附上代码求助,望高手不吝赐教,谢谢!</p>

<p>from machine import Pin<br />
import time<br />
from dht import DHT11<br />
dht11=DHT11(Pin(27)) &nbsp;<br />
cs&nbsp; = Pin(12,Pin.OUT)&nbsp; # 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 />
&nbsp;&nbsp;&nbsp; cs.value(1)<br />
&nbsp;&nbsp;&nbsp; for i in range(0,8,1):<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; sid.value(1 if(byte&lt;&lt;i)&amp;0x80 else 0)<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; clk.value(0)<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; clk.value(1)<br />
&nbsp;&nbsp;&nbsp; cs.value(0)<br />
def Lcd12864_Write(cmd,data):<br />
&nbsp;&nbsp;&nbsp; Lcd12864_Write_Byte(cmd)<br />
&nbsp;&nbsp;&nbsp; Lcd12864_Write_Byte(data&amp;0xf0)<br />
&nbsp;&nbsp;&nbsp; Lcd12864_Write_Byte((data&lt;&lt;4)&amp;0xf0)<br />
def Lcd12864_Init():<br />
&nbsp;&nbsp;&nbsp; psb.value(0) &nbsp;<br />
&nbsp;&nbsp;&nbsp; Lcd12864_Write(0xf8,0x30)<br />
&nbsp;&nbsp;&nbsp; Lcd12864_Write(0xf8,0x06)<br />
&nbsp;&nbsp;&nbsp; Lcd12864_Write(0xf8,0x0c)<br />
&nbsp;&nbsp;&nbsp; Lcd12864_Write(0xf8,0x01)<br />
&nbsp;&nbsp;&nbsp; Lcd12864_Write(0xf8,0x80)<br />
def Lcd12864_Write_Text(addr,data):<br />
&nbsp;&nbsp;&nbsp; Lcd12864_Write(0xf8,addr) &nbsp;<br />
&nbsp;&nbsp;&nbsp; for i in range(len(data)):<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Lcd12864_Write(0xfa,ord(data))&nbsp; &nbsp;<br />
def DHT11_Read_Data():<br />
&nbsp;&nbsp;&nbsp; time.sleep(1)<br />
&nbsp;&nbsp;&nbsp; dht11.measure()<br />
&nbsp;&nbsp;&nbsp; temp = dht11.temperature()<br />
&nbsp;&nbsp;&nbsp; humi = dht11.humidity()<br />
&nbsp;&nbsp;&nbsp; Lcd12864_Write_Text(0x88,str(&quot;humi = %d%%&quot;%humi))<br />
&nbsp;&nbsp;&nbsp; Lcd12864_Write_Text(0x98,str(&quot;temp = %.1f&quot;%temp))&nbsp;&nbsp; &nbsp;<br />
&nbsp;&nbsp;&nbsp; time.sleep(2)&nbsp;&nbsp; &nbsp;<br />
def main():&nbsp;&nbsp; &nbsp;<br />
&nbsp;&nbsp;&nbsp; Lcd12864_Init()<br />
&nbsp;&nbsp;&nbsp; Lcd12864_Write_Text(0x81,str(&quot;SC_CD_ZZ_XXX&quot;))<br />
&nbsp;&nbsp;&nbsp; Lcd12864_Write_Text(0x90,str(&quot;----------------&quot;))&nbsp;&nbsp; &nbsp;<br />
&nbsp;&nbsp;&nbsp; while True:<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; DHT11_Read_Data() &nbsp;<br />
if __name__ == &quot;__main__&quot;:<br />
&nbsp;&nbsp;&nbsp; main()&nbsp;&nbsp;&nbsp;</p>

Gen_X 发表于 2024-3-18 18:26

<p>建议单个汉字返送,不要以为可以发送一串汉字或词组,很头疼的!</p>

dcexpert 发表于 2024-3-18 20:30

<p>如果需要通用,就要一个字库,通过字库获取汉字点阵进行显示。如果只是几个汉字,可以先取模,存放到文件或数组。</p>

吾妻思萌 发表于 2024-3-19 07:49

用汉字取模,然后发送,

秦天qintian0303 发表于 2024-3-19 09:25

<p>自己弄就是取模,毕竟没有几个字&nbsp;&nbsp;</p>

wangerxian 发表于 2024-3-19 13:15

<p>带字库的,你找找显示汉字的例程,就知道怎么用了。</p>

相信未来999 发表于 2024-3-19 18:26

<div class='shownolgin' data-isdigest='no'><p>就以把&rdquo;temp&ldquo;换成汉字&ldquo;温度&ldquo;为例,那又怎么修改原代码呢?烦请版主与各位高手再详细赐教,谢谢!<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]
查看完整版本: 求助代码修改,使LCD12864能显示中文