day31.ADC模数转换

第31节:ADC模数转换

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

main(){
        int fd;
        char *adc ="/dev/adc";
        char buffer[512];
        int len = 0,r = 0;

        memset(buffer,0,sizeof(buffer));
        printf("adc ready!\n");

        if((fd = open(adc,O_RDWR|O_NOCTTY|O_NDELAY))<0){
                printf("open %s err\n",adc);
        }
        else{
                printf("open adc success!\n");
                len = read(fd,buffer,10);

                if(len == 0)
                        printf("return null\n");
                else{
                        r = atoi(buffer);
                        r =(int)(r*10000/4095);
                        printf("res value in %d\n",r);
                }
        }
}

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


3、将文件拷贝到TF卡上,并传入开发板上运行结果
[root@iTOP-4412]# mount /dev/mmcblk1p1 /mnt                                                                                                                                           
[root@iTOP-4412]# cd /mnt                                                                                                                                                             
[root@iTOP-4412]# ./adc                                                                                                                                                               
adc ready![ 1486.831707] adc opened
[ 1486.833399] sampling ... 
[ 1486.836011] read 1: 0x8bf
[ 1486.838695] sampling ... 
[ 1486.841206] read 1: 0x8c0
[ 1486.843759] sampling ... 
[ 1486.846405] read 1: 0x8c2
[ 1486.848966] sampling ... 
[ 1486.851612] read 1: 0x8c2
[ 1486.854175] sampling ... 
[ 1486.857073] read 1: 0x8c3
[ 1486.859384] sampling ... 
[ 1486.862042] read 1: 0x8c2
[ 1486.864591] sampling ... 
[ 1486.867237] read 1: 0x8c6
[ 1486.869939] sampling ... 
[ 1486.872452] read 1: 0x8c2
[ 1486.875006] sampling ... 
[ 1486.877653] read 1: 0x8c6
[ 1486.880257] sampling ... 
[ 1486.882814] read 1: 0x8bf
[ 1486.885467] value = 0x8c2
[ 1486.888626] adc closed


open adc success!
res value in 5474
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

打赏作者

随行之旅

python国产化自动化

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

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

打赏作者

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

抵扣说明:

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

余额充值