【飞凌OKA40i-C开发板试用体验】流水灯

描述

本文来源电子发烧友社区,作者:刘建华, 帖子地址:https://bbs.elecfans.com/jishu_2305990_1_1.html


【目的】熟悉LED灯的驱动
从手册上查到驱动LED的说明:
飞凌

应该是向文件/sys/class/gpio/export写入IO的编号,然后往sys/class/gpioXX/value里面写1或者0来控制LED的亮与灭。
1、在虚拟机work目录下面新建LED文件夹,下面新建led.c文件:

#include 
#include 
#include 
#include 
#include 

int main(int argc ,char *argv[])
{
    FILE *fp=NULL;
    int i=0;
    fp = fopen("/sys/class/gpio/export","w");
    fprintf(fp,"%d",271);
    fclose(fp);
    fp = fopen("/sys/class/gpio/export","w");
    fprintf(fp,"%d",250);
    fclose(fp);
    fp = fopen("/sys/class/gpio/gpio271/direction","w");
    fprintf(fp,"out");
    fclose(fp);
    fp = fopen("/sys/class/gpio/gpio250/direction","w");
    fprintf(fp,"out");
    fclose(fp);
    fp = fopen("/sys/class/gpio/gpio43/direction","w");
    fprintf(fp,"out");
    fclose(fp);
    for(i=0;i<100;i++)
    {
        fp = fopen("/sys/class/gpio/gpio250/value","w");
        fprintf(fp,"%d",1);
        sleep(1);
        fclose(fp);
        fp = fopen("/sys/class/gpio/gpio250/value","w");
        fprintf(fp,"%d",0);
        sleep(1);
        fclose(fp);
        fp = fopen("/sys/class/gpio/gpio271/value","w");
        fprintf(fp,"%d",1);
        sleep(1);
        fclose(fp);
        fp = fopen("/sys/class/gpio/gpio271/value","w");
        fprintf(fp,"%d",0);
        sleep(1);
        fclose(fp);

    }
    fp = fopen("/sys/class/gpio/gpio271/unexport","w");
    fprintf(fp, "%d",271);
    fclose(fp);
    return 0;

}
2、编写makefile

TARGET =LED
DEST_DIR ?=_install
#CC ?=arm-linux-gcc
CC =arm-linux-gnueabihf-gcc-5.3.1
build:
@(CC) -o (TARGET) led.c

hold:
[url=home.php?mod=space&uid=70594]@echo[/url] "LED hold[skip]"

install:
[url=home.php?mod=space&uid=2293869]@MKDIR[/url] -p $(DEST_DIR)
@cp (TARGET) (DEST_DIR)

uninstall:
@rm -fr (DEST_DIR)/(TARGET)

distclean: uninstall
@rm -fr $(TARGET)
@rm -fr _install

编译好后上传开发板,运行,LED5、LED6交替闪烁。


【流水灯体验视频,详见作者原帖子文章】

 
打开APP阅读更多精彩内容
声明:本文内容及配图由入驻作者撰写或者入驻合作网站授权转载。文章观点仅代表作者本人,不代表电子发烧友网立场。文章及其配图仅供工程师学习之用,如有内容侵权或者其他违规问题,请联系本站处理。 举报投诉

全部0条评论

快来发表一下你的评论吧 !

×
20
完善资料,
赚取积分