>#include <hidef.h> /* common defines and macros */<BR>#include <mc9s12dg128.h> /* derivative information */<BR>#pragma LINK_INFO DERIVATIVE "mc9s12dg128b"</P><P>void ADCInit()<BR>{<BR> ATD0CTL2=0xC0; //AD模块上电, 快速清零, 无等待模式, 禁止外部触发, 中断禁止<BR> ATD0CTL3=0x20; // 每个序列4次转换, No FIFO, Freeze模式下继续转换<BR> ATD0CTL4=0x83; // 8位精度, 2个时钟, ATDClock=[BusClock*0.5]/[PRS+1] ; PRS=3, divider=8<BR> ATD0CTL5=0xA0; //右对齐无符号,单通道采样,通道0 <BR> ATD0DIEN=0x00; // 禁止数字输入<BR>}</P><P><BR>void main(void) { <BR> ADCInit(); //AD初始化<BR> DDRB = 0xFF;<BR> PORTB = 0x00; <BR> /* put your own code here */<BR> EnableInterrupts;</P><P> for(;;) { <BR> while(!ATD0STAT1_CCF0); //等待转换结束 <BR> PORTB = (byte)ATD0DR0; //在B口显示转换值<BR> } /* wait forever */<BR> /* please make sure that you never leave this function */<BR>}<BR></P><P><FONT face=黑体 size=3>你找个恒压信号,比如3V,看看稳定情况先.</FONT></P>
> for(xx = 0; xx < 60; xx++){<BR> while(!ATD0STAT1_CCF0);<BR> frame[row][xx] = (byte)ATD0DR0L; <BR> }</P><P>取不到这些点的,取点要用示波器看.</P>
| 欢迎光临 智能车制作 (http://www.znczz.com/) | Powered by Discuz! X3.2 |