#include "AT91SAM7S256.h"
#include "Board.h"
volatile unsigned int EXT_AD_Val[4];
int main(void)
{
unsigned char i;
*AT91C_ADC_CR = AT91C_CKGR_MOSCEN; //ADC的软件复位,即清除ADC的所有寄存器
*AT91C_PMC_PCER = 1 << AT91C_ID_ADC; //使能ADC时钟
*AT91C_PIOA_PDR = EXT_AD0 | EXT_AD1; //禁止该两个管脚的I/O口功能,使作为模拟输入功能
*AT91C_ADC_MR = 0x0f1f3f00; //软件起动,10位分辨率,128分频
*AT91C_ADC_CHER = 0x33; //使能通道0,1,4,5
*AT91C_ADC_CHDR = 0xcc; //禁能通道2,3,6,7
*AT91C_ADC_IDR = 0xfffff; //禁止所有中断
while (1)
{
*AT91C_ADC_CR = 0x2; //起动转换
while(1)
{
if ((*AT91C_ADC_SR) & 0x33)
{
EXT_AD_Val[0] = (*AT91C_ADC_CDR0) & 0x3ff;
EXT_AD_Val[1] = (*AT91C_ADC_CDR1) & 0x3ff;吧
EXT_AD_Val[2] = (*AT91C_ADC_CDR4) & 0x3ff;
EXT_AD_Val[3] = (*AT91C_ADC_CDR5) & 0x3ff;
for (i = 0; i < 4; i++)
{
EXT_AD_Val = (EXT_AD_Val * 3300) / 1023;
}
break;
}
}
}
}
文章评论(0条评论)
登录后参与讨论