尧图网络 高端网站定制 · 原创设计
免费咨询热线
400-888-6620
免费获取方案
LCD12864 ,LCD屏显开发—幽冥大陆(一百46)-东方仙盟
控制代码// LiquidCrystal_I2C.cpp #include LiquidCrystal_I2C.h #include Wire.h // When the display powers up, it is configured as follows: // // 1. Display clear // 2. Function set: // DL 0; 4-bit interface data // N 0; 1-line display // F 0; 5x8 dot character font // 3. Display on/off control: // D 0; Display off // C 0; Cursor off // B 0; Blinking off // 4. Entry mode set: // I/D 1; Increment by 1 // S 0; No display shift // // Note, however, that resetting the Arduino doesnt reset the LCD, so we // cant assume that its in that state when a sketch starts (and the // LiquidCrystal constructor is called). LiquidCrystal_I2C::LiquidCrystal_I2C(uint8_t lcd_Addr,uint8_t lcd_cols,uint8_t lcd_rows) { _Addr lcd_Addr; _cols lcd_cols; _rows lcd_rows; _backlightval LCD_NOBACKLIGHT; } void LiquidCrystal_I2C::init(){ init_priv(); } void LiquidCrystal_I2C::init_priv() { Wire.begin(); _displayfunction LCD_4BITMODE | LCD_1LINE | LCD_5x8DOTS; begin(_cols, _rows); } void LiquidCrystal_I2C::begin(uint8_t cols, uint8_t lines, uint8_t dotsize) { if (lines 1) { _displayfunction | LCD_2LINE; } _numlines lines; _currline 0; // for some 1 line displays you can select a 10 pixel high font if ((dotsize ! 0) (lines 1)) { _displayfunction | LCD_5x10DOTS; } // SEE PAGE 45/46 FOR INITIALIZATION SPECIFICATION! // according to datasheet, we need at least 40ms after power rises above 2.7V // before sending commands. Arduino can turn on way befer 4.5V so well wait 50 delay(50); // Now we pull both RS and R/W low to begin commands expanderWrite(_backlightval); // reset expanderand turn backlight off (Bit 8 of expander) delay(1000); //put the LCD into 4 bit mode // this is according to the hitachi HD44780 datasheet // figure 24 pg 46 // we start in 8bit mode, try to set 4 bit mode write4bits(0x03 4); delayMicroseconds(4500); // wait min 4.1ms // second try write4bits(0x03 4); delayMicroseconds(4500); // wait min 4.1ms // third go! write4bits(0x03 4); delayMicroseconds(150); // finally, set to 4-bit interface write4bits(0x02 4); // set # lines, font size, etc. command(LCD_FUNCTIONSET | _displayfunction); // turn the display on with no cursor or blinking default _displaycontrol LCD_DISPLAYON | LCD_CURSOROFF | LCD_BLINKOFF; display(); // clear it off clear(); // Initialize to default text direction (for roman languages) _displaymode LCD_ENTRYLEFT | LCD_ENTRYSHIFTDECREMENT; // set the entry mode command(LCD_ENTRYMODESET | _displaymode); home(); } /********** high level commands, for the user! */ void LiquidCrystal_I2C::clear(){ command(LCD_CLEARDISPLAY);// clear display, set cursor position to zero delayMicroseconds(2000); // this command takes a long time! } void LiquidCrystal_I2C::home(){ command(LCD_RETURNHOME); // set cursor position to zero delayMicroseconds(2000); // this command takes a long time! } void LiquidCrystal_I2C::setCursor(uint8_t col, uint8_t row){ int row_offsets[] { 0x00, 0x40, 0x14, 0x54 }; if ( row _numlines ) { row _numlines-1; // we count rows starting w/0 } command(LCD_SETDDRAMADDR | (col row_offsets[row])); } // Turn the display on/off (quickly) void LiquidCrystal_I2C::noDisplay() { _displaycontrol ~LCD_DISPLAYON; command(LCD_DISPLAYCONTROL | _displaycontrol); } void LiquidCrystal_I2C::display() { _displaycontrol | LCD_DISPLAYON; command(LCD_DISPLAYCONTROL | _displaycontrol); } // Turns the underline cursor on/off void LiquidCrystal_I2C::noCursor() { _displaycontrol ~LCD_CURSORON; command(LCD_DISPLAYCONTROL | _displaycontrol); } void LiquidCrystal_I2C::cursor() { _displaycontrol | LCD_CURSORON; command(LCD_DISPLAYCONTROL | _displaycontrol); } // Turn on and off the blinking cursor void LiquidCrystal_I2C::noBlink() { _displaycontrol ~LCD_BLINKON; command(LCD_DISPLAYCONTROL | _displaycontrol); } void LiquidCrystal_I2C::blink() { _displaycontrol | LCD_BLINKON; command(LCD_DISPLAYCONTROL | _displaycontrol); } // These commands scroll the display without changing the RAM void LiquidCrystal_I2C::scrollDisplayLeft(void) { command(LCD_CURSORSHIFT | LCD_DISPLAYMOVE | LCD_MOVELEFT); } void LiquidCrystal_I2C::scrollDisplayRight(void) { command(LCD_CURSORSHIFT | LCD_DISPLAYMOVE | LCD_MOVERIGHT); } // This is for text that flows Left to Right void LiquidCrystal_I2C::leftToRight(void) { _displaymode | LCD_ENTRYLEFT; command(LCD_ENTRYMODESET | _displaymode); } // This is for text that flows Right to Left void LiquidCrystal_I2C::rightToLeft(void) { _displaymode ~LCD_ENTRYLEFT; command(LCD_ENTRYMODESET | _displaymode); } // This will right justify text from the cursor void LiquidCrystal_I2C::autoscroll(void) { _displaymode | LCD_ENTRYSHIFTINCREMENT; command(LCD_ENTRYMODESET | _displaymode); } // This will left justify text from the cursor void LiquidCrystal_I2C::noAutoscroll(void) { _displaymode ~LCD_ENTRYSHIFTINCREMENT; command(LCD_ENTRYMODESET | _displaymode); } // Allows us to fill the first 8 CGRAM locations // with custom characters void LiquidCrystal_I2C::createChar(uint8_t location, uint8_t charmap[]) { location 0x7; // we only have 8 locations 0-7 command(LCD_SETCGRAMADDR | (location 3)); for (int i0; i8; i) { write(charmap[i]); } } //turn the (optional) backlight off/on void LiquidCrystal_I2C::noBacklight(void) { _backlightvalLCD_NOBACKLIGHT; expanderWrite(0); } void LiquidCrystal_I2C::backlight(void) { _backlightvalLCD_BACKLIGHT; expanderWrite(0); } /*********** mid level commands, for sending data/cmds */ inline void LiquidCrystal_I2C::command(uint8_t value) { send(value, 0); } inline size_t LiquidCrystal_I2C::write(uint8_t value) { send(value, Rs); return 1; } /************ low level data pushing commands **********/ // write either command or data, with automatic 4/8-bit selection void LiquidCrystal_I2C::send(uint8_t value, uint8_t mode) { uint8_t highnibvalue0xf0; uint8_t lownib(value4)0xf0; write4bits((highnib)|mode); write4bits((lownib)|mode); } void LiquidCrystal_I2C::write4bits(uint8_t value) { expanderWrite(value); pulseEnable(value); } void LiquidCrystal_I2C::expanderWrite(uint8_t _data){ Wire.beginTransmission(_Addr); Wire.write((int)(_data) | _backlightval); Wire.endTransmission(); } void LiquidCrystal_I2C::pulseEnable(uint8_t _data){ expanderWrite(_data | En); // En high delayMicroseconds(1); // enable pulse must be 450ns expanderWrite(_data ~En); // En low delayMicroseconds(50); // commands need 37us to settle } // Compatibility API for old sketches void LiquidCrystal_I2C::load_custom_character(uint8_t char_num, uint8_t *rows){ createChar(char_num, rows); } void LiquidCrystal_I2C::setBacklight(uint8_t new_val){ if(new_val){ backlight(); // turn backlight on }else{ noBacklight(); // turn backlight off } } void LiquidCrystal_I2C::printstr(const char c[]){ //This function is not identical to the function used for real I2C displays //its here so the user sketch doesnt have to be rewritten print(c); }文件头// LiquidCrystal_I2C.h #ifndef LiquidCrystal_I2C_h #define LiquidCrystal_I2C_h #include Arduino.h #include Wire.h // commands #define LCD_CLEARDISPLAY 0x01 #define LCD_RETURNHOME 0x02 #define LCD_ENTRYMODESET 0x04 #define LCD_DISPLAYCONTROL 0x08 #define LCD_CURSORSHIFT 0x10 #define LCD_FUNCTIONSET 0x20 #define LCD_SETCGRAMADDR 0x40 #define LCD_SETDDRAMADDR 0x80 // flags for display entry mode #define LCD_ENTRYRIGHT 0x00 #define LCD_ENTRYLEFT 0x02 #define LCD_ENTRYSHIFTINCREMENT 0x01 #define LCD_ENTRYSHIFTDECREMENT 0x00 // flags for display on/off control #define LCD_DISPLAYON 0x04 #define LCD_DISPLAYOFF 0x00 #define LCD_CURSORON 0x02 #define LCD_CURSOROFF 0x00 #define LCD_BLINKON 0x01 #define LCD_BLINKOFF 0x00 // flags for display/cursor shift #define LCD_DISPLAYMOVE 0x08 #define LCD_CURSORMOVE 0x00 #define LCD_MOVERIGHT 0x04 #define LCD_MOVELEFT 0x00 // flags for function set #define LCD_8BITMODE 0x10 #define LCD_4BITMODE 0x00 #define LCD_2LINE 0x08 #define LCD_1LINE 0x00 #define LCD_5x10DOTS 0x04 #define LCD_5x8DOTS 0x00 // I2C PCF8574 pin mapping #define En B10000000 // Enable bit #define Rw B01000000 // Read/Write bit #define Rs B00100000 // Register select bit #define LCD_BACKLIGHT 0x08 #define LCD_NOBACKLIGHT 0x00 class LiquidCrystal_I2C : public Print { public: LiquidCrystal_I2C(uint8_t lcd_addr, uint8_t lcd_cols, uint8_t lcd_rows); void init(); void begin(uint8_t cols, uint8_t lines, uint8_t dotsize LCD_5x8DOTS); // 基础显示控制 void clear(); void home(); void setCursor(uint8_t col, uint8_t row); // 显示开关 void noDisplay(); void display(); // 光标控制 void noCursor(); void cursor(); void noBlink(); void blink(); // 屏幕滚动 void scrollDisplayLeft(); void scrollDisplayRight(); // 文字方向 void leftToRight(); void rightToLeft(); void autoscroll(); void noAutoscroll(); // 自定义字符 void createChar(uint8_t location, uint8_t charmap[]); // 背光控制 void backlight(); void noBacklight(); void setBacklight(uint8_t new_val); // 兼容旧版接口 void load_custom_character(uint8_t char_num, uint8_t *rows); void printstr(const char c[]); // Print基类重写支持print()输出 virtual size_t write(uint8_t); private: void init_priv(); void send(uint8_t value, uint8_t mode); void write4bits(uint8_t value); void expanderWrite(uint8_t _data); void pulseEnable(uint8_t _data); inline void command(uint8_t value); uint8_t _Addr; uint8_t _cols; uint8_t _rows; uint8_t _backlightval; uint8_t _displayfunction; uint8_t _displaycontrol; uint8_t _displaymode; uint8_t _numlines; uint8_t _currline; }; #endif适配 DFRobot I2C 接口 LCD1602/2004的 Arduino C 驱动库全部代码为 C 编写维护状态仓库已归档停止维护项目整体迁移至 GitLab 新仓库tandembyte/LCD_I2C最后更新2016-03-07修复 Arduino IDE 1.6.7 版本 write () 函数 bug共发布 4 个版本10 位贡献者参与开发平台适配通过library.json增加 ESP8266 平台支持兼容 Arduino、PlatformIO 开发环境。二、仓库文件清单与用途核心驱动源码LiquidCrystal_I2C.h类声明头文件提供 LCD 初始化、显示、光标、背光等对外 APILiquidCrystal_I2C.cpp底层 I2C 通信、LCD 指令时序实现兼容 WEH001602 型号屏幕IDE 配置文件keywords.txtArduino 编辑器语法高亮配置library.propertiesArduino 库管理器识别元数据迭代更新版本号library.jsonPlatformIO 平台配置文件文档README.md说明库用途、归档迁移提示、版本历史人人皆为创造者共创方能共成长每个人都是使用者也是创造者是数字世界的消费者更是价值的生产者与分享者。在智能时代的浪潮里单打独斗的发展模式早已落幕唯有开放连接、创意共创、利益共享才能让个体价值汇聚成生态合力让技术与创意双向奔赴实现平台与伙伴的快速成长、共赢致远。原创永久分成共赴星辰大海原创创意共创、永久收益分成是东方仙盟始终坚守的核心理念。我们坚信每一份原创智慧都值得被尊重与回馈以永久分成锚定共创初心让创意者长期享有价值红利携手万千伙伴向着科技星辰大海笃定前行拥抱硅基 生命与数字智能交融的未来共筑跨越时代的数字文明共同体。东方仙盟拥抱知识开源共筑数字新生态在全球化与数字化浪潮中东方仙盟始终秉持开放协作、知识共享的理念积极拥抱开源技术与开放标准。我们相信唯有打破技术壁垒、汇聚全球智慧才能真正推动行业的可持续发展。开源赋能中小商户通过将前端异常检测、跨系统数据互联等核心能力开源化东方仙盟为全球中小商户提供了低成本、高可靠的技术解决方案让更多商家能够平等享受数字转型的红利。共建行业标准我们积极参与国际技术社区与全球开发者、合作伙伴共同制定开放协议 与技术规范推动跨境零售、文旅、餐饮等多业态的系统互联互通构建更加公平、高效的数字生态。知识普惠共促发展通过开源社区 、技术文档与培训体系东方仙盟致力于将前沿技术转化为可落地的行业实践赋能全球合作伙伴共同培育创新人才推动数字经济 的普惠式增长阿雪技术观在科技发展浪潮中我们不妨积极投身技术共享。不满足于做受益者更要主动担当贡献者 。无论是分享代码、撰写技术博客还是参与开源项目 维护改进每一个微小举动都可能蕴含推动技术进步的巨大能量。东方仙盟是汇聚力量的天地我们携手在此探索硅基 生命为科技进步添砖加瓦。Hey folks, in this wild tech - driven world, why not dive headfirst into the whole tech - sharing scene? Dont just be the one reaping all the benefits; step up and be a contributor too. Whether youre tossing out your code snippets , hammering out some tech blogs, or getting your hands dirty with maintaining and sprucing up open - source projects, every little thing you do might just end up being a massive force that pushes tech forward. And guess what? The Eastern FairyAlliance is this awesome place where we all come together. Were gonna team up and explore the whole silicon - based life thing, and in the process, well be fueling the growth of technology
RELATED

