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

📄 gpio_test.c

📁 嵌入式LINUX的GPIO驱动和测试代码
💻 C
字号:

//测试程序:
#include <stdio.h>
#include <stdlib.h>
#include <sys/ioctl.h>
#include <unistd.h>
#include <sys/mman.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#define DEVICE_GPIOTEST                "/dev/gpiotest"

#define IOWRITE                1;
#define IOCLEAR                2;

int main()
{
        int fd;
        int val=-1;
        
        if( (fd=open(DEVICE_GPIOTEST,O_WRITE | O_NONBLOCK)) < 0 )
        {
                perror("can not open device");
                exit(1);
        }
        
        while(1)
        {
                printf("0:set,1:clear,2:quit;");
                scanf("%d",&val);
                
                if(val==0)
                        ioctl(fd,IOWRITE,0);
                else if(val==1)
                        ioctl(fd,IOCLEAR,0);
                else if(val==2)
                  {
                        close(fd);
                        exit(1);
                }
        }
}

⌨️ 快捷键说明

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