标题: ATD [打印本页] 作者: fangweidong 时间: 2009-4-29 21:10 标题: ATD #include <hidef.h> /* common defines and macros */
#include <MC9S12XS128.h> /* derivative information */
#pragma LINK_INFO DERIVATIVE "mc9s12xs128"
#pragma CODE_SEG __NEAR_SEG NON_BANKED
void wait() {
int i,j;
for(i=0;i<2000;i++)
for(j=0;j<1335;j++) ;
}
void ADCInit(void)
{ ATD0CTL1=0x00; //7:1-外部触发,65:00-8位精度,4:放电,3210:ch
ATD0CTL2=0x42; //禁止外部触发, 中断允许
ATD0CTL3=0xa0; //右对齐无符号,每次转换4个序列, No FIFO, Freeze模式下继续转
ATD0CTL4=0x01; //765:采样时间为4个AD时钟周期,ATDClock=[BusClock*0.5]/[PRS+1]
ATD0CTL5=0x20; //6:0特殊通道禁止,5:1连续转换 ,4:0单 通道轮流采样
ATD0DIEN=0x00; //禁止数字输入
}
word AD_wData = 0;
void main(void) {
DisableInterrupts;
ADCInit();
DDRB = 0xFF; //数据方向寄存器为输出
PORTB = 0x00;
EnableInterrupts;
for(;;) { }
}
void interrupt 22 Int_AD0(void)
{
DisableInterrupts;
AD_wData = ATD0DR0; //Read out the Result Register
PORTB = (byte)AD_wData;
wait();
EnableInterrupts;
}
这段程序调试通过了,把一模拟量输入到AN00,把电源的负极接到GND,给已下好程序的单片机通电。这样能采集吗 ???是否接线有问题啊 我采集时,PORTB口灯一直亮。没什么现象作者: sehszf 时间: 2009-5-5 17:22
ATD0CTL5_MUTL=0
意思是说单通道的采样
Multi-Channel Sample Mode—When MULT is 0, the ATD sequence controller samples only from the specified
analog input channel for an entire conversion sequence. The analog channel is selected by channel selection
code (control bits CD/CC/CB/CA located in ATDCTL5). When MULT is 1, the ATD sequence controller samples
across channels. The number of channels sampled is determined by the sequence length value (S8C, S4C, S2C,
S1C). The first analog channel examined is determined by channel selection code (CD, CC, CB, CA control bits);
subsequent channels sampled in the sequence are determined by incrementing the channel selection code or
wrapping around to AN0 (channel 0).
0 Sample only one channel
1 Sample across several channels作者: fangweidong 时间: 2009-5-10 08:39
上面哪位答非所问啊 ,哪位高手指教一下啊作者: xiaoyao8745 时间: 2009-5-20 12:38
ATD0CTL4=0x01; //765:采样时间为4个AD时钟周期,ATDClock=[BusClock*0.5]/[PRS+1]