Embedded 读取PIC上的2个模拟引脚
我有一些代码来设置和读取PIC16F690 PIC微控制器上的模拟输入 //设置 TRISA=0x01;数据方向寄存器-将端口位0设置为输入ie RA0 ANSEL=0x01;将该引脚设置为模拟 ADCON1=0x50Embedded 读取PIC上的2个模拟引脚,embedded,pic,Embedded,Pic,我有一些代码来设置和读取PIC16F690 PIC微控制器上的模拟输入 //设置 TRISA=0x01;数据方向寄存器-将端口位0设置为输入ie RA0 ANSEL=0x01;将该引脚设置为模拟 ADCON1=0x50 ADCON0=0x81 while (1){ unsigned char val = GETVALUE(); wait(); } unsigned char GETVALUE(void){ unsigned short nRet; ADCON0 |= 0x02;
ADCON0=0x81
while (1){
unsigned char val = GETVALUE();
wait();
}
unsigned char GETVALUE(void){
unsigned short nRet;
ADCON0 |= 0x02; // Start conversion
while(ADCON0 & 0x02) // wait for conversion
{
}
nRet = ADRESH;
nRet <<=8;
nRet += ADRESL;
return (nRet & 0x3FF);
}
while(1){
unsigned char val=GETVALUE();
等待();
}
无符号字符GETVALUE(void){
无符号短nRet;
ADCON0 |=0x02;//开始转换
while(ADCON0&0x02)//等待转换
{
}
nRet=ADRESH;
nRet在ADCON0
(位:CHS0..CHS3)寄存器中将ADC mux值从0更改为1,等待一段时间(一些us填充ADC采样电容器)然后再次调用GETVALUE
函数。谢谢-这很有意义。知道交换管脚之间的最小等待时间是多少吗?@user2633388:查看数据表:部分:9-1:采集时间示例,如何计算。