Chinaunix首页 | 论坛 | 博客
  • 博客访问: 608361
  • 博文数量: 149
  • 博客积分: 225
  • 博客等级: 二等列兵
  • 技术积分: 2269
  • 用 户 组: 普通用户
  • 注册时间: 2012-10-28 15:41
个人简介

心到 一切皆到

文章分类

全部博文(149)

文章存档

2014年(7)

2013年(134)

2012年(8)

我的朋友

分类: IT职场

2013-09-01 11:35:51

http://blog.chinaunix.net/uid-26495175-id-3033673.html

XC2440开发板提供了adc的测试程序,内核配置时已经加入了adc的驱动,下面测试一下看看效果

1:通过ftp工具将 adc_test执行文件传到开发板上 var/ftp/pub目录下

2:chmod a+x adc_test 改变文件权限

3:./adc_test 1    说明:./adc_test 是运行程序  1是运行程序的参数,这里表示对adc通道1操作

 

  1. /**************************************************************************
  2.   XC2440 hwmon-adc driver test
  3.   device node is "/sys/class/hwmon/hwmon0/device/adcN_raw" 
  4.   www.xcembed.com 2011.05
  5. ***************************************************************************/
  6. /***************************************************************************
  7.  * *
  8.  * This program is free software; you can redistribute it and/or modify *
  9.  * it under the terms of the GNU General Public License as published by *
  10.  * the Free Software Foundation; either version 2 of the License, or *
  11.  * (at your option) any later version. *
  12.  * *
  13.  ***************************************************************************/

  14. #include <stdio.h>
  15. #include <stdlib.h>
  16. #include <unistd.h>
  17. #include <sys/fcntl.h>

  18. int main(int argc, char *argv[])
  19. {
  20.     int fd = -1, ret;
  21.     int adc_ch, value;
  22.     char buffer[5];
  23.     char dev_name[50];
  24.     
  25.     if ( argc < 2 )
  26.     {
  27.         printf("usage adc_test chanel(0~7)\n");
  28.         exit(1);
  29.     }
  30.     else
  31.     {
  32.         adc_ch = atoi(argv[1]);
  33.     }
  34.     
  35.     if ( (adc_ch >= 0) && (adc_ch <= 7) )
  36.     {
  37.         sprintf(dev_name, "/sys/class/hwmon/hwmon0/device/adc%d_raw\0", adc_ch);
  38.         //printf("dev name %s\n", dev_name);
  39.     
  40.         if ((fd = open(dev_name, O_RDONLY)) < 0)
  41.         {
  42.             perror("open error");
  43.             exit(1);
  44.         }
  45.     }
  46.     else
  47.     {
  48.         printf("adc_ch is (0~7)\n");
  49.         exit(1);
  50.     }
  51.     
  52.     ret = read(fd, buffer, 4);
  53.     if (ret < 0)
  54.     {
  55.         perror("read error");
  56.         exit(1);
  57.     }
  58.     
  59.     value = atoi(buffer);
  60.     printf("ADC %d current value is %d\n", adc_ch, value);
  61.         
  62.     close(fd);
  63.     return 0;
  64. }

 

makefile内容:

CROSS=arm-linux-

all: adc_test

adc_test:adc_test.c
 $(CROSS)gcc -o adc_test adc_test.c
 $(CROSS)strip adc_test
clean:
 @rm -f adc_test *.o *~

阅读(2949) | 评论(0) | 转发(0) |
0

上一篇:UDA1341TS学习笔记

下一篇:linux文件结构

给主人留下些什么吧!~~