程序如下,通道6上测得电压为2.2V左右,但是结果寄存器上却显示0XFF,请问是怎么回事呢? #include <hidef.h> /* common defines and macros */ #include <mc9s12dg128.h> /* derivative information */ #include "IO.h" #include "delay.h" #pragma LINK_INFO DERIVATIVE "mc9s12dg128b" #define ATDCTL2_VAL 0xC0 //控制寄存器2:AD模块上电, 快速清零, 无等待模式, 禁止外部触发, 中断禁止 #define ATDCTL3_VAL 0x00 //控制寄存器3:每个序列8次转换, No FIFO, Freeze模式下继续转换 #define ATDCTL4_VAL 0x83 //控制寄存器4:8位转换,采样时间为2个A/D时钟周期,ATDClock=[BusClock*0.5]/[PRS+1]=8*0.5/4=1Mhz; PRS=3, divider=8 #define ATD0CTL5_VAL 0xB0//控制寄存器5:右对齐,无符号,多通道采样,首通道0 /*A/D模块初始化子程序*/ /*初始化A/D模块的控制寄存器*/ void AD_init(void) { ATD0CTL2=ATDCTL2_VAL; ATD0CTL3=ATDCTL3_VAL; ATD0CTL4=ATDCTL4_VAL; ATD0CTL5=ATD0CTL5_VAL; ATD0DIEN=0x00; // 禁止数字输入 }
void main(void) { /* put your own code here */ DisableInterrupts; AD_init(); EnableInterrupts; while(!ATD0STAT1_CCF6); { ADX_DATA=ATD0DR6;//AD转换完成后,读转换结果寄存器的值 } for(;;); /* wait forever */ /* please make sure that you never leave this function */ } |