其他分享
首页 > 其他分享> > MC9S12XEP100-ATD设置

MC9S12XEP100-ATD设置

作者:互联网

MC9S12XEP100 ATD配置

8位单通道转换

初始化

void INIT_AD(void) 
{
 ATD0CTL2 = 0x40;  //启动A/D模块,快速清零,禁止中断
 ATD0CTL1_SRES=0;  //选用8位模数转换
 ATD0CTL3 = 0x88;   //每次只转换一个通道
 ATD0CTL4 = 0x00;   //AD模块时钟频率为8MHz
}

启动AD转换

unsigned char AD_capture(unsigned char chanel) 
{
 	unsigned char ADcap;
 	switch(chanel)
 	{ 
 	 case 0:
  		ATD0CTL5 = 0x00;//转换AD00
  		while(!ATD0STAT0_SCF);
  		ADcap = ATD0DR0L;
  		break;

  	 case 1:
  		ATD0CTL5 = 0x01;//转换AD01
  		while(!ATD0STAT0_SCF);
  		ADcap = ATD0DR0L;
  		break;
  
   case 2:
  		ATD0CTL5 = 0x02;//转换AD02
  		while(!ATD0STAT0_SCF);
  		ADcap = ATD0DR0L;
  		break;
 
   case 3:
  		ATD0CTL5 = 0x03;//转换AD03
  		while(!ATD0STAT0_SCF);
  		ADcap = ATD0DR0L;
  		break;

   case 4:
  		ATD0CTL5 = 0x04;//转换AD04
  		while(!ATD0STAT0_SCF);
  		ADcap = ATD0DR0L;
  		break;

   case 5:
		ATD0CTL5 = 0x05;//转换AD05
		while(!ATD0STAT0_SCF);
		ADcap = ATD0DR0L;
		break;

   case 6:
		ATD0CTL5 = 0x06;//转换AD06
		while(!ATD0STAT0_SCF);
		ADcap = ATD0DR0L;
		break;

   case 7:
		ATD0CTL5 = 0x07;//转换AD07
		while(!ATD0STAT0_SCF);
		ADcap = ATD0DR0L;
		break;

   case 8:
		ATD0CTL5 = 0x08;//转换AD08
		while(!ATD0STAT0_SCF);
		ADcap = ATD0DR0L;
		break;

   case 9:
		ATD0CTL5 = 0x09;//转换AD09
		while(!ATD0STAT0_SCF);
		ADcap = ATD0DR0L;
		break;

   case 10:
		ATD0CTL5 = 0x0a;//转换AD10
		while(!ATD0STAT0_SCF);
		ADcap = ATD0DR0L;
		break;

   case 11:
 		ATD0CTL5 = 0x0b;//转换AD11
		while(!ATD0STAT0_SCF);
		ADcap = ATD0DR0L;
		break;

   case 12:
		ATD0CTL5 = 0x0c;//转换AD12
		while(!ATD0STAT0_SCF);
		ADcap = ATD0DR0L;
		break;

   case 13:
		ATD0CTL5 = 0x0d;//转换AD13
		while(!ATD0STAT0_SCF);
		ADcap = ATD0DR0L;
		break;

   case 14:
		ATD0CTL5 = 0x0e;//转换AD14
		while(!ATD0STAT0_SCF);
		ADcap = ATD0DR0L;
		break;

   case 15:
		ATD0CTL5 = 0x0f;//转换AD15
		while(!ATD0STAT0_SCF);
		ADcap = ATD0DR0L;
		break;
  
 	}
   return(AD_data);
}

8位多通道

void INIT_AD(void) 
{
	ATD0CTL2 = 0x40;  //启动A/D转换,快速清零,禁止中断
	ATD0CTL1_SRES=0;  //选用8位模数转换
    ATD0CTL3 = 0xa8;   //每次转换5个通道,右对齐模式
	ATD0CTL4 = 0x00;   //AD模块时钟频率为8MHz
}

void AD_capture(void) 
{
	ATD0CTL5 = 0x31;  //转换AD01和AD05
	while(!ATD0STAT0_SCF);
	AD1=ATD0DR0L;
	AD2=ATD0DR1L;
	AD3=ATD0DR2L;
	AD4=ATD0DR3L;
	AD5=ATD0DR4L;  
}

