Place to put your Basic demos and examples

Moderator: Mmiscool

User avatar
By mezjoc
#90439 Thanks. This makes it easier to read.

-------------------------------------------------------------------------------------
Code: Select all'/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

:shock:
User avatar
By mezjoc
#90467 I2C LCD control using LCDPRINT instruction. This is already a complete thermometer. HD44780 is not ready to initialize yet. Question: Is the LCDSEND instruction suitable for initialization? I am waiting for the answer: mezjoc

Link:http://web.alfredstate.edu/faculty/weimandn/lcd/lcd_initialization/lcd_initialization_index.htm

Code: Select all'/LCD COMMADS_1.bas/2021.02.08
memclear
cls

'HD44780-initialization !!!

wprint "Temp(C)="
'hom = int(temp(0)*10)/10
textbox hom
wprint "<br>"
button "Exit", [quit]
timer 3000, [refresh]
wait

[refresh]
hom = int(temp(0)*10)/10
thom = hom*10
egesz$ = asc(chr(thom/10))
tized = thom - int(thom/10)*10
tized$ = asc(chr(tized))
lcdcls
lcdprint "Temp=" & egesz$ & "." & tized$ & " C",0,0
x = 0   'pos(0...16)
y = 1   'sor(0...1)
'lcdprint "<-Second  line->",x,y      'x=0...16(pos); y=0...1(sor)
wait

[quit]            
end
User avatar
By mezjoc
#90483 WEMOS D1 mini + DS18B20 + I2C-LCD (2x16)
This program works flawlessly.
Example on the display:
1.Sor -> Temp = 22.3 C
2.Sor -> Feb 10. 18:36:40

-----------------------------------------------------------------------------
Code: Select all'/LCD_TEMP.bas/2021.02.10.
'DS28B20/DAT-->D1mini/D4/GPIO2
'LCD/SDA-->D1mini/D2/GPIO4
'LCD/SCL-->D1mini/D1/GPIO5
wifi.connect
memclear
cls
delay 300
time.setup(1)      'Hungarian Time
'---initialization--------------------------
let address = 39   'PCF8574 I2C Address
i2c.setup(4,5)      'choose your I2C bus pins
lcdsend 2,0         '2=four_bits, command
'------------------------------------------------
wprint "Temp(C)="
textbox hom
wprint "<br>"
wprint "Date/Time="
textbox t_d
wprint "<br>"
button "Exit", [quit]
timer 2000, [refresh]
wait

[refresh]
'delay 100
t_d = time("month day. hour:min:sec")
delay 100
hom = int(temp(0)*10)/10
lcdcls
lcdprint "Temp=" & hom & " C",2,0
x = 0   'pos(0...16)
y = 1   'line(0...1)
lcdprint t_d,x,y   'x=0...16(pos); y=0 or 1(line)
wait

[quit]            
end