LCD1602 --- 1602液晶屏关联功能函数

LCD1602 模块的主要功能与函数

功能相关函数

TPYBoardGpioLcd1602(rs_pin=Pin.board.Y10,
enable_pin=Pin.board.Y9,
d4_pin=Pin.board.Y5,
d5_pin=Pin.board.Y6,
d6_pin=Pin.board.Y7,
d7_pin=Pin.board.Y8,
num_lines=2, num_columns=16)

设置1602引脚与行列最大值

LCD1602.clear()

清屏函数,清除屏幕上显示的所有字符

LCD1602.move_to(x, y)

设置写入地址,x为行位置,y为列位置

LCD1602.lcd1602_write_string(self, string)

显示函数,输入参数为字符串

LCD1602与开发板接线对应引脚:

TPYBoard LCD1602
GND VSS
3V3 VDD
电位器中间 V0
Y10 RS
GND RW
Y9 E
NC D0
NC D1
NC D2
NC D3
Y5 D4
Y6 D5
Y7 D6
Y8 D7
3V3 A
GND K

程序示例:

# main.py -- put your code here!
import pyb
from pyb import Pin
from pyb import delay, udelay,millis
from tpyb_lcd1602 import TPYBoardLcd1602Api
from tpyb_gpio_lcd1602 import TPYBoardGpioLcd1602


def main():
      lcd = TPYBoardGpioLcd1602(rs_pin=Pin.board.Y10,                 #设置引脚
                                enable_pin=Pin.board.Y9,
                                d4_pin=Pin.board.Y5,
                                d5_pin=Pin.board.Y6,
                                d6_pin=Pin.board.Y7,
                                d7_pin=Pin.board.Y8,
                                num_lines=2, num_columns=16)
 lcd.lcd1602_write_string("Hi,TurnipSmart!\n This TPYBoard!")
      delay(5000)
      lcd.clear()
      lcd.lcd1602_write_string("This  lcd1602!\n Start Work!")
      delay(5000)
      lcd.clear()
      count = 0
      while True:
              lcd.move_to(0, 0)
              #%1d 宽度  返回运行当前程序的累计时间,单位是毫秒
              lcd.lcd1602_write_string("%1d" % (millis() // 1000))
              delay(1000)
              count += 1
              print(count)

#if __name__ == "__main__":
main()