Arduino--LCD1602(4bit)
生活随笔
收集整理的這篇文章主要介紹了
Arduino--LCD1602(4bit)
小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.
(1)簡介
如下圖所示,LCD1602是工業(yè)現(xiàn)場中比較常用的一款液晶顯示器,管腳比較多,本文介紹一種4位傳輸線的控制方法(可節(jié)省4個(gè)IO口)
可顯示字母、數(shù)字等,不能顯示漢字
(2)接線
| VSS | GND |
| VDD | VCC |
| VO | 接3k電阻接地,或10k電位器調(diào)節(jié) |
| RS | 12 |
| RW | GND |
| EN | 11 |
| D4 | 5 |
| D5 | 4 |
| D6 | 3 |
| D7 | 2 |
| A | VCC |
| K | GND |
其中,D0–D3這4個(gè)管腳懸空不使用
(3)程序
/*引腳說明* LCD VSS-----GND* LCD VDD-----VCC* LCD VO(接3k電阻然后接GND,實(shí)際阻值根據(jù)電流調(diào)節(jié))* LCD RS-----12* LCD RW-----GND* LCD En-----11* LCD D4-----5* LCD D5-----4* LCD D6-----3* LCD D7-----2* LCD A-----VCC* LCD K-----GND*/#include <LiquidCrystal.h> //液晶顯示頭文件LiquidCrystal lcd(12, 11, 5, 4, 3, 2);//initialize the library with the numbers of the interface pinsvoid setup() {lcd.begin(16, 2); // set up the LCD's number of columns and rows:lcd.print("hello, world!"); // Print a message to the LCD. }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);lcd.print(millis()/1000); // print the number of seconds since reset: }(4)補(bǔ)充——Arduino中其他LCD語法
| ps | 一些說明 | 語法位置為空意味著默認(rèn)加上函數(shù)即可 | 例如lcd.clear()、lcd.home() |
| LiquidCystal() | 構(gòu)造函數(shù),用來初始化LCD | LiquidCrystal(rs,rw,enable,d4,d5,d6,d7) | rs為連接至RS引腳,rw同理,enable為E引腳 |
| 8線連接時(shí) | LiquidCrystal(rs,rw,enable,d0,d1,d2,d3,d4,d5,d6,d7) | ||
| begin | 設(shè)置顯示寬高 | led.bdgin(cols,rows) | 因?yàn)闀r(shí)1602,所以為begin(16,2) |
| clear | 清楚所有內(nèi)容并把光標(biāo)固定在左上角 | ||
| home | 光標(biāo)復(fù)位至左上角 | ||
| 文本輸出 | lcd.write(data,BASE) | data為需要輸出的數(shù)據(jù)(char、byte、int、string。。)BASE為輸出進(jìn)制形式 | |
| setCursor | 移動(dòng)光標(biāo)位置 | lcd. serCursor(col,row) | setCursor(3,0)是將光標(biāo)固定在第一排第四列 |
| cursor | 顯示光標(biāo),在光標(biāo)所在位置劃出一條線 | ||
| noCursor | 隱藏光標(biāo) | ||
| blink | 開啟閃爍光標(biāo) | 需提前開啟顯示光標(biāo) | |
| noBlink | 關(guān)閉閃爍光標(biāo) | ||
| display | 開啟LCD顯示 | 會(huì)顯示noDisplay函數(shù)發(fā)生之前的內(nèi)容 | |
| noDisplay | 關(guān)閉LCD顯示 | ||
| autoscroll | 自動(dòng)滾屏 | ||
| noAutoscroll | 關(guān)閉自動(dòng)滾屏 | ||
| leftToRight | 從左到右輸入 | ||
| rightToLeft | 從右到左輸入 | ||
| scrollDisplayLeft | 向左滾屏,將LCD上顯示的所有內(nèi)容都向左移動(dòng)一格 | ||
| scrollDisplayRight | 向右滾屏 | ||
| createChar | 創(chuàng)建自定義字符,最多支持8個(gè)(num最多到8),每個(gè)自定義字符使用一個(gè)8B的數(shù)組進(jìn)行保存 | lcd.createChar(num.date) | num為自定義字符的編號,data為自定義字符的像素?cái)?shù)據(jù),但需要輸出時(shí)還要用到write()函數(shù) |
| setRowOffsets | 應(yīng)該是縱向滾屏,因?yàn)闆]有l(wèi)cd,查看了下源碼 | lcd.serRowOffsets(1,2,3,4) | 輸入數(shù)字為多少,向下滾屏多少行 |
總結(jié)
以上是生活随笔為你收集整理的Arduino--LCD1602(4bit)的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: Arduino--1838红外遥控
- 下一篇: Arduino--LCD1602(IIC