ads7842_test.c

来自「对应之前上传的ads的测试程序」· C语言 代码 · 共 43 行

C
43
字号
/*****************************************************************************
;Institue of Automation, Chinese Academy of Sciences
;www.hyesco.com
;Description:   ADC driver on Linux for H9200F 
;Date:          2006-7-10	
;Author:	
;E_mail:        Lijg@hyesco.com		
*****************************************************************************/
#include <stdio.h>
#include <string.h>
#include <malloc.h>
#include <stdio.h>
#include <sys/types.h>
#include <unistd.h>
#include <sys/stat.h>
#include <fcntl.h>

static int fd=-1;

int main()
{
  float value;
  unsigned int result,CHA;
		
		
  //打开设备文件;
  if((fd=open("/dev/ADS7842",O_WRONLY))==-1)
    {
    perror("open ADC error");
    exit(1);
    }
			
  //获取转换结果,并转换为电压伏数;
  for(CHA=0;CHA<=15;CHA++)
    {
    result = write(fd,&CHA,sizeof(unsigned int));
    value = (((float) result)/4096)*10.0;
    printf("CH %d = %f v\r\n",CHA,value);
    }	
  close(fd);
  return 0;
}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?