⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 keytest.c~

📁 uclinux底下的按键驱动 本人已经调试通过
💻 C~
字号:
/****************************************Copyright (c)****************************************************                               FREE****--------------File Info-------------------------------------------------------------------------------** File Name: led.c** Last modified Date:  2006-9-9** Last Version: 1.0** Descriptions: User Configurable File****------------------------------------------------------------------------------------------------------** Created By: ZLG CHENMINGJI** Created date:   2006-9-9** Version: 1.0** Descriptions: First version****------------------------------------------------------------------------------------------------------** Modified by:MAMAJINCO** Modified date:2006-9-9** Version:1.0** Descriptions:在此忠心感谢ZLG的模版 我的高质量编程意识起源于此**********************************************************************************************************/#include <stdio.h>#include <stdlib.h>#include <unistd.h>#include <fcntl.h>#include <sys/types.h>#include <sys/stat.h>#define read 0void delay(int delay){	int i;	for(;delay>0;delay--)	{		for(i=0 ; i < 5000 ; i ++);			}}int main(){	int fd1;	unsigned char keytemp=0x0f;        unsigned char count=0;  	fd1= open("/dev/key" , O_RDWR);  //打开设备	if(fd1 == -1)	{		printf ( "open file failed" );		return -1;	}	        printf("open success!\n");          //ioctl(fd1,read,&keytemp);  //读出按键状态  while(count!=10)  {	        ioctl(fd1,read,&keytemp);  //读出按键状态		if((keytemp&0x0f)!=0x0f)	{		keytemp=0x0f;   //清数		delay(100);   //去抖动		ioctl(fd1,read,&keytemp);  //读出按键状态		if((keytemp&0x0f)!=0x0f)		 {		 	 count++;		 	 switch(keytemp&0x0f)                        //确实有键按下		 	 {		 	 	  case 0x0e:		 	 	  	       printf("key0 is down!\n");		 	 	  	       break;		 	 	  case 0x0d:		 	 	  	       printf("key1 is down!\n");		 	 	  	       break;	    		 	 	  case 0x0b:		 	 	  	       printf("key2 is down!\n");		 	 	  	       break;  		 	 	  case 0x07:		 	 	  	       printf("key3 is down!\n");		 	 	  	       break;	        		 	 	}		 }				}	}	close (fd1);	return 0;		}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -