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