S3C2440关开LED灯

  1. /*************************************

  2. NAME:leds.c
  3. COPYRIGHT:www.embedsky.net

  4. *************************************/

  5. #include stdio.h>
  6. #include stdlib.h>
  7. #include unistd.h>
  8. #include sys/ioctl.h>

  9. int main(int argc, char **argv)
  10. {
  11.         int on;
  12.         int led_no;
  13.         int fd;
  14.         if (argc != 3 || sscanf(argv[1], "%d", &led_no) != 1 || sscanf(argv[2],"%d", &on) != 1 ||
  15.             on 0 || on > 1 || led_no 1 || led_no > 4) {
  16.                 fprintf(stderr, "Usage: leds led_no 0|1\n");
  17.                 exit(1);
  18.         }
  19.         fd = open("/dev/GPIO-Control", 0);
  20.         if (fd 0) {
  21.                 perror("open device leds");
  22.                 exit(1);
  23.         }
  24.         ioctl(fd, on, (led_no-1));
  25.         close(fd);
  26.         return 0;
  27. }
 
2、
用法:
Usage: leds led_no 0|1
[root@EmbedSky /]# ./leds 1 0     //1号灯灭
[root@EmbedSky /]# ./leds 2 0
[root@EmbedSky /]# ./leds 3 0
[root@EmbedSky /]# ./leds 4 0
[root@EmbedSky /]# ./leds 4 1     //4号灯亮

[root@EmbedSky /]# ./leds 3 1
 
 
 
上一篇:在 IBM AIX 7.1 上安装 IBM XL C/C++


下一篇:iOS头部渐变的表格视图设计