-------------------------------------------------------------------------------------
'/I2C LCD Init 4-bit.bas/2021.02.04.
wifi.connect
memclear
cls
let address = 39 'PCF8574 I2C Address
i2c.setup(4,5) 'choose your I2C bus pins
a$ = "Temp="
hom = int(temp(0)*10)/10
b$ = str(hom)
c$ = " C"
text$ = a$ & b$ & c$ 'text$ = "Hello World"
'P7 P6 P5 P4 P3 P2 P1 P0 --- PCF8574
' | | | | | | | |
'D7 D6 D5 D4 Bl EN R/W RS --- HD44780
[Initialization]
delay 150 'step1
i2c.begin(address)
i2c.write(52) '0011 0100b=52 'step2
i2c.write(0)
delay 5
i2c.write(52) '0011 0100b=52 'step3
i2c.write(0)
delay 1
i2c.write(52) '0011 0100b=52 'step4
i2c.write(0)
delay 1
i2c.write(36) '0010 0100b=36 'step5
i2c.write(0)
delay 1
i2c.write(36) '0010 0100b=36 'step6
i2c.write(0)
i2c.write(132) '1000 0100b=132
i2c.write(0)
delay 1
i2c.write(4) '0000 0100b=4 'step7
i2c.write(0)
i2c.write(132) '1000 0100b=132
i2c.write(0)
delay 1
i2c.write(4) '0000 0100b=4 'step8
i2c.write(0)
i2c.write(20) '0001 0100b=20
i2c.write(0)
delay 5
i2c.write(4) '0000 0100b=4 'step9
i2c.write(0)
i2c.write(100) '0110 0100b=100 '0 1 I/D S
i2c.write(0) 'I/D=1-->Increment by 1
i2c.end() 'S=0-->No shift
delay 1
'Initialization ends 'step10
i2c.begin(address) 'step11
i2c.write(4) '0000 0100b=4
i2c.write(0)
i2c.write(196) '1100 0100b=196 '1 1 C B
i2c.write(0) 'C=0-->Cursor off
i2c.end() 'B=0-->Blinking off
delay 100
'Display:
print "Specified string(text$):"
print text$
print "The number of characters in the string:"
print len(text$)
print
for n = 1 to len(text$)
i2c.begin(address)
i2c.write((asc(mid(text$,n,1)) and 240) + 13)
i2c.write(0)
i2c.write((asc(mid(text$,n,1)) and 15) << 4 + 13)
i2c.write(0)
i2c.end()
next n
i2c.begin(address)
i2c.write(8) '0000 1000=Blacklight:On
i2c.end()
button "EXIT",[quit]
wait
[quit]
end