MCU:MC9S12DG128。从datasheet上查到对SCF标志位的清除是写1,而我在实际用的时候却发现进入中断后写0才能清除标志位,这是怎么回事呢? 程序代码如下: /*采用中断方式查询AD结果,每个通道每次采集8次结果,每次只转换一个通道*/ #include <hidef.h> /* common defines and macros */ #include <mc9s12dg128.h> /* derivative information */ #pragma LINK_INFO DERIVATIVE "mc9s12dg128b" typedef double Voltage; #define Vref 4.73 volatile word res; volatile byte ADf=0; void PLL_Init(void) { /*--------锁相环初始化-------*/ CLKSEL=0x00; //disable pll; CLKSEL_PLLSEL = 0; PLLCTL_PLLON = 0; SYNR = 24; //6M晶镇获得K25M总线 REFDV = 5; PLLCTL = 192; PLLCTL_PLLON = 1; while(!CRGFLG_LOCK); CLKSEL_PLLSEL = 1; } /******************AD模块初始化****************/ void AD_Init() { ATD0CTL2=0x82; //AFFC=0,ASCIE=0,禁止外部触发;0x84,外部下降沿触发 ATD0CTL3=0x40; //S8C:S1C=1000,即每次系列转换8次,FIFO=0,FRZ1:FRZ0=00 ATD0CTL4=0x69; //10位转换,采样周期16clock,ATDclock=BUSCLOCK/20=1.25M;转换时间约为27.2us } /******************ATD采样结果处理*******************/ uint AD_FILTER(void) { uchar i; uint max,min,sum,res[8]; res[0]=ATD0DR0H*4+ATD0DR0L/64; res[1]=ATD0DR1H*4+ATD0DR1L/64; res[2]=ATD0DR2H*4+ATD0DR2L/64; res[3]=ATD0DR3H*4+ATD0DR3L/64; res[4]=ATD0DR4H*4+ATD0DR4L/64; res[5]=ATD0DR5H*4+ATD0DR5L/64; res[6]=ATD0DR6H*4+ATD0DR6L/64; res[7]=ATD0DR7H*4+ATD0DR7L/64; //对结果进行处理,剔除最大最小值后,输出平均值 max=res[0];min=res[0];sum=res[0]; for(i=1;i<8;i++) { sum=sum+res; if(max<res) max=res; if(min>res) min=res; } return((sum-max-min)/6); } void main(void) { /* put your own code here */ Voltage vol; DisableInterrupts; PLL_Init(); //从6M晶振获得25M总线频率 AD_Init(); EnableInterrupts; ATD0CTL5=5; //通道5 for(;;) { if(ADf) { res=AD_FILTER(); vol=Vref*(double)res/1023; ADf=0; } } /* wait forever */ /* please make sure that you never leave this function */ } #pragma CODE_SEG NON_BANKED void interrupt ATD_ISR(void) { ADf=1; ATD0STAT0&=0x7F; //清除SCF标志等价于清除ASCIF } |