gpio_test.c
来自「gpio嵌入式linuxk开发写入程序」· C语言 代码 · 共 38 行
C
38 行
#include <stdio.h>
#include <stdlib.h>
#include <sys/ioctl.h>
#include <unistd.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <sys/mman.h>
#include "gpio_test.h"
#define DEVICE_PPCFLASH "/dev/gpiotest"
int main()
{
int fd;
int val=-1;
if((fd=open(DEVICE_PPCFLASH,O_RDONLY | 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);
return 0;
}else{
printf("val is %d\n",val);
continue;
}
}
return 0;
}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?