程序如下 应如何修改
#include <hidef.h> /* common defines and macros */
#include <MC9S12XS128.h> /* derivative information */
#pragma LINK_INFO DERIVATIVE "mc9s12xs128"
unsigned int value1,out;
void SetBusCLK_40M(void)
{
CLKSEL=0X00; //初始化PLL前先使用外部晶振
PLLCTL_PLLON=1; //开启 PLL
SYNR =0xc0 | 0x04;
REFDV=0xc0 | 0x01;
POSTDIV=0x00; //pllclock=2*osc*(1+SYNR)/(1+REFDV)=80MHz;
_asm(nop); //BUS CLOCK=40M
_asm(nop);
while(!(CRG标志寄存器_LOCK==1)); //等待 pll稳定 ;
CLKSEL_PLLSEL =1; //fBUS采用 PLL to 频率设定;
}
void Atd_Init(void)
{
ATD0CTL0=0x00;
ATD0CTL1=0x18; //8位精度,
ATD0CTL2=0X40; //快速清除标志位,禁止外部触发,不使能中断
ATD0CTL3=0X88; //右对齐方式 每次转换1个序列, No FIFO, Freeze模式下继续转
ATD0CTL4=0X07; //采样时间为4个AD时钟周期
ATD0CTL5=0X20; // 单通道转换 转换通道0
ATD0DIEN=0x00; //禁止数字输入
}
void AD_capture(void)
{
ATD0CTL5 = 0x00; //转换AD00
while(!ATD0STAT2_CCF0);
value1 = ATD0DR0L;
}
void delay(void)
{
unsigned int i;
for(i=0;i<5000;i++);
}
void main(void) {
/* put your own code here */
SetBusCLK_40M();
// EnableInterrupts;
Atd_Init();
for(;;) {
AD_capture();
delay();
out=value1;
} /* loop forever */
/* please make sure that you never leave main */
}
|