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

📄 gpio-test.c

📁 嵌入式linux 设备驱动程序
💻 C
字号:
#include <stdio.h>
#include <Stdlib.h> // System
#include <fcntl.h>
#include <errno.h>
#include <unistd.h>
#include <linux/delay.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 ) ; //打开设备
	if ( fd < O )
	{
		perror ( “can not open device” ) ;
		exit ( 1 ) ;
	}
	while ( 1 ) {
		printf ( “please Select number to run program \n” ) ;
		printf ( “1 : led on \n 2 : quit\n” ) ;
		scanf ( “ %d”, & val ) ;
		if ( val ==1 )
			//ioctl ( fd , 1 , 10 ) ;
			write(fd,1,1);
		else if ( val ==2 ) {
			close ( fd ) ;
		}
	}
	return 0;
}

⌨️ 快捷键说明

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