10位单通道

void INIT_AD(void) 
{
 ATD0CTL2 = 0x40;  //启动A/D模块,快速清零,禁止中断
 ATD0CTL1_SRES=1;  //选用10位模数转换
 ATD0CTL3 = 0x88;   //每次只转换一个通道
 ATD0CTL4 = 0x00;   //AD模块时钟频率为8MHz
}

启动AD转换

unsigned char AD_capture(unsigned char chanel) 
{
 	unsigned char ADcap;
 	switch(chanel)
 	{ 
 	 case 0:
  		ATD0CTL5 = 0x00;//转换AD00
  		while(!ATD0STAT0_SCF);
  		ADcap = ATD0DR0L;
  		break;

  	 case 1:
  		ATD0CTL5 = 0x01;//转换AD01
  		while(!ATD0STAT0_SCF);
  		ADcap = ATD0DR0L;
  		break;
  
   case 2:
  		ATD0CTL5 = 0x02;//转换AD02
  		while(!ATD0STAT0_SCF);
  		ADcap = ATD0DR0L;
  		break;
 
   case 3:
  		ATD0CTL5 = 0x03;//转换AD03
  		while(!ATD0STAT0_SCF);
  		ADcap = ATD0DR0L;
  		break;

   case 4:
  		ATD0CTL5 = 0x04;//转换AD04
  		while(!ATD0STAT0_SCF);
  		ADcap = ATD0DR0L;
  		break;

   case 5:
		ATD0CTL5 = 0x05;//转换AD05
		while(!ATD0STAT0_SCF);
		ADcap = ATD0DR0L;
		break;

   case 6:
		ATD0CTL5 = 0x06;//转换AD06
		while(!ATD0STAT0_SCF);
		ADcap = ATD0DR0L;
		break;

   case 7:
		ATD0CTL5 = 0x07;//转换AD07
		while(!ATD0STAT0_SCF);
		ADcap = ATD0DR0L;
		break;

   case 8:
		ATD0CTL5 = 0x08;//转换AD08
		while(!ATD0STAT0_SCF);
		ADcap = ATD0DR0L;
		break;

   case 9:
		ATD0CTL5 = 0x09;//转换AD09
		while(!ATD0STAT0_SCF);
		ADcap = ATD0DR0L;
		break;

   case 10:
		ATD0CTL5 = 0x0a;//转换AD10
		while(!ATD0STAT0_SCF);
		ADcap = ATD0DR0L;
		break;

   case 11:
 		ATD0CTL5 = 0x0b;//转换AD11
		while(!ATD0STAT0_SCF);
		ADcap = ATD0DR0L;
		break;

   case 12:
		ATD0CTL5 = 0x0c;//转换AD12
		while(!ATD0STAT0_SCF);
		ADcap = ATD0DR0L;
		break;

   case 13:
		ATD0CTL5 = 0x0d;//转换AD13
		while(!ATD0STAT0_SCF);
		ADcap = ATD0DR0L;
		break;

   case 14:
		ATD0CTL5 = 0x0e;//转换AD14
		while(!ATD0STAT0_SCF);
		ADcap = ATD0DR0L;
		break;

   case 15:
		ATD0CTL5 = 0x0f;//转换AD15
		while(!ATD0STAT0_SCF);
		ADcap = ATD0DR0L;
		break;
  
 	}
   return(AD_data);
}

10位多通道

void INIT_AD(void) 
{
	ATD0CTL2 = 0x40;  //启动A/D转换,快速清零,禁止中断
	ATD0CTL1_SRES=1;  //选用10位模数转换
	ATD0CTL3 = 0xa8;   //每次转换5个通道,右对齐模式
	ATD0CTL4 = 0x00;   //AD模块时钟频率为8MHz
}


void AD_capture(void) 
{
	ATD0CTL5 = 0x31;  //转换AD01和AD05
	while(!ATD0STAT0_SCF);
	AD1=ATD0DR0;
	AD2=ATD0DR1;
	AD3=ATD0DR2;
	AD4=ATD0DR3;
	AD5=ATD0DR4;  
}

