版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
#include<hidef.h> /*commondefinesandmacros*/#include<mc9s12dg128.h> /*derivativeinformation*/#include<math.h>voidinit_PLL(void){ //pll _LOCK==0);//waitpllclocksteadyCLKSEL=0x80;//setbusclock=pllclock/2}voidinit_AD(void)//初始化{ATD0CTL2=0xC0;AD模块上电,快速清零,无等待模式,忽略触发,转换完成中断ATD0CTL3=0x08;//转换的通道数为1,NoFIFO,Freeze模式下不停止ATD0CTL4=0x81;//8位精度,采样2个时钟周期ATD0DIEN=0x00;//数字输入}/************initializationPort//PortH6void{PTH_PTH6=0; DDRH_DDRH6=0; PPSH_PPSH6=0; PIFH_PIFH6=1; PIEH_PIEH6=1; //中断使能}/***********initializationPortJ1******************/voidinit_intPortJ1(void){PTJ_PTJ1=DDRJ_DDRJ1=PERJ_PERJ1= //PullDevice}/************initializationPortJ0*****************/voidinit_PortJ0(void){PTJ_PTJ0=DDRJ_DDRJ0=0;//PORTJDataDirection:INPUTPPSJ_PPSJ0=1;//PORTJRisingEdgePIFJ_PIFJ0=1;//ClearPORTJInterruptPIEJ_PIEJ0=1;//PORTJInterrupt//} voidinit_(void){POL=0x0F; //PolarityCLK=0x00; //PRCLK=0x04; //ClockA=BusClock/16 ClockB=BusClock CAE=0x00; //LeftAligeOutputModeCTL=0x30; //Concatenatechannel0and1 2and3PER01=50000;//50HzDTY01=3650;PER23=6000; DTY23=0;E= //Channel1andChannel3}voidinit_ECT(void){ =0x00; //inputcaptureTSCR2=0x07; TCTL4 //下降沿捕捉脉冲PBCTL=0x40; ICPAR=0X03; 10=TSCR1 //计数器使能,读时自动}void{MCCTL=MCCTL&0Xfb;//模数计数器运MCCTL //MCCTL=MCCTL|0X04;//模数计数器使能T=2500;//(1/40M)*16*2500=MCCTLMCCTL|0X08}#defineFIELDPTIJ_PTIJ1#defineLINE39#defineDOT#defineDIV#defineTIME_INTER5chargo_ready;charbegin,t,deal;unsignedcharfield;unsignedintline;unsignedchardot;unsignedcharoddfinish,evenfinish;unsignedchari,j,k,l,m;unsignedcharleft,right,width,width0,inflag,inflag1,outflag;inttime;unsignedcharunsignedchardark0,dark,dark1,white,white0,white1,dif,dif1,ndark,nwhite;unsignedintsumwhite;unsignedcharblackarea[8],blacknum;unsignedcharmaybe[4];unsignedcharfindoutline;unsignedcharfinish;charunsignedcharfindstartline,leftoutflag=0,rightoutflag=0,outnumber;unsignedcharstartlinedally,canstop;int reaknumber;//计算曲线用charfloatturn,angle,angle0,absangle,anglechange;unsignedcharbreakpoint[20];chargetlineslope[14][2],sanjiaoout=1,sanjiaoin=0;floatlineslope[14];charturnleft,turnright,beS;intendwarp,startwarp;charroadfalse;unsignedcharintfloatkeepspeed,kp1,difu,intp0,p1,espeed,difspeed,sespeed,oldespeed=0, unsignedintnumber_count;floatwarp;floatsumwarp;floataveragewarp,a,b;floatsumx,sumy;floatsumxsumx,sumxx,sumxy;floatslope,constnum;charADDSPEED;charSLOWSPEED;#defineeclkdiv(*((volatileunsignedchar*)(0x0110)))#defineecnfg(*((volatileunsignedchar*)(0x0113)))#defineeprot(*((volatileunsignedchar*)(0x0114)))#defineestat(*((volatileunsignedchar*)(0x0115)))#defineecmd(*((volatileunsignedchar*)(0x0116)))unsignedcharrelative_addr;#defineEE_BASE((volatileunsignedint*)(0x2000))volatileunsignedint*ee_addr=EE_BASE;voidwreeprom(void)//putyourowncodehereECLKDIV=0x4b;*ee_addr=n;ECMD=0x20;ESTAT|=0x80;*ee_addr=turn;ECMD=0x20;ESTAT|=0x80;*ee_addr=count;ECMD=0x20;ESTAT|=0x80;*ee_addr=p0;ECMD=0x20;ESTAT|=0x80;}voidreadcount(void){}/************setspeed**********************/voidsetspeed(int*s1,int*s2) //speedneeddespeed{{}else{{}elseif(sespeed<=-{sespeed=-} {{}}{{}{{}}}}{}}voidgetdot(unsignedchar*c){ //现在为偶{} //{}{{finish--}{}{}}{{}{}}}voidmain(void){/*REFDV=3; //设置pll _LOCK==0);//waitpllclocksteadyCLKSEL=0x80;//setbusclock=pllclock/2 DDRK=0xFF;DDRA=0x00;if{ }else{}else{}else{}else{}else{}else{}else{}{findstartline=1;}elsefindstartline=0;{{}else{}{ {for(j=0;j<DOT-{{{}{}}elseif(*(q+j)+20<*(q+j+2)&&blacknum%2==1) {}{}}{}}{ {{}{}}}{ {{{if(*(q+center[i])+5>*(q-{}{}}{}}}}if(findoutline>=1)//真正找到{}}{{{}}{if(*(q+j)<=dark0)//找到{}else{}{}else{}else{}}for(i=start;i>0;i--{q+=i*DOTi{if(center[i]+1>k&&*(q-DOT+center[i]-{} { } {{{if(*(q-DOT+center[i]- dark0=*(q-DOT+center[i]-}elseif(*(q-DOT+center[i]-{dark=*(q-DOT+center[i]-}if(*(q-DOT+center[i]-{white0=*(q-DOT+center[i]-}elseif(*(q-DOT+center[i]-{white1=*(q-DOT+center[i]-}elseif(*(q-DOT+center[i]-{white=*(q-DOT+center[i]-}}}else{{{}elseif(*(q-{}if(*(q-{white0=*(q-}elseif(*(q-{white1=*(q-}elseif(*(q-{white=*(q-}}}{}{if(center[i]+1>k&&*(q-DOT+center[i]-{} if(center[i]+k<DOT&&*(q-{}}{}}for(j=root+1;j<DOT-{sumwhite=(*(q-DOT+j+1)+*(q-DOT+j+2)+*(q-if(*(q-DOT+j)>dif+dark&&sumwhite+dif/2>*(q-DOT+j)&&sumwhite<*(q-{{}}}for(j=root-1;j>3;j--{sumwhite=(*(q-DOT+j-1)+*(q-DOT+j-2)+*(q-DOT+j-if(*(q-DOT+j)>dif+dark&&sumwhite+dif/2>*(q-DOT+j)&&sumwhite<*(q-{}}width=right-{{{}}}{}}{}else{}}{}{}{{}{PORTK&=0xf0;}else}else}{{}{{if(*(q-{}elseif(*(q-2*DOT+center[i]-{}{}}} {} //3--{}{}if(center[i-1]>center[i]+5||center[i-1]<center[i]- {} for(i=start-1;i>end;i--{if(center[i-{if(center[i]==center[i-1]-1||center[i]==center[i-{}}}for(i=start-1;i>end;i--{{}}{horizontallength=(center[start]-}{} //15--{{{warp=-} {}}{{}}else}{}for(i=0;i<breaknumber-{ lineslope[i]/=getlineslope[i][1];//斜率{}else{}}if(breaknumber<=2)//直 {beS=0;}else{} {}{{{}{}}}{}{}a2=center[end]-center[end+1];{}a3=center[end+1]-center[end+2];{}a4=center[end+2]-center[end+3];{}{{}}if(start-end+horizontallength>20||((center[end]>DOT-2||center[end]<2)&&start-{}{{if(breakpoint[i]-breakpoint[i-{}}}{startlinedally--}else{{{if(*(q+center[i]-{{{{} *(q+(root-{}}{}}if(k<center[i]-2&&k>center[i]-{ //iffindstartline>1thenstop}}}{{{{{}elseif(*(q+(root-*(q+(root-{}}{}}{ //iffindstartline>1thenstop}}}}}////else}{} //roadfalse{n=start- {for(i=start+1;i>end;i--{sumxy+=i*center[i-sumxx+=(i-1)*(i-}for(i=start+1;i>end;i--{}{{}}{{}} {if(start-end<30||angle>10||angle<-{{}}}turn=((float)(endwarp-startwarp)*(start-10)/(start- {}elseif(turn<-{{} {}{}{}else{ }else{}if(angle-angle0>0.1||angle0-{{}elseif(ang
温馨提示
- 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
- 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
- 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
- 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
- 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
- 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
- 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- GB/T 44546-2024建筑用装配式集成吊顶通用技术要求
- 主要产品采购合同
- 家具购销合同范本经典
- 工程合同进度与质量要求
- 独家招生代理合作协议
- 股东出资协议书参考格式
- 二手推土机买卖协议
- 2024版劳务派遣协议书
- 按份共同保证书范本
- 门面转让合同范例
- TYNAEPI 0001-2024 有机固废低温绝氧碳化处理工程技术规
- 大棚膜购销合同协议书
- 2024电梯土建施工合同范本
- 甘肃省道德与法治初二上学期试题及答案解析
- 2023年中考英语备考让步状语从句练习题(附答案)
- JGJ/T235-2011建筑外墙防水工程技术规程
- (正式版)HG∕T 21633-2024 玻璃钢管和管件选用规定
- 柔性生产线设计
- 汽车维修工时定额核定方法编制说明
- 辛弃疾词《青玉案·元夕》
- 《无人机驾驶基础》课件-项目四 无人机结构及性能
评论
0/150
提交评论