感谢老邓的模块,追梦的香蕉派,以及二叔热心的支持。
以下内容参考了这个帖子:
http://www.52pi.net/forum.php?mod=viewthread&tid=949
这个模块上带一个RGB LED,5个按键,以及一个LCD 1602。
做工很精致。
效果图
 硬件连接
硬件连接很方便,模块附带一个针脚垫脚(也就是把针脚垫高),把垫脚插到香蕉派的排针上,然后再把这个LCD模块插垫脚上就可以了。
I2C配置
root用户登录
1)
apt-get install i2c-tools
2)
vi /etc/modules
添加如下两行内容
i2c-bcm2708
i2c-dev
3)
vi /etc/modprobe.d/raspi-blacklist.conf
注释掉或删除如下两行:
blacklist spi-bcm2708
blacklist i2c-bcm2708
4)
重启香蕉派并重新登录后,执行如下命令
modprobe i2c-dev
i2cdetect -y -a 2
可见LCD模块已被正确识别,模块地址为:0X20
程序代码
- 
				#include 
 - 
				#include 
 - 
				#include 
 - 
				#include 
 - 
				#include 
 - 
				
 - 
				int main()
 - 
				{
 - 
				        time_t timep;
 - 
				        struct tm *ptm;
 - 
				        int display,i;
 - 
				        
 - 
				        wiringPiSetup();
 - 
				        mcp23017Setup (100, 0x20);        
 - 
				        for(i=0;i<16;i++)
 - 
				          pinMode(100+i,OUTPUT); 
 - 
				
 - 
				        digitalWrite(107,1);
 - 
				        digitalWrite(101,0);
 - 
				        display=lcdInit(2,16,4,100,102,103,104,105,106,0,0,0,0); 
 - 
				
 - 
				        lcdHome(display);
 - 
				        lcdClear(display);
 - 
				        while(1)
 - 
				        {
 - 
				                time(&timep);
 - 
				                ptm=localtime(&timep);
 - 
				
 - 
				                lcdPosition(display,4,0);
 - 
				                lcdPrintf(display,"%04d/%02d/%02d",1900+ptm->tm_year, 1+ptm->tm_mon, ptm->tm_mday);
 - 
				
 - 
				                lcdPosition(display,4,1);
 - 
				                lcdPrintf(display,"%02d:%02d:%02d",ptm->tm_hour, ptm->tm_min, ptm->tm_sec);
 - 
				
 - 
				                delay(100); 
 - 
				        }
 - 
				}
 - 
				
 
编译并执行:
gcc lcd1602.c -lwiringPi /opt/gpio-lib/WiringBPi_Beta_V2.0/devLib/lcd.o -o lcd1602关于tm结构体:
./lcd1602
- 
				struct tm
 - 
				{
 - 
				    int tm_sec; /* Seconds. [0-60] (1 leap second) */
 - 
				    int tm_min; /* Minutes. [0-59] */
 - 
				    int tm_hour; /* Hours. [0-23] */
 - 
				    int tm_mday; /* Day. [1-31] */
 - 
				    int tm_mon; /* Month. [0-11] */
 - 
				    int tm_year; /* Year - 1900. */
 - 
				    int tm_wday; /* Day of week. [0-6] */
 - 
				    int tm_yday; /* Days in year.[0-365] */
 - 
				    int tm_isdst; /* DST. [-1/0/1]*/
 - 
				};
 - 
				
 
			
			
			
						
			
 我要赚赏金
