查看: 1694|回复: 0

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

[复制链接]
  • TA的每日心情
    奋斗
    2016-4-14 10:16
  • 签到天数: 9 天

    连续签到: 1 天

    [LV.3]偶尔看看II

    发表于 2019-2-11 16:45:33 | 显示全部楼层 |阅读模式
    分享到:
    应用程序代码参考
    #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;
    }

    回复

    使用道具 举报

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

    本版积分规则

    关闭

    站长推荐上一条 /2 下一条

    手机版|小黑屋|与非网

    GMT+8, 2024-4-26 04:23 , Processed in 0.106961 second(s), 15 queries , MemCache On.

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

    苏公网安备 32059002001037号

    Powered by Discuz! X3.4

    Copyright © 2001-2024, Tencent Cloud.