adc8_test.c

来自「为优龙公司的2410开发板写的一个的AD采样驱动程序」· C语言 代码 · 共 52 行

C
52
字号
#include<stdio.h>#include<stdlib.h>#include<fcntl.h>#include<errno.h>#include<unistd.h>#include<linux/delay.h>#include<sys/ioctl.h>#define DEVICE_ADC8TEST "/dev/adc8"int main(int argc,char *argv[]){	int j=0;	int fd;	unsigned char buf[2];	typedef union {                unsigned int inv;                struct {                        unsigned char xmsb;                        unsigned char xlsb;                }ch;        }xunion;        xunion readbuf;        unsigned int invb=0;	fd=open(DEVICE_ADC8TEST,O_RDONLY);	if(fd<0)	{		perror("can not open device adc8");		exit(1);	}	ioctl(fd,0,2500000);	//adc_frequency=2.5MHz	printf("enter adc channel number(0-7,9=exit): ");	scanf("%d",&j);printf("j=%x\n",j);                                                                           	while(j!=9)	{		ioctl(fd,1,j);		read(fd,buf,2);		readbuf.ch.xlsb=buf[0];		readbuf.ch.xmsb=buf[1];		readbuf.inv&=0x3ff;		if(readbuf.inv!=invb)		{			printf("adc[%x]=%x\n",j,readbuf.inv);			invb=readbuf.inv;		}		printf("enter adc channel number(0-7,9=exit): ");		scanf("%d",&j);printf("j=%x\n",j);	}	close(fd);	return 0;}

⌨️ 快捷键说明

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