这些小活动你都参加了吗?快来围观一下吧!>>
电子产品世界 » 论坛首页 » DIY与开源设计 » 开源硬件 » 【二叔科技】52pi's BPI 1602 LCD 完整样板

共2条 1/1 1 跳转至

【二叔科技】52pi's BPI 1602 LCD 完整样板

助工
2015-01-31 21:06:21     打赏

52pi.net有个老邓,老邓做了个LCD屏幕,


这个屏幕是给BPI也就是香蕉派制作的,



通过一个叫mcp23017的i2c芯片,


扩展出了16个双向I/O,


一个模块集成了三种功能,


1、一块1602屏幕,蓝屏

2、一个RGB-LED,亮瞎眼,盲打中

3、五个独立按键


这是一个综合的例子



#include 
#include 
#include 
#include 
#include 
#include 
int page=3;
int select=1;
int display;
int color=0;
pthread_t id;
void show()
{
    time_t timep;
    struct tm *ptm;
	digitalWrite ( 113, LOW);
	digitalWrite ( 114, LOW);
	digitalWrite ( 115, LOW);
	lcdPosition(display,0,0);
	switch(page)
	{
		case 0:
			if (select==1)
			{
				lcdPrintf(display,">>1.Joytag Time ");
				lcdPrintf(display,"  2.Uncle's RGB ");
			}
			else
			{
				lcdPrintf(display,"  1.Joytag Time ");
				lcdPrintf(display,">>2.Uncle's RGB ");
			}
			break;
		case 1:
			time(&timep);
			ptm=localtime(&timep);
            lcdPrintf(display,"   %04d/%02d/%02d   ",1900+ptm->tm_year, 1+ptm->tm_mon, ptm->tm_mday);
            lcdPrintf(display,"    %02d:%02d:%02d    ",ptm->tm_hour, ptm->tm_min, ptm->tm_sec);
			break;
		case 2:
			lcdPrintf(display," **Uncle's RGB**");
			lcdPrintf(display,"     Color: %d   ",color);
			digitalWrite ( 113, color&0x01);
			digitalWrite ( 114, color&0x02);
			digitalWrite ( 115, color&0x04);
			color=(color+1)%8;
			delay(400);
			break;
		case 3:
            lcdPrintf(display,"RGB&1602 Module ");
            lcdPrintf(display,"For BPI 52pi.net");
			break;
	}
	delay(100);
}
void key(void)
{
	int i;
	while(1)
	{
		for(i=108;i<113;i++)
		{
			if (digitalRead(i)>0)
			{
				switch(i)
				{
					case 108:
						page=0;
						break;
					case 109:
						select=select%2+1;
						break;
					case 110:
						page=3;
						break;
					case 111:
						page=select;
						break;
					case 112:
						select=select%2+1;
						break;
				}
				delay(400);
			}
		}
		delay(100);
	}
}
int main()
{
	wiringPiSetup();
	mcp23017Setup (100, 0x20);
	pthread_create(&id,NULL,(void *)key,NULL);
	digitalWrite(107,1);
	digitalWrite(101,0);
	display=lcdInit(2,16,4,100,102,103,104,105,106,0,0,0,0);
	lcdHome(display);
	while(1) 
		show();
}


首先是欢迎界面,点击右边单独的按键进入菜单




一共两个选项,没做翻页,


1、卓泰的时间

2、二叔的LED


上下键选择,右键选定,左键可以进入欢迎页面



点击右边单独的键,退回到Menu



千万不要直视,会死人的!


运行办法:


gcc bpi1602.c  -lwiringPi  /opt/gpio-lib/WiringBPi_Beta_V2.0/devLib/lcd.o -o bpi1602
./bpi1602



二叔科技原创,关注二叔科技 http://2.liub.org

二叔科技.创客空间 167153362


专家
2015-01-31 22:20:31     打赏
2楼
牛叉。1602可以这么玩

共2条 1/1 1 跳转至

回复

匿名不能发帖!请先 [ 登陆 注册 ]