本模块其实就是由arduino商家自行设置的一个LCD1602扩展板,主要就是为了方便和Arduino配合使用,实现即插即用的效果!
1602LCD主要技术参数
显示容量为16×2个字符;
芯片工作电压为4.5~5.5V;
工作电流为2.0mA(5.0V);
模块最佳工作电压为5.0V;
字符尺寸为2.95×4.35(W×H)mm。
1602液晶接口引脚定义
接口说明:
1、两组电源 一组是模块的电源 一组是背光板的电源 一般均使用5V供电。本次试验背光使用3.3V供电也可以工作。
2、VL是调节对比度的引脚,串联不大于5KΩ的电位器进行调节。本次实验使用1KΩ的电阻来设定对比度。其连接分高电位与低电位接法,本次使用低电位接法,串联1KΩ电阻后接GND。
3、RS 是很多液晶上都有的引脚 是命令/数据选择引脚 该脚电平为高时表示将进行数据操作;为低时表示进行命令操作。
4、RW 也是很多液晶上都有的引脚 是读写选择端 该脚电平为高是表示要对液晶进行读操作;为低时表示要进行写操作。
5、E 同样很多液晶模块有此引脚 通常在总线上信号稳定后给一正脉冲通知把数据读走,在此脚为高电平的时候总线不允许变化。
6、D0—D7 8 位双向并行总线,用来传送命令和数据。
7、BLA是背光源正极,BLK是背光源负极。
现在介绍一下这个扩展板的定义和描述:
Arduino LCD1602字符液晶扩展板v2.0 集国内外多款扩展板优点于一体所设计,PCB沉金工艺加工,用料十足,主板采用全新 优质2行16个字符液晶 ,不仅具有对比度调节旋钮、背光灯选择开关,还具4个方向按键、1个选择按键和一个复位按键;4个传感器模拟接口、 RB URF v1.1超声波传感器 接口、蓝牙模块接口、APC220无线数传模块通信接口、独立扩出更加易用方便。对于Arduino初学者来说,不必为繁琐复杂液晶驱动电路连线而头疼了,这款1602液晶扩展板真正意义上的将电路简化,直接将此板插到 Arduino Duemilanove或者UNO控制器 上即可,传感器也仅需一根通用3P传感器连接线(不分数字连接线与模拟连接线)连接,可轻松实现传感器数据的记录显示。
LCD Keypad Shield输入输出扩展板使用2行16个字符液晶,具有对比度调节和背光灯,使用1个模拟口便完成5个按键的输入,1个复位按键,未使用的IO口都扩展出来备用,充分利用IO口。占用数字端口:PIN4(DB4),5(DB5),6(DB6),7(DB7),8(RS),9(E),10(背光控制),模拟按键端口A0。
将LCD Keypad Shield插接到Arduino控制器上,然后需要下载LCD4Bit_mod.h(右键另存为)库文件到arduino-0015\hardware\libraries中,接着编译下面的一个测试程序再下载到Arduino中,初次使用LCD Keypad Shield,先观察LCD有没有显示字符,如果没有显示字符那可能是对比度不正确,可以使用一字起子调节RP1(顺时针旋转),调到出现清晰地字符即可。
看一下整个模块的效果图:
如果你想了解这个扩展板的定义,请看一下这两个图片的引脚定义。
上面这两个功能图解就能说明问题了,IIC接口是A4与A5两个接口,那扩展板上A4、A5的接口也就是插接IIC设备的数据通信接口,这部分接口复用,就想串口那些接口一样,既可以当数字接口输出高低电平也可以串行通信.
以下就是测试代码:
- //example use of LCD4Bit_mod library
- #include <LCD4Bit_mod.h>
- //create object to control an LCD.
- //number of lines in display=1
- LCD4Bit_mod lcd = LCD4Bit_mod(2);
- //Key message
- char msgs[5][18] = {"fiveKeyNoProblem ",
- "threeKeyNoProblem",
- "fourKeyNoProblem ",
- "twoKeyNoProblem",
- "oneKeyNoProblem" };
- int adc_key_val[5] ={30, 150, 360, 535, 760 };
- int NUM_KEYS = 5;
- int adc_key_in;
- int key=-1;
- int oldkey=-1;
- void setup() {
- pinMode(13, OUTPUT); //we'll use the debug LED to output a heartbeat
- lcd.init();
- //optionally, now set up our application-specific display settings, overriding whatever the lcd did in lcd.init()
- //lcd.commandWrite(0x0F);//cursor on, display on, blink on. (nasty!)
- lcd.clear();
- lcd.printIn("geeetech.com");
-
- }
- void loop() {
- adc_key_in = analogRead(0); // read the value from the sensor
- digitalWrite(13, HIGH);
- key = get_key(adc_key_in); // convert into key press
-
- if (key != oldkey) // if keypress is detected
- {
- delay(50); // wait for debounce time
- adc_key_in = analogRead(0); // read the value from the sensor
- key = get_key(adc_key_in); // convert into key press
- if (key != oldkey)
- {
- oldkey = key;
- if (key >=0){
- lcd.cursorTo(2, 0); //line=2, x=0
- lcd.printIn(msgs[key]);
- }
- }
- }
-
- //delay(1000);
- digitalWrite(13, LOW);
-
-
-
-
- }
- // Convert ADC value to key number
- int get_key(unsigned int input)
- {
- int k;
-
- for (k = 0; k < NUM_KEYS; k++)
- {
- if (input < adc_key_val[k])
- {
-
- return k;
- }
- }
-
- if (k >= NUM_KEYS)
- k = -1; // No valid key pressed
-
- return k;
- }
复制代码
下面来一个和GP2D12测距的代码!
- #include <LCD4Bit_mod.h>
- LCD4Bit_mod lcd = LCD4Bit_mod(2);
- char GP2D12;
- char a,b;
- char str1[]="Renge:";
- char str2[]=" Renge Over ";
- char str3[]="cm";
- void setup()
- {
- lcd.init();
- lcd.clear();
- lcd.printIn("GP2D12 testing...");
- }
- void loop()
- {
- GP2D12=read_gp2d12_range(1);
- if(GP2D12>80||GP2D12<10)
- {
- lcd.cursorTo(2,0);
- lcd.printIn(str2);
- }
- else
- {
- a=0x30+GP2D12/10;
- b=0x30+GP2D12%10;
- lcd.cursorTo(2, 3);
- lcd.printIn(str1);
- lcd.print(a);
- lcd.print(b);
- lcd.printIn(str3);
- }
- delay(50);
- }
- float read_gp2d12_range(byte pin)
- {
- int tmp;
- tmp = analogRead(pin);
- if (tmp < 3)return -1;
- return (6787.0 /((float)tmp - 3.0)) - 4.0;
- }
-
复制代码 |