




版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
1、程序源代码中国民航大学三队PAGE PAGE XLIX程序源代码附件 A#include /* common defines and macros */#include /* derivative information */#pragma LINK_INFO DERIVATIVE mc9s12dg128b#define FIELD PTIJ_PTIJ1#define LINE 39#define DOT 68#define DIV 7char go_ready;char begin,t,deal;unsigned char field;unsigned int line;unsigned c
2、har dot;unsigned char oddLINEDOT,evenLINEDOT,*p,*q,*q0,centerLINE,root;unsigned char oddfinish,evenfinish;unsigned char i,j,k,l;unsigned char left,right,width;float slope0;float absoluteslope0;unsigned char overnumber;unsigned char dark0,dark,white,white0,white1,dif,ndark,nwhite;unsigned int sumwhit
3、e;unsigned char blackarea8,blacknum;unsigned char maybe4;unsigned char findoutline;unsigned char start,end;unsigned char finish;char beline,beline0,lasting;unsigned char findstartline;unsigned char startlinedally;unsigned char s0,e0,n;unsigned char breakpoint15;char breaknumber;char getlineslope142;
4、float lineslope14,diflineslope13;char turnleft,turnright,difrise,difdown;char beS,rightcircle,leftcircle;int endwarp,startwarp;unsigned char horizontallength;float turn;char roadfalse,falsetimes;float angle,angle0,absangle;unsigned char portK;unsigned char count,speed,neededspeed,turnspeed;float kee
5、pspeed;int p0,p1,espeed;float warp;float sumwarp;float averagewarp;float sumx,sumy;float sumxsumx,sumxx,sumxy;float slope,constnum;char ADDSPEED;char SLOWSPEED;/*initialization AD0*/void init_AD(void)/初始化 ATD0CTL2=0 xC0; ATD0CTL3=0 x08; ATD0CTL4=0 x81; ATD0CTL5=0 xA0; ATD0DIEN=0 x00; /*initializatio
6、n Port H6*/Port H6为电触开关,作为中断信号void init_intPortH6(void) PTH_PTH6 = 0; DDRH_DDRH6 = 0; PPSH_PPSH6 = 0; PIFH_PIFH6 = 1; PIEH_PIEH6 = 1; /*initialization Port J1*/void init_intPortJ1(void) PTJ_PTJ1 = 0; DDRJ_DDRJ1 = 0; PERJ_PERJ1 = 1; /*initialization Port J0*/void init_PortJ0(void) PTJ_PTJ0 = 0; DDRJ_
7、DDRJ0 = 0; PPSJ_PPSJ0 = 1; PIFJ_PIFJ0 = 1; PIEJ_PIEJ0 = 1; /*initalization PWM*/ void init_PWM(void) PWMPOL = 0 x0F; PWMCLK = 0 x00; PWMPRCLK = 0 x04; PWMCAE = 0 x00; PWMCTL = 0 x30; PWMPER01 = 60000; PWMDTY01 = 0 x0E30; PWMPER23 = 6000; PWMDTY23 = 0; PWME = 0 x0F;/*init_ECT*/void init_ECT(void) TIO
8、S = 0 x00; TSCR2 = 0 x07; PACTL = 0 x10; ICPAR_PA3EN = 1; TCTL4 = 0 xc0; TSCR1 = 0 x90;/*readcount*/void readcount(void) count=PACN3; PACN3=0;/* setspeed */void setspeed(unsigned char *s1,unsigned char *s2) if(findstartline2|go_ready=0) *s2=0; PORTK_BIT5=0; PWMDTY23=0; p0=0; p1=0; espeed=0; keepspee
9、d=SLOWSPEED; else if(*s2!=0) p0=(*s2-*s1)*200+espeed; if(p0=2000) PORTK_BIT5=0; if(p06000) p0=6000; else p0*=3; p0-=4000; if(p0=0) PORTK_BIT5=0; else PORTK_BIT5=1; p0+=6000; if(p05&line0) finish-; p+=(t-6)*DOT; for(dot=0;dot6;dot+) while(!ATD0STAT1_CCF0); *p=ATD0DR0L; for(dot=0;dot0;i-) q=q0+i*DOT;
10、blacknum=0; maybe0=0; maybe1=0; maybe2=0; maybe3=0; findoutline=1; for(j=0;j*(q+j+2)+20&blacknum%2=0) if(*(q+j)*(q+j+1)+15) blackareablacknum=j+1; blacknum+; else blackareablacknum=j+2; blacknum+; else if(*(q+j)+20*(q+j+2)&blacknum%2=1) if(*(q+j)+15=8) findoutline=0; break; if(findoutline=1) blacknu
11、m/=2; findoutline=0; for(k=0;k1&width0) for(k=0;kblacknum;k+) if(maybek=1) centeri=(blackarea2*k+1+blackarea2*k)/2; for(l=0;l*(q-DOT*2+centeri+l) break; else if(*(q+centeri)+5*(q-DOT*2+centeri-l) break; if(l=5) maybek=0; findoutline-; if(findoutline=1) break; if(i20) start=i; q=q0; q+=i*DOT; for(k=0
12、;kblacknum;k+) if(maybek=1) centeri=(blackarea2*k+1+blackarea2*k)/2; break; for(j=0;jDOT;j+) if(*(q+j)=dark0) dark=dark0; dark0=*(q+j); else if(*(q+j)=white0) white=white1; white1=white0; white0=*(q+j); else if(*(q+j)=white1) white=white1; white1=*(q+j); else if(*(q+j)white) white=*(q+j); dif=(white
13、-dark)*2/3; for(i=start;i0;i-) q=q0; q+=i*DOT; right=DOT; left=0; for(k=0;kk&*(q-DOT+centeri-k)dark+dif/2) root=centeri-k; break; else if(centeri+kDOT&*(q-DOT+centeri+k)=3) break; for(j=root+1;jdif+dark&sumwhite+dif/4*(q-DOT+j)&sumwhite*(q-DOT+j)+dif/4) if(sumwhitewhite+dif/2&whitesumwhite+dif&dark/
14、2*(q-DOT+root)+dif/2&*(q-DOT+root)3;j-)/ sumwhite=(*(q-DOT+j-1)+*(q-DOT+j-2)+*(q-DOT+j-3)/3; if(*(q-DOT+j)dif+dark&sumwhite+dif/4*(q-DOT+j)&sumwhite(8-(LINE-i)/20)*(absoluteslope0+1) if(i3) break; else for(k=0;k6;k+) if(*(q-2*DOT+centeri+k)dark+dif/2) centeri-1=centeri+k; break; else if(*(q-2*DOT+ce
15、nteri-k)=6) break; overnumber+; else centeri-1=(right+left)/2; if(overnumber4) break; if(centeri-1centeri+3|centeri-1+3centeri&absoluteslope0=3) slope0=(float)(centeri+3-centeri-1)/5; absoluteslope0=slope0; if(slope0end;i-) if(centeri-1=centeri+1) if(centeri=centeri-1-1|centeri=centeri-1+1) centeri=
16、centeri-1; for(i=start-1;iend;i-) if(centeri-1centeri¢eri+1centeri)| (centeri-1centeri¢eri+1centeri) centeri=(centeri-1+centeri+1)/2; s0=start; e0=end; breakpoint0=end; j=1; while(j15) n=s0-e0; for(i=e0+1;is0;i+) warp=centeri*n-centere0*(s0-i)-centers0*(i-e0); if(warpn) break; if(i2) for(j=1
17、;jbreaknumber;j+) n=breakpointj+1-breakpointj-1; warp=centerbreakpointj*n-centerbreakpointj-1*(breakpointj+1-breakpointj)-centerbreakpointj+1*(breakpointj-breakpointj-1); if(warp0) warp=-warp; if(warpn) for(i=j;ibreaknumber;i+) breakpointi=breakpointi+1; j-; breaknumber-; for(i=0;i0) turnright+; els
18、e if(getlineslopei00) turnleft+; for(i=0;i4) for(i=1;i0&diflineslopei-10&diflineslopei+10)| (diflineslopei0&diflineslopei+10) if(getlineslopei1*8getlineslopei-11+getlineslopei+11) lineslopei=(lineslopei-1+lineslopei+1)/2; diflineslopei=lineslopei-lineslopei+1; diflineslopei-1=lineslopei-1-lineslopei
19、; for(i=0;i0) difrise+; else difdown+; if(breaknumber3) for(i=1;i0&diflineslopei-10)| (diflineslopei0) if(getlineslopei1*4getlineslopei-11&getlineslopei10) difrise-; else difdown-; lineslopei=(lineslopei-1+lineslopei+1)/2; diflineslopei=lineslopei-lineslopei+1; diflineslopei-1=lineslopei-1-lineslope
20、i; rightcircle=0; leftcircle=0; beS=0; if(difrise=0&difdown0) leftcircle=1; else if(difdown=0&difrise0) rightcircle=1; else if(difrise0&difdown0) beS=1; if(breaknumbercenterend) horizontallength=(centerstart-centerend); else horizontallength=(centerend-centerstart); roadfalse=1; if(start-end+horizon
21、tallength25|(centerendDOT-5|centerend5) roadfalse=0; else for(i=1;i5) roadfalse=0; break; /起始线判断/ if(startlinedally0) startlinedally-; else if(end20) q=q0; for(i=20;i15) if(*(q+centeri-15+i*DOT)*(q+centeri+i*DOT)+dif/2) root=i; k=centeri-15; while(kcenteri) for(l=0;l2;l+) if(*(q+(root+l)*DOT+k+1)*(q
22、+centeri+i*DOT)+dif/2| *(q+(root+l)*DOT+k+1)*(q+root*DOT+k)+5) root=root+l; k+; break; else if(*(q+(root-l)*DOT+k+1)*(q+centeri+i*DOT)+dif/2| *(q+(root-l)*DOT+k+1)*(q+root*DOT+k)+5) root=root-l; k+; break; if(l=2) break; if(kcenteri-8) findstartline+; startlinedally=250; break; else if(*(q+centeri+1
23、5+i*DOT)centeri) for(l=0;l2;l+) if(*(q+(root+l)*DOT+k+1)*(q+centeri+i*DOT)+dif/2| *(q+(root+l)*DOT+k+1)*(q+root*DOT+k)+5) root=root+l; k-; break; else if(*(q+(root-l)*DOT+k+1)*(q+centeri+i*DOT)+dif/2| *(q+(root-l)*DOT+k+1)centeri+3&k8) turn=8; else if(turnend;i-) sumxy+=i*centeri-1; sumy+=centeri-1;
24、 sumxx+=(i-1)*(i-1); sumx=(start+end)*n/2; sumxsumx=sumx*sumx; slope=(n*sumxy-sumx*sumy)/(n*sumxx-sumxsumx); constnum=(sumxx*sumy-sumx*sumxy)/(n*sumxx-sumxsumx); for(i=start+1;iend;i-) warp=centeri-1-slope*(i-1)-constnum; sumwarp+=warp*warp; averagewarp=sumwarp/n; if(beline0=0) if(averagewarp35&beS=
25、0) beline=1; else if(averagewarp10) beline=1; angle=turn*8; if(beline=1) if(start-end10|angle0) if(start-end+horizontallength30|(centerendDOT-3|centerend20) falsetimes=0; else falsetimes-; if(angle-angle00.1|angle0-angle0.1) if(angle30) angle=30; else if(angle-30) angle=-30; PWMDTY01=0 x0DC0-25*angl
26、e; angle0=angle; absangle=angle; if(angle30) absangle=30; if(averagewarp40) averagewarp=40; averagewarp-=10; turnspeed=ADDSPEED*(30-absangle)/100+(30-averagewarp)/150+(10-breaknumber)/100)+SLOWSPEED; neededspeed=turnspeed; if(speedkeepspeed) keepspeed+=0.2; neededspeed=keepspeed; else keepspeed=neededspeed; else keepspeed=neededspeed; if(slow1) portK=0 x07; else if(beline=1) portK=0 x01; else if(beline=0) if(leftcircle=1) portK=0 x02; else if(rightcircle=1) portK=0 x04; else portK=0 x08; PORTK&=0 xF0; PORTK+=portK; beline0=beline; else portK=0 x0F; PORTK&
温馨提示
- 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
- 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
- 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
- 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
- 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
- 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
- 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- 幼儿园大班教学年度计划及优化思路
- 幼儿园语言发展测评与干预措施
- 医疗机构感染管理规范操作指南
- 档案管理考试题及试题及答案
- 2025注册电气工程师真题含答案详解综合题
- 2025司法考试主观题模拟题及答案
- 2025年税务师考试税法二试题及答案解析考生回忆版
- 2025普通外科学同步习题与全真模拟及答案
- 道路运输从业者资格认证模拟试题及答案
- 管理咨询项目分类及服务流程
- 生产主管转正工作总结
- 2025至2030中国高纯铝行业发展趋势与行业发展研究与产业战略规划分析评估报告
- 西藏介绍课件
- 会务理论考试题及答案
- 2025年期货从业资格之《期货法律法规》真题附答案详解【巩固】
- 幼儿园各项安全管理制度汇编
- 2025年“安全生产年”工作总结(2篇)
- GB/T 2481.1-2025固结磨具用磨料粒度组成的检测和标记第1部分:粗磨粒F4~F220
- 锦囊工程(修订版)
- 药敏试验结果的解读
- DB14∕T 1319-2021 公路工程标准工程量清单及计量规范
评论
0/150
提交评论