12位单通道

void INIT_AD(void) 
{
 ATD0CTL2 = 0x40;  //启动A/D模块,快速清零,禁止中断
 ATD0CTL1_SRES=2;  //选用12位模数转换
 ATD0CTL3 = 0x88;   //每次只转换一个通道
 ATD0CTL4 = 0x00;   //AD模块时钟频率为8MHz
}

unsigned int AD_capture(unsigned char chanel) 
{
 unsigned int ADcap;
 switch(chanel)
 { 
  case 0:
	ATD0CTL5 = 0x00;//转换AD00
	while(!ATD0STAT0_SCF);
	ADcap = ATD0DR0;
	break;

  case 1:
	ATD0CTL5 = 0x01;//转换AD01
	while(!ATD0STAT0_SCF);
	ADcap = ATD0DR0;
	break;
  
  case 2:
	ATD0CTL5 = 0x02;//转换AD02
	while(!ATD0STAT0_SCF);
	ADcap = ATD0DR0;
	break;
 
  case 3:
	ATD0CTL5 = 0x03;//转换AD03
	while(!ATD0STAT0_SCF);
	ADcap = ATD0DR0;
	break;

  case 4:
	ATD0CTL5 = 0x04;//转换AD04
	while(!ATD0STAT0_SCF);
	ADcap = ATD0DR0;
	break;

  case 5:
	ATD0CTL5 = 0x05;//转换AD05
	while(!ATD0STAT0_SCF);
	ADcap = ATD0DR0;
	break;

  case 6:
	ATD0CTL5 = 0x06;//转换AD06
	while(!ATD0STAT0_SCF);
	ADcap = ATD0DR0;
	break;

  case 7:
	ATD0CTL5 = 0x07;//转换AD07
	while(!ATD0STAT0_SCF);
	ADcap = ATD0DR0;
	break;

  case 8:
	ATD0CTL5 = 0x08;//转换AD08
	while(!ATD0STAT0_SCF);
	ADcap = ATD0DR0;
	break;

  case 9:
	ATD0CTL5 = 0x09;//转换AD09
	while(!ATD0STAT0_SCF);
	ADcap = ATD0DR0;
	break;

  case 10:
	ATD0CTL5 = 0x0a;//转换AD10
	while(!ATD0STAT0_SCF);
	ADcap = ATD0DR0;
	break;

  case 11:
	ATD0CTL5 = 0x0b;//转换AD11
	while(!ATD0STAT0_SCF);
	ADcap = ATD0DR0;
	break;

  case 12:
	ATD0CTL5 = 0x0c;//转换AD12
	while(!ATD0STAT0_SCF);
	ADcap = ATD0DR0;
	break;

  case 13:
	ATD0CTL5 = 0x0d;//转换AD13
	while(!ATD0STAT0_SCF);
	ADcap = ATD0DR0;
	break;

  case 14:
	ATD0CTL5 = 0x0e;//转换AD14
	while(!ATD0STAT0_SCF);
	ADcap = ATD0DR0;
	break;

  case 15:
	ATD0CTL5 = 0x0f;//转换AD15
	while(!ATD0STAT0_SCF);
	ADcap = ATD0DR0;   
	break;
  
 }
 return(AD_data);
}

12位多通道

void INIT_AD(void) 
{
	ATD0CTL2 = 0x40;  //启动A/D转换,快速清零,禁止中断
	ATD0CTL1_SRES=2;  //选用12位模数转换
    ATD0CTL3 = 0xa8;   //每次转换5个通道,右对齐模式
	ATD0CTL4 = 0x00;   //AD模块时钟频率为8MHz
}


void AD_capture(void) 
{
	ATD0CTL5 = 0x31;  //转换AD01和AD05
	while(!ATD0STAT0_SCF);

	AD1=ATD0DR0;
	AD2=ATD0DR1;
	AD3=ATD0DR2;
	AD4=ATD0DR3;
	AD5=ATD0DR4;  
}

标签:case,ATD0STAT0,SCF,ATD,MC9S12XEP100,while,设置,ATD0CTL5,ADcap
来源: https://blog.csdn.net/haizeique/article/details/120353439