|
虽然很简单,但还是得问:ADC采样控制寄存器采样通道的设置
[复制链接]
在ADC的驱动里编写Read_Adc,设置采样通道,pADCIOreg->rADCCON = (1<<14)|(ch<<3)|(19<<6); 不太懂到底是如何移位的,希望高手忍住笑指点一下!
int Read_Adc( volatile ADCreg* pADCIOreg,int ch )
{
RETAILMSG(1, (TEXT("channel:%d\r\n")),ch);
pADCIOreg->rADCCON = (1<<14)|(ch<<3)|(19<<6); // setup channel
//pADCIOreg->rADCCON |= 0<<3; // setup channel
pADCIOreg->rADCCON |= 0x1; // start adc
while(pADCIOreg->rADCCON & 0x1); //check if Enable_start is low
while(!(pADCIOreg->rADCCON & 0x8000)); //check if End of Conversion flag is high
return ( (int)pADCIOreg->rADCDAT0 & 0x3ff ); //return the digital value
}
下面是s2410.h对ADCCON采样控制寄存器的定义
[15]位:转换结束标志(只读)
[14]位:A/D转换器分频使能(1=使能)
[13:6]位:A/D转换器分频值
[5:3]位:模拟通道选择
[2]位:等待模式选择
[1]位:通过读进行采样
[0]位:通过使能使采样开始
#define ADC_BASE 0xB1800000 // 0x58000000
typedef struct {
unsigned int rADCCON;
unsigned int rADCTSC;
unsigned int rADCDLY;
unsigned int rADCDAT0;
unsigned int rADCDAT1;
}ADCreg ;
|
|