test-adc.c

来自「基于s3c2410芯片的ADC驱动程序源代码」· C语言 代码 · 共 45 行

C
45
字号
/*********************************************************************
* File:		test-adc.c
* Author:	
* Desc:		ADC channel conversion test example.
* History:		
*	
*********************************************************************/

#include <unistd.h>
#include <stdio.h>
#include <stdlib.h>
#include <getopt.h>
#include <fcntl.h>
#include "test-adc.h"


int main(int argc, char** argv)
{
	int i=2, ch, usConData,usEndData, fd;
	char *pAINx="2";
	static char *driver = "/dev/misc/adc";
	
	printf(" ADC Read Example base on Linux.\n");
	/* open device */
	fd = open(driver, O_RDWR);
	if(fd < 0)
	{
		printf("device open fail\n");
		return -1;
	}
	//printf(" Loop Read %d-times to convert.\n",i);
	printf(" Infinite Reading from AIN%s (^C to exit).\n",pAINx);
	printf(" Press ^C to exit.\n");
	while(1)//i--)
	{
		read(fd, &usConData, 1);             printf("%d\n",usConData);
		printf(" %0.4f \n",usConData*3.3/0x3ff);
		sleep(1);
	}

	printf(" end.\n");
	return 0;
}

⌨️ 快捷键说明

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