首页 | 新闻 | 新品 | 文库 | 方案 | 视频 | 下载 | 商城 | 开发板 | 数据中心 | 座谈新版 | 培训 | 工具 | 博客 | 论坛 | 百科 | GEC | 活动 | 主题月 | 电子展
返回列表 回复 发帖

ARM Linux S3C2440之ADC驱动实现(3)

ARM Linux S3C2440之ADC驱动实现(3)

应用程序adc_test:
[cpp]

  • #include <stdio.h>

  • #include <stdlib.h>

  • #include <unistd.h>

  • #include <sys/ioctl.h>

  • #include <fcntl.h>         


  • int main(void)  
  • {  

  • int fd;  

  • char buf[4];  

  • int i,res,adc_data;  


  • if ((fd = open("/dev/ADC_DEV",O_RDONLY)) < 0) {  
  •             printf("open adc_dev failed\n");  

  • return 1;  
  •     }  
  •    printf("adc_test result:\n");  

  • for (i= 0; i< 5; i++) {  

  • if ((res =read(fd, buf, 4)) != 4) {  
  •             printf("read adc_dev failed \n");  

  • return 1;  
  •         }   

  • else {  
  •             adc_data = buf[0] + (int)(buf[1]<<8);  
  •             printf("adc value = %d (%.2f V) \n",adc_data, adc_data/1024.0*3.3);  
  •         }  
  •     }  
  •     close(fd);  


  • return 0;  
  • }  

测试结果:
[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)
继承事业,薪火相传
返回列表