from machine import Pin
from utime import sleep_ms
# Pines LCD
rs = Pin(12, Pin.OUT)
en = Pin(11, Pin.OUT)
d4 = Pin(10, Pin.OUT)
d5 = Pin(9, Pin.OUT)
d6 = Pin(8, Pin.OUT)
d7 = Pin(7, Pin.OUT)
# ----------------------------
def lcd_pulse():
en.value(1)
sleep_ms(1)
en.value(0)
sleep_ms(1)
def lcd_write4(b4, b5, b6, b7):
d4.value(b4)
d5.value(b5)
d6.value(b6)
d7.value(b7)
lcd_pulse()
def lcd_send(byte, mode):
rs.value(mode)
# nibble alto
lcd_write4(
(byte >> 4) & 1,
(byte >> 5) & 1,
(byte >> 6) & 1,
(byte >> 7) & 1
)
# nibble bajo
lcd_write4(
byte & 1,
(byte >> 1) & 1,
(byte >> 2) & 1,
(byte >> 3) & 1
)
def lcd_cmd(cmd):
lcd_send(cmd, 0)
sleep_ms(2)
def lcd_data(data):
lcd_send(ord(data), 1)
def lcd_print(text):
for char in text:
lcd_data(char)
# ----------------------------
# INICIALIZACION LCD
# ----------------------------
sleep_ms(50)
lcd_cmd(0x33)
lcd_cmd(0x32)
lcd_cmd(0x28) # 4 bits, 2 filas
lcd_cmd(0x0C) # display ON
lcd_cmd(0x06) # cursor incrementa
lcd_cmd(0x01) # limpiar
sleep_ms(5)
# ----------------------------
# FILA 1
# ----------------------------
lcd_cmd(0x80)
lcd_print("* GRADO NOVENO *")
# ----------------------------
# FILA 2
# ----------------------------
lcd_cmd(0xC0)
lcd_print(" CAST - TECH ")