基于粤嵌GEC6818开发板的智能家居控制系统(附程序) 您所在的位置:网站首页 gec中登录 基于粤嵌GEC6818开发板的智能家居控制系统(附程序)

基于粤嵌GEC6818开发板的智能家居控制系统(附程序)

2024-07-13 21:04| 来源: 网络整理| 查看: 265

一、需求分析

智能家居系统是一种近年来兴起的智能化系统,在家庭场合基本都能看到它的身影,各种家居通过一个智能控制终端来进行人机交互。本课题基于粤嵌GEC-6818开发平台,定制的Linux系统,通过C语言的编程,经过交叉编译环境,让编译的文件能够直接适用于ARM开发板。用7寸LCD电容式触摸屏作为人机互交的方式,做到可以LED控制、液晶屏检测、报警控制、电子相册、音乐播放、家电控制的功能,显示相应的界面。具有音频输出的功能,获取屏幕触摸点的坐标,实现界面上相应的功能。通过这次的设计,掌握了ARM的结构体系,了解了部分的Linux命令,对文件的读写操作等,初步掌握了交叉编译方式,加强了对嵌入式产品的认知。同时,在本课程设计时的调试、排错,让我们对C语言进行了一次查漏补缺,也巩固了C语言基础。让我们能够用团队的力量,对ARM系列的开发板进行开发,用固定的硬件设备实现多种功能,了解ARM开发的文件读取方式、交叉编译环境。扩大了我们的眼界,学会了无显示界面时使用Linux命令操作设备。

二、设计过程1、嵌入式开发环境搭建12345678910安装交叉编译器:arm-linux-gnueabi-5.4.0.tar.xz1)复制arm-linux-gnueabi-5.4.0.tar.xz到/usr/local/arm2)解压命令arm-linux-gnueabi-5.4.0.tar.xz3)然后配置下编译环境路径:在/usr/local/arm下输入:vi /etc/profile加上下面代码:export PATH=/usr/local/arm/5.4.0/usr/bin:$PATH4)重启不重启:输入source /etc/profile使之生效 2、进行在液晶屏上显示单色–液晶屏检测的功能

打开液晶屏—open()

1234#include #include #include int open(const char *pathname, int flags);

参数说明:const char *pathname —–文件的路径名。液晶屏:“/dev/fb0”int flags —- 文件的访问属性:O_RDONLY, O_WRONLY, or O_RDWR2、写入颜色数据—write()显示红色:

