中级会员
- 积分
- 222
- 威望
- 200
- 贡献
- 22
- 兑换币
- 0
- 注册时间
- 2008-7-15
- 在线时间
- 0 小时
|
5#
楼主 |
发表于 2008-7-16 21:34:21
|
只看该作者
Re:ad 问题 在线等答案。
#include <hidef.h> /* common defines and macros */<br>#include <mc9s12dg128.h> /* derivative information */<br>#pragma LINK_INFO DERIVATIVE "mc9s12dg128b"<br><br> /*pin connect <br> pin_PT0 = row_AYNS row fresh after 59.4us <br> pin_PT1 = frame_AYNS frame fresh after 19.75ms or 19.80ms<br> */ <br>byte frame[40][60], ATDResult;<br>int row=0,colum=0;<br>int rowcount = 0 ,res = 0 ,width=0,height=0, xx, xxrow = 0;<br>int frameNum = 0 ;<br>int sendCounter=0;<br>int mg = 0;<br><br>void Init_SCI(void)<br>{<br> SCI0BD=208;<br> SCI0CR1=0x00;<br> SCI0CR2=0x0C;<br>}<br><br>void delay(int t){<br> int i, j;<br> for(i = 0; i < t; i++)<br> for(j = 0; j < 125; j++);<br>}<br><br>void tx_sci(char tx_d)<br>{<br> while(SCI0SR1_TC!=1);<br> while(SCI0SR1_TDRE!=1);<br> SCI0DRL=tx_d;<br>}<br><br>void sendframe(){<br> int i, j;<br> for(i = 0; i < 40; i++)<br> for(j = 0; j < 60; j++)<br> tx_sci(frame<i>[j]);<br> <br> for(i = 0; i < 60; i++)<br> tx_sci(0xff); <br>}<br><br>void higherFreqence(void) //×ü??3??μμ?32M<br>{<br> REFDV=3;//2<br> SYNR=7; //5<br> while(0==CRGFLG_LOCK);<br> CLKSEL=0x80;<br>}<br><br>void setATD(void){<br> ATD0CTL2=0xC0; //AD?£?éé?μ?, ?ì?ù??á?, ?Tμè′y?£ê?, ???1ía2?′¥·¢, ?D?????1<br> ATD0CTL3=0x20; // ????DòáD4′?×a??, No FIFO, Freeze?£ê????ìD?×a??<br> ATD0CTL4=0x83; // 8?????è, 2??ê±?ó, ATDClock=[BusClock*0.5]/[PRS+1] ; PRS=3, divider=8<br> ATD0CTL5=0xA0; //óò?????T·?o?£?μ¥í¨μà2é?ù£?í¨μà0<br> ATD0DIEN=0x00; // ???1êy×?ê?è?<br> } <br> void set_ic0(void) {<br> TIOS_IOS0=0; <br> TCTL4_EDG0B=1;<br> TCTL4_EDG0A=0; //capture falling edge<br> TIE_C0I=1;<br> TSCR1_TEN=1;<br> TSCR2_PR = 0;<br> } <br> void set_ic1(void) {<br> TIOS_IOS1=0; <br> TCTL4_EDG1B=1;<br> TCTL4_EDG1A=0; //capture falling edge<br> TIE_C1I=1;<br> TSCR1_TEN=1;<br> TSCR2_PR = 0;<br> }<br>void Init_frame(){<br> int i, j;<br> for(i=0;i<40;i++)for(j=0;j<60;j++)frame<i>[j] = 0;<br>}<br>void main(void) {<br> Init_frame();<br> DisableInterrupts; <br> DDRB = 0XFF;<br> PORTB = 0Xff;<br> higherFreqence();<br> Init_SCI();<br> set_ic0();<br> set_ic1();<br> setATD();<br> EnableInterrupts; <br> TIE_C0I = 0X00;<br> TIE_C1I = 0X01;<br> for(;;) { <br> if(mg){<br> //HERE DO GAO();<br> sendframe();<br> mg = 0;<br> xxrow = row = 0;<br> Init_frame();<br> TIE_C1I = 0X01;<br> }<br> }<br>}<br><br><br>void interrupt rowFresh(void){ // enter this interrupt function after per 64us later<br> xxrow++;<br> if(xxrow >= 40 && xxrow <= 200){<br> rowcount++;<br> if(rowcount == 4){<br> rowcount = 0;<br> for(xx = 0; xx < 60; xx++){<br> while(!ATD0STAT1_CCF0);<br> frame[row][xx] = (byte)ATD0DR0L; <br> }<br> row++;<br> }<br> } <br> // tx_sci(0); <br> if(xxrow > 200){<br> mg = 1;<br> TIE_C0I = 0X00; //1?DD?D??<br> } <br>}<br><br>void interrupt frameFresh(void){ // enter this interrupt funtioin per 20ms later<br> // tx_sci(1);<br> TIE_C1I = 0X00; //1?3??D??<br> TIE_C0I = 0X01; //?aDD?D?? <br>} <br><br><br><br><br><br><br><br><br><br><br><br>这个是我的程序。麻烦您看一下,为什么发出来的东西乱七八糟的呢。还有3场的空白。<br> |
|