查看“1602 LCD”的源代码
←
1602 LCD
跳转至:
导航
,
搜索
因为以下原因,您没有权限编辑本页:
您所请求的操作仅限于这些用户组的用户使用:
用户
,labplus
您可以查看与复制此页面的源代码。
[[文件:黑色传感器最终版12.20 画板 43.png|350px|缩略图|右]] == 概述 == 16x2液晶显示字符模块,可用于显示字母、数字、字符等。I2C LCD1602液晶模块可以显示2行,每行16个字符。对于A初学者来说,不必为繁琐复杂液晶驱动电路连线而头疼了,这款LCD扩展板将电路简化,使用相关文档中的库文件,您只需使用几行简单控制代码便能完成LCD控制显示的功能。背面的电位器还能提供你调节液晶显示器对比度的功能。 == 技术参数 == * 工作电压:VCC 3.3-5V * I2C数字信号输出 * 背光:蓝色,白色字符 * 可调节对比度 * 模块尺寸:80x36x18.6mm == 引脚定义 == {| class="wikitable" |- | <small>VCC</small> || <small>电源</small> |- | <small>SDA</small> || <small>I2C数据</small> |- | <small>SCL</small> || <small>I2C时钟</small> |- | <small>GND</small> || <small>地</small> |} == 使用教程 == === 连接示意图 === === Arduino示例 === [http://wiki.labplus.cn/images/0/01/LCD1602.rar 1602 LCD库文件下载] <pre style="color:blue"> //程序功能:显示"hello,world和时间(S)// /* LiquidCrystal Library - Hello World Demonstrates the use a 16x2 LCD display. The LiquidCrystal library works with all LCD displays that are compatible with the Hitachi HD44780 driver. There are many of them out there, and you can usually tell them by the 16-pin interface. This sketch prints "Hello World!" to the LCD and shows the time. The circuit: * LCD RS pin to digital pin 12 * LCD Enable pin to digital pin 11 * LCD D4 pin to digital pin 5 * LCD D5 pin to digital pin 4 * LCD D6 pin to digital pin 3 * LCD D7 pin to digital pin 2 * LCD R/W pin to ground * LCD VSS pin to ground * LCD VCC pin to 5V * 10K resistor: * ends to +5V and ground * wiper to LCD VO pin (pin 3) Library originally added 18 Apr 2008 by David A. Mellis library modified 5 Jul 2009 by Limor Fried (http://www.ladyada.net) example added 9 Jul 2009 by Tom Igoe modified 22 Nov 2010 by Tom Igoe This example code is in the public domain. http://www.arduino.cc/en/Tutorial/LiquidCrystal */ // include the library code: #include <LCD1602.h> #include <Wire.h> // initialize the library with the numbers of the interface pins LiquidCrystal lcd; void setup() { // set up the LCD's number of columns and rows: Wire.begin(); lcd.begin(16, 2); // Print a message to the LCD. lcd.print("hello, world!"); } void loop() { // set the cursor to column 0, line 1 // (note: line 1 is the second row, since counting begins with 0): lcd.setCursor(0, 1); // print the number of seconds since reset: lcd.print(millis() / 1000); } </pre> === MicroPython示例 === from microbit import * <pre style="color:blue"> # commands LCD_CLEARDISPLAY = 0x01 LCD_RETURNHOME = 0x02 LCD_ENTRYMODESET = 0x04 LCD_DISPLAYCONTROL = 0x08 LCD_CURSORSHIFT = 0x10 LCD_FUNCTIONSET = 0x20 LCD_SETCGRAMADDR = 0x40 LCD_SETDDRAMADDR = 0x80 # flags for display entry mode LCD_ENTRYRIGHT = 0x00 LCD_ENTRYLEFT = 0x02 LCD_ENTRYSHIFTINCREMENT = 0x01 LCD_ENTRYSHIFTDECREMENT = 0x00 #flags for display on/off control LCD_DISPLAYON = 0x04 LCD_DISPLAYOFF = 0x00 LCD_CURSORON = 0x02 LCD_CURSOROFF = 0x00 LCD_BLINKON = 0x01 LCD_BLINKOFF = 0x00 #flags for display/cursor shift LCD_DISPLAYMOVE = 0x08 LCD_CURSORMOVE = 0x00 LCD_MOVERIGHT = 0x04 LCD_MOVELEFT = 0x00 #flags for function set LCD_8BITMODE = 0x10 LCD_4BITMODE = 0x00 LCD_2LINE = 0x08 LCD_1LINE = 0x00 LCD_5x10DOTS = 0x04 LCD_5x8DOTS = 0x00 _displayfunction = LCD_8BITMODE | LCD_2LINE | LCD_5x8DOTS _row_offsets = [0, 0, 0, 0] _displaymode = LCD_ENTRYLEFT | LCD_ENTRYSHIFTDECREMENT _displaycontrol = LCD_DISPLAYON | LCD_CURSOROFF | LCD_BLINKOFF def lcdInit(): setRowOffsets(0x00, 0x40, (0x00 + 16), (0x40 + 16)) sleep(50) lcdDisplay() lcdClear() sendCommand(LCD_ENTRYMODESET | _displaymode) def lcdPrint(str): for c in str: sendCharacter(ord(c)) # 清屏 def lcdClear(): sendCommand(LCD_CLEARDISPLAY) sleep(2) # 设置光标位置 def lcdSetCursor(col, row): sendCommand(LCD_SETDDRAMADDR | (col + _row_offsets[row])) # 消隐光标 def lcdNoCursor(): global _displaycontrol _displaycontrol &= ~LCD_CURSORON sendCommand(LCD_DISPLAYCONTROL | _displaycontrol) # 显示光标 def lcdCursor(): global _displaycontrol _displaycontrol |= LCD_CURSORON sendCommand(LCD_DISPLAYCONTROL | _displaycontrol) # 光标不闪烁 def lcdNoBlink(): global _displaycontrol _displaycontrol &= ~LCD_BLINKON sendCommand(LCD_DISPLAYCONTROL | _displaycontrol) # 光标闪烁 def lcdBlink(): global _displaycontrol _displaycontrol |= LCD_BLINKON sendCommand(LCD_DISPLAYCONTROL | _displaycontrol) # 左滚动显示 def lcdScrollDisplayLeft(): sendCommand(LCD_CURSORSHIFT | LCD_DISPLAYMOVE | LCD_MOVELEFT) # 右滚动显示 def lcdScrollDisplayRight(): sendCommand(LCD_CURSORSHIFT | LCD_DISPLAYMOVE | LCD_MOVERIGHT) # 字符串流从左到右 def lcdLeftToRight(): global _displaymode _displaymode |= LCD_ENTRYLEFT sendCommand(LCD_ENTRYMODESET | _displaymode) # 字符串流从右到左 def lcdRightToLeft(): global _displaymode _displaymode &= ~LCD_ENTRYLEFT sendCommand(LCD_ENTRYMODESET | _displaymode) # 以光标位置为起点,将显示字符往左挤 def lcdAutoscroll(): global _displaymode _displaymode |= LCD_ENTRYSHIFTINCREMENT sendCommand(LCD_ENTRYMODESET | _displaymode) # 取消往左挤,恢复正常显示方式(即往右显示字符) def lcdNoAutoscroll(): global _displaymode _displaymode &= ~LCD_ENTRYSHIFTINCREMENT sendCommand(LCD_ENTRYMODESET | _displaymode) # 制作用户自定义 def lcdCreateChar(location, charmap = []): _location = location & 0x7 sendCommand(LCD_SETCGRAMADDR | (_location << 3)); for i in range(0,8): sendCharacter(charmap[i]) # 光标返回屏幕原点 def lcdHome(): sendCommand(LCD_RETURNHOME) sleep(2) # 非用户调用函数------------------------------------------------ #关显示 def lcdNoDisplay(): global _displaycontrol _displaycontrol &= ~LCD_DISPLAYON; sendCommand(LCD_DISPLAYCONTROL | _displaycontrol) #开显示 def lcdDisplay(): global _displaycontrol _displaycontrol |= LCD_DISPLAYON sendCommand(LCD_DISPLAYCONTROL | _displaycontrol) #设置行偏移 def setRowOffsets(row0, row1, row2, row3): _row_offsets[0] = row0 _row_offsets[1] = row1 _row_offsets[2] = row2 _row_offsets[3] = row3 def sendCommand(cmd): command = bytearray([0x01, cmd]) i2c.write(24,command) sleep(1) def sendCharacter(c): character = bytearray([0x02,c]) i2c.write(24, character) sleep(1) lcdInit() lcdSetCursor(0, 0) lcdPrint("hello, world") lcdSetCursor(0, 1) lcdPrint("hello, world") #lcdCursor() #lcdBlink() while True: for i in range(0,8): lcdScrollDisplayRight() sleep(500) for i in range(0,8): lcdScrollDisplayLeft() sleep(500) </pre> === 图形化示例 ===
返回至
1602 LCD
。
导航菜单
个人工具
登录
命名空间
页面
讨论
变种
视图
阅读
查看源代码
查看历史
更多
搜索
导航
首页
软件
Labplus软件
mPython软件
Mixly集成盛思版
mpython_conn
教学套件
创客初级实验箱
创客初级实验箱进阶版
创客中级实验箱
创客中级实验箱Ⅱ
人工智能交互实验箱
桌面机器人
乐动魔盒
可穿戴作品电子套件
创意触摸板套装
乐动魔块中级套装
乐动魔块高级套装
bot:bit
编程造物套装
逻辑造物套装
人工智能套装
物联网套装
高中信息技术套装
掌控板初级套装
初中信息技术材料包
开源硬件教学套装
冲锋舟
造物
Arduino
乐动魔块(旧版)
Blue:bit电子积木
MicroBit系列
掌控板系列
AI摄像头V1.0
AI摄像头V2.0
1956
掌控魔盒
乐动掌控
乐动魔块
互动作品
森林奇遇记
创客森林
创客乐园
物联网演示系统
博物馆防盗演示实验系统
梦想舞台演示实验系统
智能家居演示实验系统
智能教室演示实验系统
智能停车场演示实验系统
DIY-木板系列
嘘寒问暖
硬币存款机
吼一声试试
斜不胜正灯
时光葫芦
旋转转盘
越光宝盒
治愈系萌犬
光明使者
避障机械车
DIY-亚克力系列
情绪机器人
创意七彩灯
温湿度机器人
留言机
游龙戏灯
三色时钟
光影精灵
光影时钟
智能应用系列
LED眼镜
32x16 RGB LED点阵屏
DIY环境温湿度显示系统
DIY创客空间访客记录仪
其他
金属结构件套装
耗材存取管理柜
更多
课程资源
常见问题解答
Arduino语法参考手册
链接
Labplus官网
STEAM创客教育平台
工具
链入页面
相关更改
特殊页面
页面信息