文档详情

LINUX实验报告 (800字).doc

发布:2017-05-11约1.41万字共23页下载文档
文本预览下载声明
LINUX实验报告 (800字) 本科生实验报告 实验课程 多传感器信息融合技术 学院名称 信息科学与技术学院 专业名称 物联网工程学生姓名 何月明 学生学号 201213060307 指导教师 赖武刚 实验地点 6B607 实验成绩 二〇 14 年 11月二〇 14年12月 题目1.按键控制蜂鸣器增减 一、实验要求。 (1)按键1:启动/停止蜂鸣器。 按键2:增加频率10Hz 按键3:减小频率10Hz按键8:退出程序。 (2)程序初始化完成后,蜂鸣器的默认状态是停止。 二、实验流程图。 三、实验步骤。 首先明白实验的要求,从按键,数据采集去考虑程序的写法。则程序可如下: #include lt;termios.hgt; #include lt;stdio.hgt; #include lt;fcntl.hgt; #include lt;unistd.hgt; #include lt;stdlib.hgt; #include lt;sys/ioctl.hgt; #include lt;sys/types.hgt; #include lt;sys/stat.hgt; #define PWM_IOCTL_SET_FREQ #define PWM_IOCTL_STOP #define ESC_KEY static int getch(void){ struct termios oldt,newt; int ch; if (!isatty(STDIN_FILENO)) { fprintf(stderr, quot;this problem terminal\nquot;); exit(1); should 1 0x1b be run at a } // save terminal setting if(tcgetattr(STDIN_FILENO, amp;oldt) lt; 0) { perror(quot;save the terminal settingquot;); exit(1); } // set terminal as need terminalquot;); exit(1);} newt = oldt; newt.c_lflag amp;= ~( ICANON | ECHO ); if(tcsetattr(STDIN_FILENO,TCSANOW, amp;newt) lt; 0) { perror(quot;set ch = getchar(); open_buzzer(); perror(quot;restore the termial settingquot;); // restore termial setting if(tcsetattr(STDIN_FILENO,TCSANOW,amp;oldt) lt; 0) { return ch; } static int fd = -1; static void close_buzzer(void); static void open_buzzer(void) { fd = open(quot;/dev/pwmquot;, 0); if (fd lt; 0) { pwm_buzzer devicequot;); } // any function exit call will stop the buzzer atexit(close_buzzer); } static void close_buzzer(void) { exit(1);} perror(quot;open exit(1); if (fd gt;= 0) { ioctl(fd, PWM_IOCTL_STOP); 2) lt; 0) { } static void set_buzzer_freq(int freq) { // this IOCTL command is the key to set frequency int ret = ioctl(fd, PWM_IOCTL_SET_FREQ, freq); if(ret lt; 0) { perror(quot
显示全部
相似文档