注册会员
- 积分
- 177
- 威望
- 219
- 贡献
- 28
- 兑换币
- 0
- 注册时间
- 2010-1-22
- 在线时间
- 0 小时
|
#include <hidef.h> /* common defines and macros */
#include <MC9S12XS128.h> /* derivative information */
#pragma LINK_INFO DERIVATIVE "mc9s12xs128"
void setbusclock(void)
{
CLKSEL=0X00; //disengage PLL to system
PLLCTL_PLLON=1; //turn on PLL
SYNR=0xC5;
REFDV=0x81; //pllclock=2*osc*(1+SYNR)/(1+REFDV)=32MHz;
_asm(nop); //BUS CLOCK=16M ?
_asm(nop);
while(!(CRGFLG_LOCK==1)); //when pll is steady ,then use it;
CLKSEL_PLLSEL =1; //engage PLL to system;
}
void vADInit(void)
{
ATD0CTL1=0b00000000;//8位精度
ATD0CTL2=0b01000000;//禁止外部触发,标志位快速清零,中断禁止
ATD0CTL3=0b10001000;//右对齐无符号.转换序列长度为1,No FIFO模式,Freeze模式下继续转换?
ATD0CTL4=0b00000111;//4AD采样周期,ATDClock=[BusClock*0.5]/[PRS+1] ; PRS=15, divider=32 ?
ATD0CTL5=0b00100000;//特殊通道禁止,单通道采样,扫描模式连续采样,ch AN0
ATD0DIEN=0b00000000;//禁止数字输入
}
unsigned char ReadATD()
{
byte ad=0;
while(!ATD0STAT0_SCF);
ad= ATD0DR0L;
return ad;
}
void main(void) {
setbusclock();
DDRB=0xFF;
PORTB=0x00;
vADInit();
EnableInterrupts;
for(;;){
PORTB=ReadATD(); //在B口显示转换值
}
} |
|