您好,欢迎来到小侦探旅游网。
搜索
您的当前位置:首页基于Mini2440的四路抢答器的设计

基于Mini2440的四路抢答器的设计

来源:小侦探旅游网
/**************************************** 嵌入式原理课程设计

基于Mini2440的四路抢答器的设计 主程序设计:main.c

******************************************/

#include #include #include #include #include #include #include #include #include #include

/*main函数*/ int main(void) {

int buttons_fd;/*按键设备描述符*/

int led_fd; int flag=1;

/*Led设备描述符*/ /*标志*/

char buttons[6] = {'0', '0', '0', '0', '0', '0'};

led_fd = open(\"/dev/leds0\

if(led_fd < 0){led_fd = open(\"/dev/leds\if(led_fd < 0) {

perror(\"open device leds\"); exit(1); }

ioctl(led_fd, 0,0); ioctl(led_fd, 0,1); ioctl(led_fd, 0,2);

ioctl(led_fd, 0,3);/*打开LED设备驱动,先关掉四个LED*/

buttons_fd = open(\"/dev/buttons\打开按键设备驱动*/ if (buttons_fd < 0) { }

perror(\"open device buttons\"); exit(1);

for(;;) {

char current_buttons[6]; int count_of_changed_key; int i,j; while(flag) {

if(read(buttons_fd,current_buttons,sizeof

current_buttons)!=sizeof current_buttons)/*读入按键状况*/ */ {

if (buttons[i] != current_buttons[i]) {

printf(\"condidate %d stroke!\显示哪位

for (i = 0, count_of_changed_key = 0; i < 4; i++)/*扫描按键 { }

perror(\"read buttons:\"); exit(1);

选手最先抢到*/

} }

ioctl(led_fd, 1,i);/*点亮该选手对应的灯*/ }

count_of_changed_key++; flag=0;

if (count_of_changed_key) /*换行*/ { }

printf(\"\\n\");

if (read(buttons_fd, current_buttons, sizeof current_buttons) != sizeof current_buttons)/*重新读入按键,判断复位*/ */ {

ioctl(led_fd, 0,0); ioctl(led_fd, 0,1);

{ }

perror(\"read buttons:\"); exit(1);

if(current_buttons[5]!=buttons[5])/*复位,将四个LED灯熄灭

}

}

ioctl(led_fd, 0,2); ioctl(led_fd, 0,3); flag=1;

}

close(buttons_fd);/*关闭设备*/ close(led_fd); return 0;

因篇幅问题不能全部显示,请点此查看更多更全内容

Copyright © 2019- xiaozhentang.com 版权所有 湘ICP备2023022495号-4

违法及侵权请联系:TEL:199 1889 7713 E-MAIL:2724546146@qq.com

本站由北京市万商天勤律师事务所王兴未律师提供法律服务