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

📄 gpio_test.c

📁 在嵌入式Linux中编写驱动程序的很好范例
💻 C
字号:
#include <stdio.h>
#include <stdlib.h>	//system
#include <fcntl.h>
#include <errno.h>
#include <unistd.h>
#include <sys/ioctl.h>

#define DEVICE_GPIOTEST "/dev/gpio" 	 //设备节点

int main(int argc,char* argv[])
{
	int fd;
	int val=-1;
	fd=open(DEVICE_GPIOTEST,O_RDONLY);//打开设备
	printf("fd= %d\n",fd);//fd=3
	if ( fd < 0 )
		{
			perror( "can not open device" );
			exit( 1 );
		}
//	printf( "please select number to run program\n" );
//	printf( "1:to run\n2:to close\n" );
//	printf("select:");
	scanf( "%d" , &val );	
//	if(val==1)
		ioctl( fd , val ,8);
//	if(val==2)
//		close( fd );
//	else{
//		printf("val= %d\n",val);
//		printf("input error number!\n");
//	}
	return 0;
}

⌨️ 快捷键说明

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