硬件连接:
LCD1602是常见的LCD显示屏,显示的内容16个字符×2行,即最多只能显示32个字符。我手头的1602是5V驱动的,经过大胆测试,各个IO是可以直接和Pico的3.3V IO直接相连的,网友其他的器件不要像我这样直接相连,不一定好用。
程序使用四线驱动方式。
1602的R/W直接接GND。LCD驱动电压连接10K可调电阻后接GND。其他的管脚在程序中定义就可以。
图片:
软件:
import machine
import utime
rs = machine.Pin(0,machine.Pin.OUT)
e = machine.Pin(1,machine.Pin.OUT)
d4 = machine.Pin(2,machine.Pin.OUT)
d5 = machine.Pin(3,machine.Pin.OUT)
d6 = machine.Pin(4,machine.Pin.OUT)
d7 = machine.Pin(5,machine.Pin.OUT)
def pulseE():
e.value(1)
utime.sleep_us(40)
e.value(0)
utime.sleep_us(40)
def send2LCD4(BinNum):
d4.value((BinNum & 0b00000001) >>0)
d5.value((BinNum & 0b00000010) >>1)
d6.value((BinNum & 0b00000100) >>2)
d7.value((BinNum & 0b00001000) >>3)
pulseE()
def send2LCD8(BinNum):
d4.value((BinNum & 0b00010000) >>4)
d5.value((BinNum & 0b00100000) >>5)
d6.value((BinNum & 0b01000000) >>6)
d7.value((BinNum & 0b10000000) >>7)
pulseE()
d4.value((BinNum & 0b00000001) >>0)
d5.value((BinNum & 0b00000010) >>1)
d6.value((BinNum & 0b00000100) >>2)
d7.value((BinNum & 0b00001000) >>3)
pulseE()
def setUpLCD():
rs.value(0)
send2LCD4(0b0011)#8 bit
send2LCD4(0b0011)#8 bit
send2LCD4(0b0011)#8 bit
send2LCD4(0b0010)#4 bit
send2LCD8(0b00101000)
send2LCD8(0b00001100)
send2LCD8(0b00000110)
send2LCD8(0b00000001)
utime.sleep_ms(2)
setUpLCD()
rs.value(1)
for x in 'www.EEWorld.com':
send2LCD8(ord(x))