手机版
你好,游客 登录 注册
背景:
阅读新闻

ARM Linux S3C2440之ADC驱动实现

[日期:2012-02-22] 来源:Linux社区  作者:yyplc [字体:大 中 小]

应用程序adc_test:

[cpp]
  1. #include <stdio.h>   
  2. #include <stdlib.h>   
  3. #include <unistd.h>   
  4. #include <sys/ioctl.h>   
  5. #include <fcntl.h>           
  6.   
  7. int main(void)  
  8. {  
  9.     int fd;  
  10.     char buf[4];  
  11.     int i,res,adc_data;  
  12.   
  13.     if ((fd = open("/dev/ADC_DEV",O_RDONLY)) < 0) {  
  14.             printf("open adc_dev failed\n");  
  15.         return 1;  
  16.     }  
  17.    printf("adc_test result:\n");  
  18.     for (i= 0; i< 5; i++) {  
  19.         if ((res =read(fd, buf, 4)) != 4) {  
  20.             printf("read adc_dev failed \n");  
  21.             return 1;  
  22.         }   
  23.         else {  
  24.             adc_data = buf[0] + (int)(buf[1]<<8);  
  25.             printf("adc value = %d (%.2f V) \n",adc_data, adc_data/1024.0*3.3);  
  26.         }  
  27.     }  
  28.     close(fd);  
  29.   
  30.     return 0;  
  31. }  

测试结果:

[root@www.linuxidc.com /]# ./adc_test 
adc_test result:
adc value = 740 (2.38 V) 
adc value = 744 (2.40 V) 
adc value = 744 (2.40 V) 
adc value = 744 (2.40 V)

linux
相关资讯       arm  S3C2440 
本文评论   查看全部评论 (0)
表情: 表情 姓名: 字数

       

评论声明
  • 尊重网上道德,遵守中华人民共和国的各项有关法律法规
  • 承担一切因您的行为而直接或间接导致的民事或刑事法律责任
  • 本站管理人员有权保留或删除其管辖留言中的任意内容
  • 本站有权在网站内转载或引用您的评论
  • 参与本评论即表明您已经阅读并接受上述条款