12345int lcd_buf[800*480];//数组的大小:800*480*4for(int i=0; i 100 && ts.y < 160)//led3 on { led_ctrl(LED3, LED_ON); printf("LED3 on\n"); ts.x=0;ts.y=0; } if (ts.x > 530 && ts.x < 680 && ts.y > 200 && ts.y < 260)//led3 off { led_ctrl(LED3, LED_OFF); printf("LED3 off\n"); ts.x=0;ts.y=0; } if (ts.x > 530 && ts.x < 680 && ts.y > 300 && ts.y < 360)//led4 on { led_ctrl(LED4, LED_ON); printf("LED4 on\n"); ts.x=0;ts.y=0; } if (ts.x > 530 && ts.x < 680 && ts.y > 400 && ts.y < 460)//led4 off { led_ctrl(LED4, LED_OFF); printf("LED4 off\n"); ts.x=0;ts.y=0; } } if (ts.x > 60 && ts.x < 300 && ts.y > 240 && ts.y < 300 && mode == CTL)//进入LCD测试界面 { mode = LCDt; //进入液晶屏检测功能 int ret; ret = pthread_create(&tid_ts, NULL, check_lcd, NULL); if(ret < 0 ) { perror("create ts_thread error"); return -1; } while (1) { ts = ts_get_xy(); if (ts.x > 700 && ts.x < 800 && ts.y > 0 && ts.y < 60) { //退出液晶屏检测 pthread_cancel(tid_ts); break; } } mode=CTL; ts.x=0;ts.y=0; } if ((ts.x > 60 && ts.x < 300 && ts.y > 350 && ts.y < 420 && mode == CTL) || mode == MUS)//进入Music界面 { lcd_show_bmp("/pic/music.bmp"); mode = MUS; if (ts.x > 30 && ts.x < 170 && ts.y > 210 && ts.y < 260)//Music界面:音乐播放 { printf("Music begin\n"); system("madplay /IOT/mp3/test.mp3 &"); //madplay进程在后台运行 } if (ts.x > 135 && ts.x < 273 && ts.y > 300 && ts.y < 400)//上一首 { printf("Previous music \n"); } if (ts.x > 515 && ts.x < 657 && ts.y > 300 && ts.y < 400)//下一首 { printf("Next music \n"); } if (ts.x > 230 && ts.x < 370 && ts.y > 210 && ts.y < 260)//Music界面:音乐暂停 { printf("Music pause\n"); system("killall -STOP madplay &"); ts.x=0;ts.y=0; } if (ts.x > 420 && ts.x < 560 && ts.y > 210 && ts.y < 260)//Music界面:音乐继续 { printf("Music continue\n"); system("killall -CONT madplay &"); ts.x=0;ts.y=0; } if (ts.x > 620 && ts.x < 760 && ts.y > 210 && ts.y < 260)//Music界面:音乐停止 { printf("Music stop\n"); system("killall -KILL madplay &"); ts.x=0;ts.y=0; } } if ((ts.x > 460 && ts.x < 700 && ts.y > 140 && ts.y < 200 && mode == CTL )|| mode == BEEP)//进入蜂鸣器控制 { mode = BEEP; lcd_show_bmp("/pic/beep_ctrl.bmp"); if (ts.x > 120 && ts.x < 310 && ts.y > 200 && ts.y < 322)//蜂鸣器响 { beep_ctrl(BEEP_ON); printf("Beep open \n"); ts.x=0;ts.y=0; } if (ts.x > 490 && ts.x < 670 && ts.y > 200 && ts.y < 322)//蜂鸣器停 { beep_ctrl(BEEP_OFF); printf("Beep stop \n"); ts.x=0;ts.y=0; } } if (ts.x > 460 && ts.x < 700 && ts.y > 240 && ts.y < 300 && mode == CTL)//进入数码相册 { mode = HA; int ret; ret = pthread_create(&tid_ts, NULL,digital_photo, NULL); if(ret < 0 ) { perror("create ts_thread error"); return -1; } while (1) { ts = ts_get_xy(); if (ts.x > 700 && ts.x < 800 && ts.y > 0 && ts.y < 60) { //退出电子相册 pthread_cancel(tid_ts); break; } } mode=CTL; ts.x=0;ts.y=0; } if ((ts.x > 460 && ts.x < 700 && ts.y > 350 && ts.y < 420)&& mode == CTL || mode == HA)//进入家电控制 { mode = HA; lcd_show_bmp("/pic/key.bmp"); if (ts.x > 158 && ts.x < 298 && ts.y > 195 && ts.y < 255)//风扇开 { printf("Fan:on \n"); ts.x=0;ts.y=0; } if (ts.x > 158 && ts.x < 298 && ts.y > 320 && ts.y < 372)//风扇关 { printf("Fan:off \n"); ts.x=0;ts.y=0; } if (ts.x > 500 && ts.x < 640 && ts.y > 195 && ts.y < 255)//空调开 { printf("Air-conditioning:on \n"); ts.x=0;ts.y=0; } if (ts.x > 500 && ts.x < 640 && ts.y > 320 && ts.y < 372)//空调关 { printf("Air-conditioning:off \n"); ts.x=0;ts.y=0; } } if (ts.x > 650 && ts.x < 800 && ts.y > 420 && ts.y < 480 && mode == MAIN)//start { lcd_show_bmp("/pic/control"); mode = CTL; ts.x=0;ts.y=0; } } ts.x=0;ts.y=0; } } return 0; }

touch.h:

1234567891011121314151617181920212223242526272829303132#include "touch.h"struct xy ts_get_xy(void){ struct xy z; int x,y; int fd_ts; fd_ts = open("/dev/input/event0", O_RDONLY); if(fd_ts == -1) { perror("open ts"); exit(-1); } struct input_event ts_data; for (int i = 0; i < 6; i++) { //2、读取触摸屏的数据 read(fd_ts, &ts_data, sizeof(struct input_event)); if(ts_data.type == EV_ABS) { if(ts_data.code == ABS_X) x = ts_data.value*800/1024; else if(ts_data.code == ABS_Y) y = ts_data.value*480/600; } } z.x=x; z.y=y; close(fd_ts); return z;}

Touch.h:

1234567891011121314151617#ifndef __TOUCH_H_#define __TOUCH_H_#include #include #include #include #include #include #include struct xy{ int x; int y;};struct xy ts_get_xy();#endif

Lcd.c:

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166#include #include "lcd.h"int lcd_show_color(unsigned int color){//1、打开液晶屏---open() int lcd_fd; lcd_fd = open("/dev/fb0",O_RDWR); if(lcd_fd == -1) { perror("open lcd failed"); return -1; }//2、显存映射,得到显存的首地址---mmap() int *lcd_base = NULL; lcd_base = mmap(NULL, // 填NULL表示显存地址由系统自动分配 800*480*4, // 整块屏幕的显存大小 PROT_READ|PROT_WRITE, // 显存保护权限:可读可写 MAP_SHARED, // 多进程共享设置 lcd_fd, // LCD文件描述符 0); // 0表示不偏移 if(lcd_base == NULL) { printf("lcd mmap error\n"); return -1; }//3、通过显存首地址,直接向显存写入颜色数据 for(int i=0;i


【本文地址】

公司简介

联系我们

今日新闻

    推荐新闻

    专题文章
      CopyRight 2018-2019 实验室设备网 版权所有