中级会员
- 积分
- 213
- 威望
- 191
- 贡献
- 22
- 兑换币
- 0
- 注册时间
- 2008-4-29
- 在线时间
- 0 小时
|
<>我毕设做的是CCD的路径识别,到了现在采集的程序还是调不成功。我是新手,对单片机了解较少。麻烦大家帮我看下编的这个图像采集程序。我用的是PT0捕捉行同步,PM口查询奇偶场同步信号跳变。</P><P>#include <hidef.h> /* common defines and macros */<BR>#include <mc9s12dg128.h> /* derivative information */<BR>#pragma LINK_INFO DERIVATIVE "mc9s12dg128b"</P><P>#define ROW_MAX 10 // number of rows needed to be sampled in each picture<BR>#define LINE_MAX 30 // number of points sampled in each row<BR>#define ROW_START 100 // begin to sample from line start<BR>#define ROW_END 320 // end flag of sampling<BR>#define INTERVAL 20 // interval between effective rows<BR>#define odd_even PTM_PTM4 // odd_even signal is sent into PortM_bit4<BR>unsigned char image_data[ROW_MAX][LINE_MAX];//data array of picture<BR>unsigned char black_mid[ROW_MAX]; // 0ne-dimensional array<BR>unsigned char black_mid_temp[ROW_MAX];<BR>unsigned char row; // x-position of the array<BR>unsigned char line; // y-position of the array<BR>unsigned int row_count; // row counter<BR>unsigned char line_sample; // used to counter in AD<BR>unsigned char row_image;<BR>unsigned char line_temp; // temperary variable used in data transfer<BR>unsigned char sample_data[LINE_MAX] ; // used to save one-dimension array got in interruption<BR>char oeflag;</P><P>void Init_PLL(void){<BR>REFDV=0x01;<BR>SYNR=0x04; // bus period=16Mhz*(SYNR+1)/(REFDV+1)<BR>while(!(CRGFLG&0x08)) {} // 等待PLL稳定<BR>CLKSEL=0x80;// open PLL<BR>}</P><P>void Init_PORT(void){<BR>DDRM_DDRM4=0; // Port M4 function as odd_even signal input<BR>}</P><P>void Init_ECT(void) {<BR>TIOS = 0x00; /*select all channels as input*/<BR>TSCR1 = 0x80; /*timer enable*/<BR>TSCR2 = 0x04; /*for 32M bus clock,set prescaler to 32.76ms*/<BR>TCTL4=0x01; /* PT0 捕捉上升沿 */<BR>TFLG1=0x01; /*clear C0F interrupt flag*/<BR>DLYCT=0x03; /*delay 1024 bus clock to avoid disturb*/<BR>TIE_C0I=0x01; /*enable C0I interrupt*/<BR>}</P><P>void Init_AD(void){<BR>ATD0CTL2=0xC0;// open AD, quick clear, no wait mode, inhibit outer awake, inhibit interrupt<BR>ATD0CTL3=0x08;// one transform in one sequence, No FIFO, contine to transform under freeze mode<BR>ATD0CTL4=0x81;<BR>// 8-bit precision, two clocks, ATDClock=[BusClock*0.5]/[PRS+1] ; PRS=1, divider=4 ;BusClock=40MHZ<BR>ATD0CTL5=0xA0; // right-algned unsigned,single channel,channel 0<BR>ATD0DIEN=0x00; // inhibit digital input<BR>}</P><P>#pragma CODE_SEG NON_BANKED<BR>void interrupt 8 ECT0_ISR(void){<BR>TFLG1=0x01; /*clear C0F interrupt flag*/<BR>row_count++;<BR>if((row_count>ROW_START)&&(row_count%INTERVAL==0)&&(row_image<ROW_MAX)){<BR>Init_AD();<BR>for(line_sample=0;line_sample<LINE_MAX;line_sample++){<BR>while(!ATD0STAT1_CCF0); // WAIT FOR TRANSFORM TO END<BR>sample_data[line_sample]= ATD0DR0L; // A/D transfer<BR>}<BR>ATD0CTL2=0x00; /*关ATD*/<BR>row_image++;<BR>}<BR>if((row_count>ROW_START)&&(row_count%INTERVAL==2)&&(row_image<ROW_MAX+1)){<BR>for(line_temp=0;line_temp<LINE_MAX;line_temp++){<BR>image_data[row_image-1][line_temp]=sample_data[line_temp];}<BR>}<BR>}</P><P>#pragma CODE_SEG DEFAULT<BR>void main(void){<BR>Init_PLL();<BR>Init_PORT();<BR>Init_ECT();<BR>Init_AD();<BR>for(;;){<BR>if((odd_even==1)&&(oeflag==0)){ //even field transfers to odd field<BR>oeflag=1;<BR>row_count=0;<BR>row_image=0;<BR>EnableInterrupts;<BR>DisableInterrupts;<BR>}<BR>else{<BR>if((odd_even==0)&&(oeflag==1)){ //odd field transfers to even field<BR>oeflag=0;<BR>}<BR>row_count=0;<BR>row_image=0;<BR>EnableInterrupts;<BR>DisableInterrupts;<BR>}<BR>}<BR>}<BR></P> |
|