The AD part code example is shortted as blow:
#include <hidef.h> /* common defines and macros */
#include "derivative.h" /* derivative-specific definitions */
void AutoEle_InitPLL (void)
{
CLKSEL &= ~(0x80); //Select OSCCLK as MCU clock
REFDV = 0xC0; //FREF = Fosc / (REFDIV +1), FEFFRQ=11, REFDIV=0
SYNR = 0xC2; //FVCO = 2 * Fref * (SYNR + 1)
POSTDIV = 0; //FPLL = FVCO / (2 * POSTDIV)
while (!CRGFLG_LOCK) ; // Wait unitl PLL locked
CLKSEL |= 0x80; //Select PLLCLK as MCU clock
}
void AutoEle_EP100_ADInit(void)
{
/* AD0 AN0-AN15 */
ATD0CTL0 = 15; //回环通道
ATD0CTL1 = 0x2F; //外部触发源,10位分辨率
ATD0CTL2 = 0x40; //CCF位快速清除,及中断使能配置
ATD0CTL3 = 0x80 | (0 << 3); //右对齐,转换序列长度为3,非FIFO模式
ATD0CTL4 = 0x57; //采样时间8AD时钟周期,总线时钟分频 Fad= Fbus/(2*(Prs[4~0] + 1)) 1M ,
ATD0CMPE = 0x0; //比较功能关闭 2bytes
ATD0DIEN = 0x0; //Disable digital input buffer to ANx pin 2bytes
ATD0CTL5 = 0x10;
/* AD1 AN16-AN23 */
ATD1CTL0 = 7; //回环通道
ATD1CTL1 = 0x2F; //外部触发源,10位分辨率
ATD1CTL2 = 0x40;
ATD1CTL3 = 0x80 | (8 << 3); //右对齐,转换序列长度为3,非FIFO模式
ATD1CTL4 = 0x57; //采样时间8AD时钟周期,总线时钟分频 Fad= Fbus/(2*(Prs[4~0] + 1)) 1M ,
ATD1CMPE = 0x0; //比较功能关闭 2bytes
ATD1DIEN = 0x18; //Disable digital input buffer to ANx pin 2bytes
ATD1CTL5 = 0x10;
}
void main(void)
{
/* put your own code here */
AutoEle_EP100_ADInit();
AutoEle_EP100_ADInit();
EnableInterrupts;
for(;;)
{
if ((ATD0STAT0_SCF == 0) || (ATD1STAT0_SCF == 0))
{
}
else
{
ATD0CTL5 = 0x10; //启动转换
ATD1CTL5 = 0x10; //启动转换
}
_FEED_COP(); /* feeds the dog */
} /* loop forever */
/* please make sure that you never leave main */
} !