相关推荐

macOS 部署 Hermes Agent 接入火山方舟 Coding Plan 全流程实录

macOS 部署 Hermes Agent 接入火山方舟 Coding Plan 全流程实录

从零开始配置 Hermes Agent,把每一步选择都讲清楚,不走冤枉路 目录 前言:为什么写这篇文章环境准备安装 Hermes Agent配置向导逐项解析Provider 选择:Custom endpoint 的必要性API Base URL 与 Key:火山方舟的特殊之处…

📅 2026/9/29 18:13:16
为什么现有AI方向是错的,以及为什么“无数据推理的自指AI“才是下一个万亿市场

为什么现有AI方向是错的,以及为什么“无数据推理的自指AI“才是下一个万亿市场

为什么现有AI方向是错的,以及为什么"无数据推理的自指AI"才是下一个万亿市场摘要:​ 过去七年AI产业的叙事主线是"堆数据、堆参数、堆算力"——GPT-4到GPT-5、Claude、Gemini,全在Scale这条轴上卷。这条路线不是"错…

📅 2026/9/21 14:05:21
如何快速搭建专属游戏串流服务器:Sunshine完整配置指南

如何快速搭建专属游戏串流服务器:Sunshine完整配置指南

如何快速搭建专属游戏串流服务器:Sunshine完整配置指南 【免费下载链接】Sunshine Self-hosted game stream host for Moonlight. 项目地址: https://gitcode.com/GitHub_Trending/su/Sunshine Sunshine是一款强大的自托管游戏串流服务器,专为Moo…

