查看: 1809|回复: 0

点亮led

[复制链接]

该用户从未签到

发表于 2017-1-2 13:11:35 | 显示全部楼层 |阅读模式
分享到:
之前在uboot里更改实现了le的点亮,现在编写程序点亮led
下面是程序
/*
* led.c
*
*  Created on: 2014-4-09
*  Author: Vic
*/

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <fcntl.h>
#include <sys/ioctl.h>
#include <linux/types.h>

int main(int argc, char *argv[]){

    int fd;
    char buf;
    fd = open("/sys/class/leds/usr0/brightness",O_WRONLY);
    if(fd<0){
        printf("Can not open led device.");
        return 0;
    }
    while(1){
        buf = '0';        // LED off
        write(fd,&buf,1);
        sleep(1);
        buf = '1';        // LED on
        write(fd,&buf,1);
        sleep(1);
    }
    close(fd);
    return 0;
}
把程序编译arm-none-linux-gnueabi-gcc -o led led.c
生成的可执行文件放到板子上./led
就可以看到led闪烁了


回复

使用道具 举报

您需要登录后才可以回帖 注册/登录

本版积分规则

手机版|小黑屋|与非网

GMT+8, 2024-4-23 16:29 , Processed in 0.101103 second(s), 15 queries , MemCache On.

ICP经营许可证 苏B2-20140176  苏ICP备14012660号-2   苏州灵动帧格网络科技有限公司 版权所有.

苏公网安备 32059002001037号

Powered by Discuz! X3.4

Copyright © 2001-2024, Tencent Cloud.