⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 adc_test.c

📁 嵌入式linux ADC驱动及测试程序
💻 C
字号:
/*****************************************************************************
;Institue of Automation, Chinese Academy of Sciences
;www.hyesco.com
;Description:	ADC driver on Linux for XKMHK 
;Date:		2006-5-27	
;Author:	
;E_mail:		
*****************************************************************************/

#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;
		
			//输入通道号(0~3):
			location:		
			printf("please input the channel number(0~3): ");
			scanf("%d",&CHA);
			if((CHA < 0)||(CHA > 3))
				{
				printf("Channel number error!\r\n");
				goto location;
				}
		
			//打开设备文件;
			if((fd=open("/dev/adc0",O_WRONLY))==-1)
				{
				perror("open ADC error");
				exit(1);
				}
			
			//获取转换结果,并转换为电压伏数;
			result = write(fd,&CHA,sizeof(unsigned int));
			value = (((float) result)/4095)*5.0;
			printf("Value=%f v\r\n",value);
			
			close(fd);
			return 0;
}

⌨️ 快捷键说明

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