Raspberry Pi Developer's Guide: LCD Display



{3V3} 整合型{4/8BIT,IIC,4SPI}1602英文字型藍底白字LCD螢幕(附排針)-適用於樹莓派,微控制器

此賣場所販售的 整合型 { 4BIT, 8BIT, IIC, 4SPI } 1602 英文字型 LCD 螢幕是 3V3 系統電源版本,不須外掛任何晶片,就可以使用四種通訊模式的 1602 LCD 螢幕,出貨預設是 I2C 通訊模式。

性能

  • 重量輕:≤ 30g
  • 體積小:≤ 11mm 厚
  • 正常工作電流為:10 ∽ 20mA
  • 工作電壓:5.0 V( LED 的工作電壓是 3.0V,電流 ≤ 20mA,因為在 PCB 上有限流電阻,所以可以直接使用 3.3V 或 5V 電壓驅動
  • 功耗低:10 - 100mW(不帶背光 10 mW,帶背光不大於 100 mW)
  • 顯示內容:192 種字元 ( 5×8 點字型 );32 種字元 ( 5×11 點字型 );可自編 8 種(5×8)或 4 種(5×11)種字元,(注每顯示一個介面最多可以達到 8 個自編字符,但更換顯示介面後可再編);
  • 指令功能強:可組合成各種輸入、顯示、移位元方式以滿足不同的要求;
  • 介面簡單方便:可選擇 4 位平行介面、8 位平行介面、4 線 SPI 序列介面、IIC 介面(I 2 C 介面)
  • 工作溫度寬:-20℃ ~ 70℃;
  • 可靠性高:壽命為 50,000 小時(25℃)。
  • 液晶螢幕尺寸與孔位圖,請參閱所附的資料手冊。

KS0066i

INTRODUCTION
KS0066i is a LCD driver & controller LSI which is fabricated by low power CMOS technology.
It can display 2 lines x 8 (5 x 8 dot format) characters or 1 lines x 8 (5 x 8 or 5 x 11dot format)
characters. It is ideal for multi-language application.
Standard code KS0066i can support up to 240 fonts. Customized codes are available.

FUNCTIONS
  • Character type dot matrix LCD driver & controller
  • Internal drivers
  • 16common and 40 segment for 2 line display, 1/16 duty (N=1, F=0). 11common and 40 segment for 1 line display, 1/11 duty (N=0, F=1). 8 common and 40 segment for 1 line display, 1/8 duty (N=0, F=0).
  • Easy interface with 4-bit or 8-bit 68 series MPU or 4 lines SPI / IIC serial peripheral interface
  • 5 x 8 dot matrix font or 5 x 11 dot matrix font
  • Various instruction functions
  • Automatic power on reset
  • Double Frequency, half instruction time
FEATURES
  • Internal Memory
  • Character Generator ROM (CGROM): 13200 bits (240 characters: 5 x 8 dot or 5 x 11 dots)
  • Character Generator RAM (CGRAM): 64 x 8 bits (8 characters x 5 x 8 dot or 4 characters x 5 x 11)
  • Display Data RAM (DDRAM): 80 x 8 bits (80 characters max.)
  • Power supply voltage range: 2.7 ~ 5.5 V (VDD)
  • LCD Drive voltage range: 3.0 ~ 7V (V0 – VSS)
  • CMOS process
  • Programmable duty cycle: 1/16, 1/11, 1/8 (refer to Table1)
  • Low power consumption
  • Bare chip available

接腳配置與說明

3V3 整合型 1602 英文字型 LCD 螢幕接腳如下所示,跟一般 1602 液晶螢幕接腳都相同。所不同的是,您現在看到的這片液晶螢幕,在未經過任何修改前,就是可直接使用 IIC 通訊控制的液晶螢幕。 為了要能完全使用四種通訊模式,需要對 LCD 作一些小修改。 修改之後的 LCD ,四種模式可經由特意焊接出的兩條選擇線做選擇 ( 如下面圖片中,由 LCD 螢幕下方拉出的兩條紫色細線 ),並且可經由既有的接腳做 I2C 位址的變更,以及切換 SPI 在4種模式下,各接腳的定義與說明:
  • I2C 模式 ( 預設出貨設定模式 )下
  • 經過修改之後的 LCD 螢幕,可藉由 AD0, AD1 ( 兩隻 DB 接腳 ) 設置多達四個不同的 IIC 位址,控制四組 LCD。 若液晶螢幕有經過改裝,則相對應的 I2C 位址 ( AD0, AD1) 設定請參閱所附的 IIC 接線電路圖中的說明。
  • SPI 模式
  • 經過修改之後的 LCD 螢幕,可以使用 RS, CS, SCL, SDA 四個接腳做 SPI 控制通訊模式,連接的 LCD 螢幕數目只侷限於硬體的限制。
  • 4 / 8 BIT 模式下
  • 這是傳統的 LCD 通訊模式,控制通訊方法的說明與範例,請直接參考賣場布拉格中的 "驅動 16x2 英文字型 LCD 螢幕" ( ruten-proteus b logspot com/2012/11/16x2-lcd.html ) 這篇網頁。

Example: 內建四種控制模式整合型1602英文字型液晶螢幕, IIC 通訊模式下,LCD 控制功能展示

完全使用樹莓派硬體 I2C 操作液晶螢幕,除了自定字元功能沒有在影片中出現之外,其他功能完全在影片中呈現。想要知道此液晶螢幕的功能與運作,請上此網頁觀看簡介與影片。


{3V3} 整合型{4/8BIT,IIC,4SPI}1602英文字型藍底白字LCD螢幕(附排針)-適用於樹莓派,微控制器

Price

NT$ 240.

Description

此賣場所販售的 整合型 { 4BIT, 8BIT, IIC, 4SPI } 1602 英文字型 LCD 螢幕是 3V3 系統電源版本
整合型 1602 英文字型 LCD 螢幕是不須外掛任何晶片,就可以使用四種通訊模式的 1602 LCD 螢幕,出貨預設是 IIC 通訊模式。

為了要能完全使用四種通訊模式,需要對 LCD 作一些小修改,因此購買此片 LCD 螢幕的買家,若之後要學習或是使用其他控制通訊模式,就需要自己動手做修改
修改之後的 LCD 就如同打開任督二脈一樣不再受限,四種模式可經由特意焊接出的兩條選擇線做選擇 ( 如下面圖片中,由 LCD 螢幕下方拉出的兩條紫色細線 ),並且可經由既有的接腳做 I2C 位址的變更,以及切換 SPI

控制通訊功能條列如下:
  • IIC 通訊控制模式 ( 硬體、或是軟體 Bit-Banging )
  • 經過修改之後的 LCD 螢幕,可藉由 AD0, AD1 ( 兩隻 DB 接腳 ) 設置多達四個不同的 IIC 位址,控制四組 LCD。
  • SPI 通訊控制模式 ( 硬體,或是軟體 Bit-Banging )
  • 經過修改之後的 LCD 螢幕,可以使用 RS, CS, SCL, SDA 四個接腳做 SPI 控制通訊模式,連接的 LCD 螢幕數目只侷限於硬體的限制。
  • 4 / 8 BIT 通訊模式
  • 這是傳統的 LCD 通訊模式,控制通訊方法的說明與範例,請直接參考賣場布拉格中的 "驅動 16x2 英文字型 LCD 螢幕" ( http://ruten-proteus.blogspot.tw/2012/11/16x2-lcd.html ) 這篇網頁。

出貨清單:
  • 1 x pcs [ 16-pin, 直角 ( 90 ° ) 排針 ]
  • 1 x pcs [ 16-pin, 單頭長排針 ]
  • 1 x pcs [半固定可變電阻 (調亮度用) ]
  • 1 x pcs [ {5V} 整合型 1602 英文字型 LCD 螢幕

性能:

重量輕:≤ 30g
體積小:≤ 11mm 厚
功耗低:10 - 100mW(不帶背光 10 mW,帶背光不大於 100 mW)
顯示內容:192 種字元 ( 5×8 點字型 );32 種字元 ( 5×11 點字型 );可自編 8 種(5×8)或 4 種(5×11)種字元,(注每顯示一個介面最多可以達到 8 個自編字符,但更換顯示介面後可再編);
指令功能強:可組合成各種輸入、顯示、移位元方式以滿足不同的要求;
介面簡單方便:可選擇 4 位平行介面、8 位平行介面、4 線 SPI 序列介面、IIC 介面(I 2 C 介面)
工作溫度寬:-20℃ ~ 70℃;
可靠性高:壽命為 50,000 小時(25℃)。
液晶螢幕尺寸與孔位圖,請參閱所附的資料手冊。

接腳配置與說明

3V3 整合型 1602 英文字型 LCD 螢幕接腳如下所示,跟一般 1602 液晶螢幕接腳都相同。所不同的是,您現在看到的這片液晶螢幕,在未經過任何修改前,就是可直接使用 IIC 通訊控制的液晶螢幕。

在下面的三個表格,就是液晶螢幕在四種通訊控制模式的各接腳功能定義與說明,只要經過小改裝 ( 不變更任何硬體下 ) 就可以自由的設定通訊模式,學習到不同的通訊控制模式。
IIC 模式 ( 預設出貨設定模式 )下,各接腳的定義與說明如下表所示:
Note:若液晶螢幕有經過改裝,則相對應的 IIC 位址 ( AD0, AD1) 設定請參閱所附的 IIC 接線電路圖中的說明。


Example

用在樹莓派上,請先安裝 wiringPi 函式庫 ( wiringpi com/download-and-install ),
相關的使用說明及4-BIT 模式的程式碼,請參考{ 內建四種控制模式整合型 1602 英文字型液晶螢幕 } IIC 通訊模式下,LCD 控制功能展示
  • Bit-Banging 模擬 IIC 模式下,自訂字元與內建字型顯示的樹莓派程式範例 ( C 語言,改寫自 Keil C 程式 )
  • Bit-Banging 模擬 SPI 模式下,自訂字元與內建字型顯示的樹莓派程式範例 ( C 語言,改寫自 Keil C 程式 )
  • SPI 模式下,液晶螢幕功能測試程式 ( 提供 .OBJ 檔、標頭檔 ( .h )以及測試程式範例 ( .c ) )
  • IIC 模式下,液晶螢幕功能測試程式 ( 提供 .OBJ 檔、標頭檔 ( .h )以及測試程式範例 ( .c ) )
  • 使用樹莓派讀取 DHT-11 溫溼度和 BH1750 光強度值並顯示在整合型 LCD 上 ( .C 原始碼 )
  • 大型數字顯示的樹莓派程式碼 ( C 語言 )

Note:預設出貨設定是 IIC 通訊控制模式。經過簡單的改裝之後,就可以變成可使用四種通訊模式控制的 1602 英文字型液晶螢幕。
在不須外掛任何晶片的情況之下,可以使用四種方法來做控制:
  • 並行通訊
  • 4-bit 匯流排模式, 8-bit 匯流排模式
  • 串列通訊
  • IIC ( or 稱 I2C) 模式, 4 線 SPI 模式
IIC 與 SPI 模式函式庫的編譯說明:

如果購買的整合型 LCD 是 3V3 版本,那在商品的雲端硬碟的 codes 資料夾下多了兩個功能測試的程式,分別是使用 IIC 和 SPI 通訊的功能測試,這些功能測試就是上面影片中的那些選項,每個畫面中的選項都對應到函式庫裡的一個功能函式。所有功能函式的定義都宣告在 JLX1602A4IIC.h ( @ IIC 模式 ) 和 JLC1602A4SPI.h ( @ SPI 模式 ) 裡,函式庫已預先編譯為 OBJ 檔 ( 現不提供函式庫原始檔 )。

這些程式可以直接在樹莓派使用瀏覽器下載 ( 或使用部落格介紹的編輯環境設置說明網頁 ) 並存放在家目錄下 ( 假設目錄名稱為 ~/codes/ ),程式編譯的方式如下:


@I2C

pi@raspberrypi ~/codes $ sudo g++ IIC_FunctionTest.cpp JLX1602A4IIC.o -lwiringPi -o iic_functiontest


@SPI

pi@raspberrypi ~/codes $ sudo g++ SPI_FunctionTest.cpp JLX1602A4SPI.o -lwiringPi -o spi_functiontest


要執行,直接輸入編譯後名稱即可,例如要執行 iic_functiontest 就輸入

pi@raspberrypi ~/codes $ ./iic_functiontest

How to Setup an I2C LCD on the Raspberry Pi

Just connect your LCD with I2C, it only uses two pins (well, four if you count the ground and power).
If you want to learn more about I2C and the details of how it works, check out the article "Basics of the I2C Communication Protocol".
There are a couple ways to use I2C to connect an LCD to the Raspberry Pi. The simplest is to get an LCD with an I2C backpack. The hardcore DIY way is to use a standard HD44780 LCD and connect it to the Pi via a chip called the PCF8574.
he PCF8574 converts the I2C signal sent from the Pi into a parallel signal that can be used by the LCD. Most I2C LCDs use the PCF8574 anyway. I’ll explain how to connect it both ways in a minute.

I’ll also show you how to program the LCD using Python, and provide examples for how to print and position the text, clear the screen, scroll text, print data from a sensor, print the date and time, and print the IP address of your Pi.

If you don’t have an I2C enabled LCD or a PCF8574, these tutorials will show you how to connect an LCD with the GPIO pins:
  • How to Setup an LCD on the Raspberry Pi and Program it With C
  • How to Setup an LCD on the Raspberry Pi and Program it With Python

Connect the LCD

I2C (inter-integrated circuit) is also known as the two-wire interface since it only uses two wires to send and receive data. Actually it takes four if you count the Vcc and ground wires, but the power could always come from another source.

Connecting an I2C Enabled LCD
Connecting an LCD with an I2C backpack is pretty self-explanatory. Connect the SDA pin on the Pi to the SDA pin on the LCD, and the SCL pin on the Pi to the SCL pin on the LCD. The ground and Vcc pins will also need to be connected. Most LCDs can operate with 3.3V, but they’re meant to be run on 5V, so connect it to the 5V pin of the Pi if possible.

Connecting an LCD With a PCF8574
If you have an LCD without I2C and have a PCF8574 chip laying around, you can use it to connect your LCD with a little extra wiring. The PCF8574 is an 8 bit I/O expander which converts a parallel signal into I2C and vice-versa. The Raspberry Pi sends data to the PCF8574 via I2C. The PCF8574 then converts the I2C signal into a 4 bit parallel signal, which is relayed to the LCD.

Enable I2C on the Pi


Before we get into the programming, we need to make sure the I2C module is enabled on the Pi and install a couple tools that will make it easier to use I2C.

Enable I2C in raspi-config

First, log in to your Pi and enter sudo raspi-config to access the configuration menu. Then arrow down and select “Advanced Settings”:
Now arrow down and select “I2C Enable/Disable automatic loading”:

Choose “Yes” at the next prompt, exit the configuration menu, and reboot the Pi to activate the settings.
Install I2C-tools and SMBUS


Now we need to install a program called I2C-tools, which will tell us the I2C address of the LCD when it’s connected to the Pi. So at the command prompt, enter sudo apt-get install i2c-tools.

Next we need to install SMBUS, which gives the Python library we’re going to use access to the I2C bus on the Pi. At the command prompt, enter sudo apt-get install python-smbus.

Now reboot the Pi and log in again. With your LCD connected, enter i2cdetect -y 1 at the command prompt. This will show you a table of addresses for each I2C device connected to your Pi:

The I2C address of my LCD is 21. Take note of this number, we’ll need it later.

Programming the LCD





留言

熱門文章