day29.led 灯

第29节:led 灯

1、编写运行编译例程:
root@ubuntu:/home/linuxsystemcode/led# cat led.c
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <stdio.h>
#include <unistd.h>
#include <string.h>
#include <stdlib.h>

#define LED_NUM 2
#define LED_C 2

//cmd is zero(off),cmd is one(on)
//io is zero Near peak ringing device,io is one Close to independent keystroke lamp
int main(int argc,char *argv[]){
        int fd,led_num,led_c;

        char *leds ="/dev/leds";

        led_num = LED_NUM;
        led_c = LED_C;
        printf("argv1 is cmd;argv2 is io\n");
        if(atoi(argv[1])>led_c){
                printf("argv1 is 0 or 1\n");
                exit(1);
        }
        if(atoi(argv[1])>led_num){
                printf("argv2 is 0 or 1\n");
                exit(1);
        }
        if((fd = open(leds,O_RDWR|O_NOCTTY|O_NDELAY))<0){
                printf("open %s failed\n",leds);
        }
        else{
                ioctl(fd,atoi(argv[1],atoi(argv[2])));
                printf("iocti %s success\n",leds);
        }
        close(fd);
        return 0;
}


2、进行文件编译
root@ubuntu:/home/linuxsystemcode/led# arm-none-linux-gnueabi-gcc -o led led.c -static
root@ubuntu:/home/linuxsystemcode/led# ls
led  led.c


3、将文件拷贝到TF卡上,并传入开发板上运行结果
Please press Enter to activate this console. 


[root@iTOP-4412]# mount /dev/mmcblk1p1 /mnt                                                                        
[root@iTOP-4412]# cd /mnt
[root@iTOP-4412]# ls
System Volume Information  creat.c                    read
argvc                      led                        read.c
argvc.c                    led.c                      write
creat                      open                       write.c

[root@iTOP-4412]# ./led
argv1 is cmd;argv2 is io

4、 0为灭
[root@iTOP-4412]# ./led 0 0
argv1 is cmd;argv[  409.659981] LEDS_CTL DEBUG:Device Opened Success!
[  409.664876] debug: leds_ioctl cmd is 0
[  409.668605] LEDS_CTL DEBUG:Device Closed Success!
2 is io

iocti /dev/leds success


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

随行之旅

python国产化自动化

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值