gpiotest.c

来自「led control 在s3c2410 同时还有key board」· C语言 代码 · 共 30 行

C
30
字号
#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<0) 
 { 
  perror("can not open device"); 
  exit(1); 
 } 
  while(1){ 
  printf("please select number to run program\n"); 
  printf("1:led on \n2:quit "); 
  scanf("%d",&val);  
  if(val==1) 
   ioctl(fd,1,10); 
  else if(val==2){ 
   close(fd); 
  } 
 } 
  return 0; 
} 

⌨️ 快捷键说明

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