文章目录

模数转换需要read读函数

滑动变阻器2,往3方向拨动,XadcAIN0最多能读到1.8V,往1方向拨动则最多可以读到0V

AD_datasheet_4412

模拟输入电压 0-1.8VAnalog Input Range:0 to 1.8V

寄存器dsatasheet

AD寄存器AD DAT最大为0XFFF,最小为0

电阻最大为10K,最下为0

示例程序

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
#include <stdio.h>
#include <stdlib.h>
#include <fcntl.h>
#include <errno.h>
#include <unistd.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <string.h>
#include <stdint.h>
#include <termios.h>
//#include <android/log.h>
//#include <sys/ioctl.h>

int main(void){
int fd;
char *adc = "/dev/adc";
char buffer[512];
int len=0, r=0;

memset(buffer,0,sizeof(buffer)); //将s所指向的某一块内存中的每个字节的内容全部设置为ch指定的ASCII值,块的大小由第三个参数指定,这个函数通常为新申请的内存做初始化工作
printf("adc ready!\n");

if((fd = open(adc, O_RDWR|O_NOCTTY|O_NDELAY))<0)
printf("open adc err!\n");
else{
printf("open adc success!\n");

len=read(fd,buffer,10);

if(len == 0)
printf("return null\n");
else{
r = atoi(buffer);
r = (int)(r*10000/4095); //Datas transition to Res 注意OXFFF对应的数值10000
printf("res value is %d\n",r);
}
}
}
文章目录