- 积分
- 26
贡献40
飞刀6 FD
注册时间2016-7-8
在线时间20 小时
扫一扫,手机访问本帖
|
- #include <stdio.h>
- #include <stdlib.h>
- #include <unistd.h>
- #include "sys/types.h"
- #include "sys/ioctl.h"
- #include "stdlib.h"
- #include "termios.h"
- #include "sys/stat.h"
- #include "fcntl.h"
- #include "sys/time.h"
- #define LED_ON 0
- #define LED_OFF 1
- int main()
- {
- int fd,i,j,k;
- int led_status = 0; //初始状态为熄灭
- fd = open("/dev/leds", O_RDONLY); //打开设备
- if (fd < 0) { // 如果打开设备失败,退出
- perror("open device led failed !");
- exit(1);
- }
- printf("led test show. press ctrl+c to exit \n");
- ioctl(fd,LED_OFF);
- while(1){//主循环
- k++;
- ioctl(fd,LED_ON,0); //点亮
- printf("led0: on \n");
- for(i=0;i<3000;i++)
- for(j=0;j<10000;j++);
- ioctl(fd,LED_OFF,0); //熄灭
- ioctl(fd,LED_ON,1); //点亮
- printf("led1: on \n");
- for(i=0;i<3000;i++)
- for(j=0;j<10000;j++);
- ioctl(fd,LED_OFF,1); //熄灭
- ioctl(fd,LED_ON,2); //点亮
- printf("led2: on \n");
- for(i=0;i<3000;i++)
- for(j=0;j<10000;j++);
- ioctl(fd,LED_OFF,2); //熄灭
- ioctl(fd,LED_ON,3); //点亮
- printf("led3: on \n");
- for(i=0;i<3000;i++)
- for(j=0;j<10000;j++);
- ioctl(fd,LED_OFF,3); //熄灭
- }
- close(fd); //关闭设备
- return 0;
- }
复制代码 |
|