from machine import Pin,I2C
from utime import sleep

rs=0x01
rw=0x02
e=0x04
bl=0x08

i2c = I2C(0, scl=Pin(1), sda=Pin(0), freq=400_000)
add=i2c.scan() 
print(add)
addlcd=add[0]  # lcd address

def cmd_wrt(data):
    data1=data&0xf0
    i2c.writeto(addlcd,bytes([data1|bl]))
    sleep(0.001)
    i2c.writeto(addlcd,bytes([data1|e|bl]))
    sleep(0.001) 
    i2c.writeto(addlcd,bytes([data1|bl]))
    sleep(0.001) 

    data1=(data&0x0f)<<4
    i2c.writeto(addlcd,bytes([data1|bl]))
    sleep(0.001)
    i2c.writeto(addlcd,bytes([data1|e|bl]))
    sleep(0.001) 
    i2c.writeto(addlcd,bytes([data1|bl]))
    sleep(0.001)     

def data_wrt(data):
    data1=data&0xf0
    i2c.writeto(addlcd,bytes([data1|rs|bl]))
    sleep(0.001)
    i2c.writeto(addlcd,bytes([data1|rs|e|bl]))
    sleep(0.001) 
    i2c.writeto(addlcd,bytes([data1|rs|bl]))
    sleep(0.001) 

    data1=(data&0x0f)<<4
    i2c.writeto(addlcd,bytes([data1|rs|bl]))
    sleep(0.001)
    i2c.writeto(addlcd,bytes([data1|rs|e|bl]))
    sleep(0.001) 
    i2c.writeto(addlcd,bytes([data1|rs|bl]))
    sleep(0.001)    

def start_lcd():
    cmd_wrt(0x02)
    sleep(0.01)
    cmd_wrt(0x28)
    sleep(0.01)
    cmd_wrt(0x0c)
    sleep(0.01)
    cmd_wrt(0x01)
    sleep(0.01)
    cmd_wrt(0x80)
    sleep(0.01)

def str_wrt(ayat):
    for i in ayat:
        data_wrt(ord(i))

def zfl(s, width):
    return '{:0>{w}}'.format(s, w=width)

def zfl1(s, width):
    return '{: >{w}}'.format(s, w=width)

start_lcd()

    

BOOTSELLED1239USBRaspberryPiPico©2020RP2-8020/21P64M15.00TTT