📅 2026/9/29 8:48:57
MORE NEWS

更多资讯

📰

本地优先开源AI角色扮演工具Utopia:从Ollama到角色卡的完整实践

如果你在找一个“不绑大厂、本地优先”的开源AI角色扮演工具,我这一个月写的 Utopia 可能正好对得上号。事情起因很简单:我一个朋友想找个能陪他聊虚拟角色的工具,但他不想注册大厂账号、不想按月付费、不想把对话记录留在云端,还…

📰

Java中的length:数组属性、String方法与集合size的底层原理

1. 一道 Java 面试题把我问懵之后,我把 length 彻底研究了一遍先说个场景。面试官随手在白板上写了两行代码,一行int[] arr new int[10]; arr.length;,一行String s "hello"; s.length();,问我有什么区别。我很快答出…

📰

Ego-Planner实战:解决无人机撞树问题的避障指南

室外飞无人机,我最怕的不是炸机,是撞树。尤其多旋翼在树林、果园或者园区绿地里穿行,树冠、细枝、电线杆,随便来一下就是螺旋桨报废、电机堵转,运气差一点整机直接摔。很多朋友第一反应是“避障没做好”,但…

📰

从零构建本地AI角色扮演工具:Ollama+FastAPI+Vue实战

上个月有个周五晚上,朋友发来一条语音,语气比白天开会时精神多了:“能不能帮我弄一个能自己在电脑上跑的AI角色扮演工具?”我第一反应是,这不是现成一堆开源项目么,去GitHub上拉一个就行。结果她把需求一条…

📰

Jetson Orin NX串口读取GNSS模块:NMEA解析与RTK定位实战

做室外机器人定位这件事,绕不开GNSS。我最近在Jetson Orin NX 16GB上接了一个联适R70M-GNSS模块,目标很明确:用串口把高精度定位数据读出来,并解析成程序能直接用的经纬度和状态信息。这套组合不是什么高深技术,但正因…

📰

ADS AEL参数化设计:磁性元件建模与自动化实现

1. 这不是“写个脚本”那么简单:为什么参数化电感与变压器设计是ADS用户真正的分水岭在ADS(Advanced Design System)里写AEL(ADS Expression Language)脚本,很多人停留在“把S参数读出来画个图”或者“循环…

TODAY

今日更新

THIS WEEK

本周精选

THIS MONTH

本月热门

读完文章,想聊聊您的网站?

告诉我们您的行业与需求,资深顾问一对一梳理方案与报价,全程免费。

📞 💬