Difference between revisions of "Matrix - I2C LCD1602"
From FriendlyELEC WiKi
(→How It Works) |
(→PCF8574) |
||
Line 18: | Line 18: | ||
==How They Work== | ==How They Work== | ||
===PCF8574=== | ===PCF8574=== | ||
− | * | + | *The PCF8574 module's interface is I2C parallel which is 8 bit and has 8 IO (P0 - P7) outputs. |
+ | *模块为i2c并行口扩展电路,即对输入的i2c字节数据实现8位并行io输出(P0-P7),因此开发板可以可以通过i2c总线实现远程io扩展。 | ||
+ | *The PCF8574 module uses the PCF8574T chip whose address diagram is as follows | ||
*PCF8574需要与i2c总线进行通信,由i2c总线特性可以知道i2c总线传输数据到该模块时必须有该模块的器件地址。本模块使用的PCF8574芯片型号为PCF8574T,其地址为如下图所示: | *PCF8574需要与i2c总线进行通信,由i2c总线特性可以知道i2c总线传输数据到该模块时必须有该模块的器件地址。本模块使用的PCF8574芯片型号为PCF8574T,其地址为如下图所示: | ||
[[File:pcf8574.png|frameless|400px|PCF8574]] | [[File:pcf8574.png|frameless|400px|PCF8574]] |
Revision as of 08:20, 17 August 2015
Contents
1 Introduction
This is an LCD module which has an I2C controller. It can display 16 x 2 characters. Its interface is parallel. To simplify its application we designed a controller on this module, which interfaces with other modules through I2C and transfers received signals to parallel signals to LCD1602. It can display, turn on and off back light.
2 Features
- I2C interface. It can display characters, and turn on and off back light
- 2.54 mm spacing pin
- I2C PCB dimension:16 x 42 mm
- LCD1602 PCB dimension: 36 x 80 mm
3 How They Work
3.1 PCF8574
- The PCF8574 module's interface is I2C parallel which is 8 bit and has 8 IO (P0 - P7) outputs.
- 模块为i2c并行口扩展电路,即对输入的i2c字节数据实现8位并行io输出(P0-P7),因此开发板可以可以通过i2c总线实现远程io扩展。
- The PCF8574 module uses the PCF8574T chip whose address diagram is as follows
- PCF8574需要与i2c总线进行通信,由i2c总线特性可以知道i2c总线传输数据到该模块时必须有该模块的器件地址。本模块使用的PCF8574芯片型号为PCF8574T,其地址为如下图所示:
- 由模块的原理图可以看出A2-A0全部置1,则7位器件地址为0x27(0100111),RW默认为0,此时模块为写模式。
- 这时打开i2c-0设备并设置好器件地址了,便可以成功对模块进行写操作了。
- 当要对模块进行读操作需要把模块设置为读模式(RW改置1),由于这里没有用到,不详细介绍,具体可以参看PCF8574的datasheet。
3.2 LCD1602
- 由模块的原理图可以看出PCF8574模块的输出引脚P0-P7与LCD模块的引脚连接如下图:
- RS为指令/数据控制位,RW为读/写控制位,E为使能位(边沿触发),BL为背光灯控制位,D4-D7为数据位。
- 由于LCD用到四个数据位,因此只能使用4线来驱动。通过指令表我们可以对LCD进行写指令设置LCD的工作转态,但这里的指令/数据(DB7-DB0)是八位的,而LCD却是4线驱动,因此每次写指令/数据时是先写高四位(DB7-DB4),再写低四位(DB3-DB0)。
- 注意:LCD内置了192个常用字模,存放在CGROM,所以我们在显示字符A时可以直接写入“A”,此外LCD还有8个允许用户自定义的字符产生的RAM,称为CGRAM,这里由于没有涉及到所以不介绍,有兴趣的用户可以去了解一下。
4 How To
4.1 Connection
- Connect to Tiny4412 SDK (1506)
- GND: Ground
- VCC: 5V
- SDA: I2C SDA
- SCL: I2C SCL
4.2 Code Sample in C Under Linux
#include <stdio.h> #include <unistd.h> #include <sys/types.h> #include <sys/stat.h> #include <fcntl.h> #include <stdlib.h> #include "libfahw.h" void test(char* line1, char* line2) { int devFD; if ((devFD = LCD1602Init()) == -1) { printf("Fail to init LCD1602\n"); return; } if (LCD1602Clear(devFD) == -1) { printf("Fail to Clear\n"); return; } if (LCD1602DispLines(devFD, line1, line2) == -1) { printf("Fail to Display String\n"); return ; } LCD1602DeInit(devFD); } int main(int argc, char ** argv) { int i; for (i=0; i<10; i++) { test("FriendlyARM", "From 2003"); sleep(3); } return 0; }
4.3 Compile and Run
git clone http://github.com/friendlyarm/fa-hardware.git cd fa-hardware cd demo cd matrix-i2c_lcd1602 make
Copy your compiled bin to your board and you are ready to go.