这些小活动你都参加了吗?快来围观一下吧!>>
电子产品世界 » 论坛首页 » DIY与开源设计 » 开源硬件 » 芯灵思Sinlinx A33开发板 Linux中断编程 3--- 应用程序

共1条 1/1 1 跳转至

芯灵思Sinlinx A33开发板 Linux中断编程 3--- 应用程序

助工
2019-02-11 16:45:48     打赏

应用程序代码参考

#include <stdio.h>

#include <stdlib.h>

#include <string.h>

#include <sys/types.h>

#include <sys/stat.h>

#include <fcntl.h>

#include <unistd.h>

#include <sys/ioctl.h>

#include <sys/types.h>

#include <errno.h>    

#define  DEV_NAME    "/dev/mybtn"

int main(int argc, char *args[])

{

    int fd = 0;

    int ret = 0;

    unsigned char recv_buf[1] = {"0"};


    fd = open(DEV_NAME, O_RDONLY);

    //fd = open(DEV_NAME, O_RDONLY|O_NONBLOCK);

    if(fd < 0) {

        perror("open");

    }


    while(1) {

        strcpy(recv_buf, "0000");

        //读取按键数据

        ret = read(fd, recv_buf, 1);

        if((ret < 0) && (errno != EAGAIN)) {

            perror("read");

            exit(-1);

        }


        //输出按键状态

        printf("%s\r\n", recv_buf);

    }


    return 0;

}




共1条 1/1 1 跳转至

回复

匿名不能发帖!请先 [ 登陆 注册 ]