首页 | 新闻 | 新品 | 文库 | 方案 | 视频 | 下载 | 商城 | 开发板 | 数据中心 | 座谈新版 | 培训 | 工具 | 博客 | 论坛 | 百科 | GEC | 活动 | 主题月 | 电子展
返回列表 回复 发帖

ATD转换结果不正确

ATD转换结果不正确

哪位帮我看一下为什么转换结果不正确?谢谢

#include <hidef.h> /* common defines and macros */
#include <mc9s12xdp512.h> /* derivative information */
#pragma LINK_INFO DERIVATIVE "mc9s12xdp512"


void delay_100us(void);
unsigned char jishu;
unsigned char resultr;
unsigned char result;
void delay_ms(int i); //USE the ATD1 converter


void main(void)
{

ATD1CTL0=0x0A; //WRAP Around to AN0

ATD1CTL1=0x00; // None External Trigger Source Select

ATD1CTL2=0xA0; // disabled ATD Sequence Complete interrupt requests, Enable external trigger,Ring Edge External Trigger

ATD1CTL3=0x0A; //One Conversion Sequence Length,

ATD1CTL4=0xA0; //8 bit resolution

delay_100us() ;



PORTA = 0xFF;
PORTB = 0x00;
PORTC = 0x00;
PORTD = 0x00;
DDRA = 0xFF;
DDRB = 0xFF;
DDRC = 0xFF;
DDRD = 0xFF;

ATD1CTL5=0x0A; // Left justified 8 bit data in the result registers, Analog Input Channel Select AN10

delay_ms(150);
PORTB_PB0=ATD1STAT0_SCF;
PORTB_PB2=ATD1STAT1_CCF0;

while(!ATD1STAT0_SCF)
{

;
}


PORTC=((0x07&ATD1DR0H)<<2);
PORTD=(0x1F&(ATD1DR0H>>3));
if(ATD1STAT0_SCF)
{
ATD1STAT0_SCF=1;
}



EnableInterrupts;

for(;;) {} /* wait forever */
/* please make sure that you never leave this function */
}


void delay_100us(void)
{
int i;
for(i=0;i<50;i++)
asm("nop");

}
void delay_ms (int i)
{
unsigned char j;

for(j=0;j<i;j++)
{
delay_100us();
}
}

返回列表