北京邮电大学电子信息嵌入式实验报告.doc_第1页
北京邮电大学电子信息嵌入式实验报告.doc_第2页
北京邮电大学电子信息嵌入式实验报告.doc_第3页
北京邮电大学电子信息嵌入式实验报告.doc_第4页
北京邮电大学电子信息嵌入式实验报告.doc_第5页
已阅读5页,还剩14页未读 继续免费阅读

下载本文档

版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领

文档简介

电子工程学院 2008211204嵌入式实验王宁西 08211002电子信息科学与技术专业实验实验报告班级 2008211204姓名 王宁西学号 08211002-第一部分-必做实验:1. 基本实验:搭建PXA270嵌入式LINUX开发软硬件环境;安装LINUX操作系统;安装与配置建立宿主机端交叉编译调试开发环境;配置宿主机 PC 机端的minicom(或超级终端)、TFTP服务、NFS服务,使宿主PC机与PXA270开发板可以通过串口通讯,并开通TFTP和NFS服务。2. 人机接口:键盘驱动;LCD控制;触摸屏数据采集与控制实验;3. 应用实验:完成VGA显示;Web服务器实验;网络文件传输实验;多线程应用实验。4. 应用实验扩展应用:完成USB摄像头驱动与视频采集;GPS实验;GSM/GPRS通讯;视频播放移植;USB蓝牙设备无线通讯;NFS文件服务器;蓝牙视频文件服务器。5. QT实验:完成基本嵌入式图形开发环境搭建;“Hello world!”QT初探;创建一个窗口并添加按钮;对象通信:Signal和Slot;菜单和快捷键;工具条和状态栏;鼠标和键盘事件;对话框;QT的绘图;俄罗斯方块;基于QT的GSM手机在嵌入式LINUX下的设计与实现。实验体会:以前没有接触过LINUX系统,也没有用LINUX、C对硬件进行开发过。此次实验的必做部分提供了详细的实验步骤和一些必要信息,因此必做实验完成起来基本没有难度。但通过必做实验要熟悉驱动程序框架、目标板相关板块开发的细节,以及扩展功能的实现方法。因为此次实验在知识上有一定的跨度,所以必做实验提供的代码对于加深理解和加快学习速度有很大帮助。通过实践和分析实验手册上提供的实验步骤,可以直观地了解每一个步骤的作用及意义。必做实验也为选做实验提供了一个拓展平台,为最后设计综合实验的相关知识进行了强化。-第二部分-选做实验:(以下是本人所选题目以及完成情况)1. 基于LCD、键盘、触摸屏设计实现对PXA270开发系统上的LCD上彩色条竖纹或彩色圆环等变化控制。流程图:Heng() 画横条输入1If判断主程序main开始Main 结束Shu() 画竖条输入0程序:#include #include #include #include / open() close()#include / read() write()#include #define DEVICE_NAM /dev/keypad#define DEVICE_NAME /dev/fb#define VERSION PXA2700EP-LCD-V1.00-060530void showversion(void) printf(*n); printf(t %s tn, VERSION); printf(*nn);/- main -void heng(void)unsigned short buf640*480;int i;int ret;int fd;fd = open(DEVICE_NAME,O_RDWR); for(i=0;i640*480/8;i+) bufi=0x0001; for(i=640*480/8;i640*480*2/8;i+) bufi=0xf800; for(i=640*480*2/8;i640*480*3/8;i+) bufi=0x07ef; for(i=640*480*3/8;i640*480*4/8;i+) bufi=0x001f; for(i=640*480*4/8;i640*480*5/8;i+) bufi=0xffe0; for(i=640*480*5/8;i640*480*6/8;i+) bufi=0x07ff; for(i=640*480*6/8;i640*480*7/8;i+) bufi=0xf81f; for(i=640*480*7/8;i640*480;i+) bufi=0xffff; ret = write(fd,buf,sizeof(buf);void shu(void)unsigned short buf640*480;int i;int j;int ret;int fd;fd=open(DEVICE_NAME,O_RDWR); for(j=0;j480;j+) for(i=640*j;i640*j+640/8;i+) bufi=0x0001; for(i=640*j+640/8;i640*j+640*2/8;i+) bufi=0xf800; for(i=640*j+640*2/8;i640*j+640*3/8;i+) bufi=0x07ef; for(i=640*j+640*3/8;i640*j+640*4/8;i+) bufi=0x001f; for(i=640*j+640*4/8;i640*j+640*5/8;i+) bufi=0xffe0; for(i=640*j+640*5/8;i640*j+640*6/8;i+) bufi=0x07ff; for(i=640*j+640*6/8;i640*j+640*7/8;i+) bufi=0xf81f; for(i=640*j+640*7/8;i0时执行)程序:Pthread.c#include #include #include #include pthread.h#include #include / open() close()#include / read() write()#include #include /#include #include #include #include touch.h#define DEVICE_KEYNAME /dev/keypad#define DEVICE_FBNAME /dev/fb#define BUFFER_SIZE 16int flag=0;Point d;/*-*/ /print circlevoid drawcircle(int x,int y)unsigned short buf640*480;int i,j;int ret;int fd;fd=open(DEVICE_FBNAME,O_RDWR);for(i=0;i480;i+)for(j=0;j640;j+)if (i-y)*(i-y)+(j-x)*(j-x)20000) bufi*640+j=0x07ff;if (i-y)*(i-y)+(j-x)*(j-x)13000) bufi*640+j=0x07ef;if (i-y)*(i-y)+(j-x)*(j-x)lock, NULL); pthread_cond_init(&b-notempty, NULL); pthread_cond_init(&b-notfull, NULL); b-readpos = 0; b-writepos = 0;/*-*/* Store an integer in the buffer */void put(struct prodcons * b, Point data)pthread_mutex_lock(&b-lock); /* Wait until buffer is not full */ while (b-writepos + 1) % BUFFER_SIZE = b-readpos) printf(wait for not fulln); pthread_cond_wait(&b-notfull, &b-lock); /* Write the data and advance write pointer */ b-bufferb-writepos.x = data.x;b-bufferb-writepos.y = data.y; b-writepos+; if (b-writepos = BUFFER_SIZE) b-writepos = 0; /* Signal that the buffer is now not empty */ pthread_cond_signal(&b-notempty);pthread_mutex_unlock(&b-lock);/*-*/* Read and remove an integer from the buffer */void get(struct prodcons * b) Point data;pthread_mutex_lock(&b-lock); /* Wait until buffer is not empty */ while (b-writepos = b-readpos) printf(wait for not emptyn);pthread_cond_wait(&b-notempty, &b-lock); /* Read the data and advance read pointer */ data.x = b-bufferb-readpos.x;data.y = b-bufferb-readpos.y; b-readpos+; if (b-readpos = BUFFER_SIZE) b-readpos = 0; /* Signal that the buffer is now not full */ pthread_cond_signal(&b-notfull); pthread_mutex_unlock(&b-lock);d.x=data.x;d.y=data.y;/ return data;/*-*/Point OVER;Point nn;struct prodcons buffer;/*-*/*-screen input-*/int touchscreen_fd = 0; /* touch screen device handle */ts_event_t ts_CalPointsCAL_POINT_NUM; /* touch screen calibration pBuffer */ / Retrieve an average data from touch screen input deviceint Cal_DataAvg(int ts_handler, ts_event_t * ts_avg, unsigned short max_num) ts_event_t *tmpDataArr; ts_event_t tmpData; unsigned short bp, i; unsigned short count; long tempX, tempY; int ret; static int curr_x = 0, curr_y = 0, curr_p = 0; static int got_curr_x = 0, got_curr_y = 0; int got_curr_p = 0; int next_x, next_y; int got_next_x = 0, got_next_y = 0; struct input_event ev; tmpDataArr = (ts_event_t *)malloc(max_num * sizeof(ts_event_t); if (tmpDataArr = NULL) printf(Error: malloc failed.n); return -1; for (i = 0; i max_num; i+) tmpDataArri.x = 0; tmpDataArri.y = 0; tmpDataArri.pressure = 0; tmpDataArri.flag = -1; / Read a set of data into buffer count = 0;do bp = 0; while (1) memset(&tmpDataArrbp, 0, sizeof(ts_event_t); ret = read(ts_handler, &ev, sizeof(struct input_event); if (ret sizeof(struct input_event) break; if (ev.type = EV_ABS) switch (ev.code) case ABS_X: curr_x = ev.value; break; case ABS_Y: curr_y = ev.value; break; case ABS_PRESSURE: curr_p = ev.value; break; tmpDataArrbp.x = curr_x; tmpDataArrbp.y = curr_y; tmpDataArrbp.pressure = curr_p; if (bp max_num ) bp+; else break; count = bp; while (count = 0); tempX = tempY = 0; for (bp = 0; bp x = tempX / count; ts_avg-y = tempY / count; ts_avg-pressure = 0xffff; / Release free(tmpDataArr);void getpoint(void) char * tsconf_name; Point Screen_PointCAL_POINT_NUM;/* unsigned short x_max, y_max; unsigned short i; */int x_max,y_max;int i; FILE * fp; i = 0;Point xy; touchscreen_fd = open(TOUCHSCREEN_DEV, O_RDONLY); if (touchscreen_fd 0) fprintf (stderr, Cannot open touch screen device %s.n, TOUCHSCREEN_DEV);nn.x=-1; nn.y=-1; /return NULL; else fprintf (stderr, the touch screen device %sis opened.n, TOUCHSCREEN_DEV);fprintf (stderr, please touch the screen to test the driver is workingn); while (1) Cal_DataAvg(touchscreen_fd, &ts_CalPointsi, 10);xy.x=ts_CalPointsi.x;xy.y=ts_CalPointsi.y;flag+;printf(x=%d,y=%d,flag=%dn,xy.x,xy.y,flag);nn=xy;put(&buffer,xy); close(touchscreen_fd);void * screen(void * data) Point n;/* for (n = 0; n %dn, n); put(&buffer, n); */ getpoint(); n.x=-1; n.y=-1; put(&buffer,n); put(&buffer, OVER); printf(screen stopped!n); return NULL;/*-*/void inputpoint()int fd; int ret; unsigned char buff2; char pre_scancode = 0xff;Point xy; fd = open(DEVICE_KEYNAME, O_RDWR); printf(fd = %dn,fd); if (fd = -1) printf(open device %s errorn,DEVICE_KEYNAME); else buff0=0x22; while(1) read(fd,buff,1); if(buff0!=pre_scancode) xy.x=nn.x;xy.y=nn.y; if(buff0!=0xff) if(buff0=0x02) xy.y=xy.y+50; printf(push 2n); if(buff0=0x04) xy.x=xy.x-50; printf(push 4n);if(buff0=0x06) xy.x=xy.x+50; printf(push 6n);if(buff0=0x08) xy.y=xy.y-50; printf(push 8n); if(xy.x0) xy.x=0; /rectifyif(xy.y=640) xy.x=640-1;if(xy.y=480) xy.y=480-1;if(xy.x!=nn.x)|(xy.y!=nn.y)flag+;printf(x=%d,y=%d,flag=%dn,xy.x,xy.y,flag);nn.x=xy.x; nn.y=xy.y;put(&buffer,xy); /if pre pre_scancode = buff0; /while/else ret=close(fd);void * keyboard(void * data) Point n; int i=0;/* while (1) d = get(&buffer); if (d = OVER ) break; printf( %d-getn, d); */ inputpoint(); n.x=-1; n.y=-1; put(&buffer,n); printf(keyboard stopped!n); return NULL;/*-*/void * outp(void * data) /Point d; while (1) if(flag0)flag-;get(&buffer);printf(d=%d,%d flag=%dn,d.x,d.y,flag);if (d.x=-1 & d.y=-1 )break;printf(draw:x=%d,y=%dn,d.x,d.y);drawcircle(d.x,d.y); printf(drawing finished!n); return NULL;/*-*/int main(void) pthread_t th_a, th_b, th_c; void * retval;OVER.x=-1;OVER.y=-1;nn.x=320; nn.y=240; init(&buffer); pthread_create(&th_a, NULL, keyboard, 0); pthread_create(&th_b, NULL, screen, 0);pthread_create(&th_c, NULL, outp, 0); /* Wait until screen and keyboard finish. */ pthread_join(th_a, &retval); pthread_join(th_b, &retval);pthread_join(th_c, &retval); return 0;*说明*Drawcircle(int x, int y) 以(x,y)为中心,画小半径6000,中半径13000,大半径20000的圆环。Cal_DataAvg(int ts_handler, ts_event_t *ts_avg, unsigned short max_num) 从触屏上获取触点坐标(x,y),存入全局变量nn中。 Nn为Point类型。Inputpoint() 在nn坐标的基础上,从键盘输入进行控制*3. 在QT环境下的图形界面应用程序设计。流程图:(简易计算器)CCounter类顶层对话框建立按键通信显示、反馈信号CDigitalButton对按键功能的实现Main.cpp对顶层对话框类的调用程序:CCounter.h/* * 文件名:CCounter.cpp* 类名:CCounter* 功能:计算器* 作者:WNX* 时间:2011年10月17日* 版本:0.01* */#ifndef _CCELLPHONE_H_#define _CCELLPHONE_H_#include / 包含Qt头文件#include #include #include #include #include #include CDigitalButton.h/ 包含自定义头文件#define iWidthDigital50/ 数字按钮宽度#define iHeightDigital50/ 数字按钮高度#define iWidthOther100/ 其它按钮宽度#define iHeightOther40/ 其它按钮高度#define cAppWidth(iWidthDigital*4)/ 总宽度#define cAppHeight(iWidthDigital*4+iHeightOther*2)/ 总高度#define iWidthOn100/On按钮宽度#define iWidthCancel100/ Cancel按钮宽度#define DisLenth 5#define cDigital1/ 没用到#define cErro2#define cCall3class CCounter : public QDialogQ_OBJECT/ Never forget it when using signal&slotpublic:CCounter ( QWidget * parent = 0, const char * name = 0, bool modal = true );/ 重载构造函数,默认模态CCounter();protected:QLCDNumber *m_pLCD;CDigitalButton *m_pDigitalBtn11;QPushButton *m_pOn;QPushButton *m_pCancel;QPushButton *AddButton;QPushButton *SubButton;QPushButton *MulButton;QPushButton *DivButton;QPushButton *EqlButton;QString m_strLCD;int m_stateLCD;protected:void InitConnect(void);/ 初始化Signal/Slot的连接void InitButton(void);/ 初始化各个按钮public slots:/ 定义插槽void ClearLCDNumber();void AddLCDNumber( const QString& str );void DeleteLCDNumber();void Culculate();void IncCounter();void SubCounter();void MulCounter();void DivCounter();signals:/ 定义信号void LCDChanged( const QString& str );private:int counter;int fh; / +1,-2,*3,/4,=5int flag; /0:clear; 1:un-doint ans;#endifCCounter.cpp#include CCounter.hCCounter:CCounter ( QWidget * parent, const char * name, bool modal ):QDia

温馨提示

  • 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
  • 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
  • 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
  • 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
  • 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
  • 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
  • 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

评论

0/150

提交评论