Board logo

标题: ATD转换结果不正确 [打印本页]

作者: CarolineLY    时间: 2008-5-19 10:33     标题: 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();
}
}






欢迎光临 电子技术论坛_中国专业的电子工程师学习交流社区-中电网技术论坛 (http://bbs.eccn.com/) Powered by Discuz! 7.0.0