收藏 分享(赏)

摄像头可跑程序.doc

上传人:hyngb9260 文档编号:6724312 上传时间:2019-04-21 格式:DOC 页数:24 大小:63.50KB
下载 相关 举报
摄像头可跑程序.doc_第1页
第1页 / 共24页
摄像头可跑程序.doc_第2页
第2页 / 共24页
摄像头可跑程序.doc_第3页
第3页 / 共24页
摄像头可跑程序.doc_第4页
第4页 / 共24页
摄像头可跑程序.doc_第5页
第5页 / 共24页
点击查看更多>>
资源描述

1、摄像头可跑程序/-2012-5-15-/#include #include “derivative.h“ #include #define ROW 48 /采集行数#define COLUMN 152 /采集列数#define ROW_Z 48 /中线数组容量#define row_min 3 / 处理的开始行数#define row_max 48 /处理的结束行数#define ti PORTB_PB1unsigned char Image_DataROWCOLUMN; /输入灰度值数组unsigned char VSYN_C=0, Line_Flag=1, m = 0;unsigned i

2、nt Line_C=0;unsigned char Interval;int flag_line=0;unsigned char THRESHOLD=0x80; /阈值unsigned int centralROW_Z; /中心线数组unsigned int central_left=0; /左边黑线起始列unsigned int central_right=125; /右边黑线起始列unsigned int left_lineROW_Z;unsigned int right_lineROW_Z;const uchar hang= 6,7, 8,10,12,14,16,18,20,22,24,

3、26,28,30,32,34,36, 38,40,43,46,49,52,55,58,61,64,67,72,77,83,89,95,101,107,113,119,125,133,141,150,159,170,181,195,210,225,233;/-函数声明-/void PLL_Init(void); /时钟初始化void TIM_Init(void); /行场中断初始化void SCI0_Init(void); /串口初始化void SCI_Write(unsigned char sendchar);/串口发送数据int left_saltus(int row,int start);

4、 /左跳变点检测int right_saltus(int row,int start); /右跳变点检测void image_centralline(void); /中线提取void image_central_disp1(void); /上位机中心线输出void image_central_disp2(void); /上位机中心线输出void SCI0_SWJ(void); /上位机发送图象的数据void Init_PWMout(void);void Delay(uint dly);int start_line_find(int start_line, int left); /基准行检查/-

5、 时钟初始化函数 -/void PLL_Init(void)CLKSEL=0x00; /48mhzSYNR=0XC0 | 0X05;REFDV=0XC0 | 0X03;PLLCTL_PLLON=1;POSTDIV=0X00;asm(nop);asm(nop);while(0=CRGFLG_LOCK); /锁相环锁定CLKSEL_PLLSEL=1; /选定 PLL时钟/- 行场中断初始化函数 -/void TIM_Init(void) TIOS =0x00; /定时器通道 0,1 为输入捕捉TSCR1=0x80; /定时器使能TCTL4=0x09; /通道 0 捕捉上升沿通道 1 捕捉下降沿TI

6、E=0x03; /通道 0,1 中断使能TFLG1=0xFF; /清中断标志位/- 串口 1初始化函数 -/void SCI0_Init()SCI0BDL = (byte)(48000000 /* OSC freq */2) / 19200 /* baud rate */ / 16 /*factor*/);SCI0CR1 = 0X00; /*normal,no parity*/SCI0CR2 = 0X0C; /*RIE=1,TE=1,RE=1, */- 串口发送数据-/void SCI_Write(unsigned char sendchar) while (!(SCI0SR1SCI0DRH=

7、0;SCI0DRL=sendchar;/-PWM初始化-/void Init_PWMout(void) PWME=0x00; /关闭 pwm/PWME=0x28; PWMCAE=0x00; /左对齐方式PWMPOL=0x28; /极性位=1, duty=高电平时间 3 5 通道PWMCTL = 0x70; /45. 23.01 通道级联PWMCLK = 0x28; PWMPRCLK=0x22; /clock 4 clock B 4 PWMSCLA = 3; / clockSA = 1mhz 转向舵机PWMSCLB = 6; /clockSB=1Mhz 电机PWMPER23=10000; /P3

8、口输出频率 100HZPWMDTY23=1059; /中心=1059;左极限=995;右极限=1118PWME_PWME3=1; PWMPER45=200; /P5口输出频率 5KHZPWMDTY45=100;PWME_PWME5=1;/ PWME=0xff; /启动 pwm/- 延时函数-/void Delay(uint dly) uint i;for(;dly0;dly-)for(i=0;i=end;i-)if(Image_Datarowi-Image_Datarowi-115)if(Image_Datarowi-Image_Datarowi-3)15) temp+;if(Image_Da

9、tarowi-Image_Datarowi-4)15) temp+; /检测黑线是否够宽if(temp=1)return i; /宽度大于 2 确定是跳变点return 1; /没有检测到跳变点int left_saltus_last(int row,int start) int i,end,temp;end = start-15;if(end=end;i-)if(Image_Datarowi-Image_Datarowi-115)if(Image_Datarowi-Image_Datarowi-3)15) temp+;if(Image_Datarowi-Image_Datarowi-4)15

10、) temp+; /检测黑线是否够宽if(temp=1)return i; /宽度大于 2 确定是跳变点return 1; /没有检测到跳变点int right_saltus_last(int row,int start) int i,end,temp;end = start+15;if(end152) end = 152;for(i=start;i15)if(Image_Datarowi-Image_Datarowi+3)15) temp+;if(Image_Datarowi-Image_Datarowi+4)15) temp+; /检测黑线是否够宽if(temp=1) return i;

11、/宽度大于 3 确定是跳变点return 1; /没有检测到跳变点/-基准行扫描-/int start_line_find_left(int start_line)int i;int temp=0;/int end_line=start_line-16; int left; for(i=start_line;i=1;i-) / 收索六行 作为基准行 起始行left=left_saltus(i,60);if(left!=1) left_linei=left;temp+;if(temp1) temp=0;return i; return 1;int start_line_find_right(in

12、t start_line)int i;int temp=0;/ int end_line=start_line-16; int right; for(i=start_line;i=1;i-) / 收索六行 作为基准行 起始行right=right_saltus(i,90);if(right!=1) temp+;if(temp1) temp=0;return i;right_linei=right; return 1;/-后面 40行的黑线提取-/int last_line_find_left() int i;int temp=0;int base_line,left_1;base_line=s

13、tart_line_find_left(46);if(base_line=1) return; elsefor(i=base_line;i=1;i-) left_1 = left_saltus_last(i,left_linei+1+8);if(left_1=1) temp+;if(temp=1) temp=0;return;left_linei=left_linei+1; else left_linei=left_1; int last_line_find_right() int i;int base_line,right_1;int temp=0;base_line=start_line_

14、find_right(46);if(base_line=1) return; elsefor(i=base_line;i=1;i-) right_1 = right_saltus_last(i,right_linei+1-8);if(right_1=1) temp+; if(temp=1) temp=0;return;right_linei=right_linei+1; else right_linei=right_1; /-中线提取-/-中心线输出-/void image_central_disp1(void) int i,j;SCI_Write(0x01);for(i=1;i=0) / c

15、entel=centel;PWMDTY45= 125+3*abs_1(centel)/2;if(PWMDTY45=135) PWMDTY45=135;centel=2*centel-20;else centel=2*(centel+5);PWMDTY45= 125+4*abs_1(centel)/2;if(PWMDTY45=140) PWMDTY45=135;dir=1059+centel;if(dir1110) dir=1110;if(dir48|m252)return;if(m5) Image_DataLine_C1 = PORTA;Image_DataLine_C2 = PORTA;Im

16、age_DataLine_C3 = PORTA;Image_DataLine_C4 = PORTA;Image_DataLine_C5 = PORTA;Image_DataLine_C6 = PORTA;Image_DataLine_C7 = PORTA;Image_DataLine_C8 = PORTA;Image_DataLine_C9 = PORTA;Image_DataLine_C10 = PORTA;Image_DataLine_C11 = PORTA;Image_DataLine_C12 = PORTA;Image_DataLine_C13 = PORTA;Image_DataLi

17、ne_C14 = PORTA;Image_DataLine_C15 = PORTA;Image_DataLine_C16 = PORTA;Image_DataLine_C17 = PORTA;Image_DataLine_C18 = PORTA;Image_DataLine_C19 = PORTA;Image_DataLine_C20 = PORTA;Image_DataLine_C21 = PORTA;Image_DataLine_C22 = PORTA;Image_DataLine_C23 = PORTA;Image_DataLine_C24 = PORTA;Image_DataLine_

18、C25 = PORTA;Image_DataLine_C26 = PORTA;Image_DataLine_C27 = PORTA;Image_DataLine_C28 = PORTA;Image_DataLine_C29 = PORTA;Image_DataLine_C30 = PORTA;Image_DataLine_C31 = PORTA;Image_DataLine_C32 = PORTA;Image_DataLine_C33 = PORTA;Image_DataLine_C34 = PORTA;Image_DataLine_C35 = PORTA;Image_DataLine_C36

19、 = PORTA;Image_DataLine_C37 = PORTA;Image_DataLine_C38 = PORTA;Image_DataLine_C39 = PORTA;Image_DataLine_C40 = PORTA;Image_DataLine_C41 = PORTA;Image_DataLine_C42 = PORTA;Image_DataLine_C43 = PORTA;Image_DataLine_C44 = PORTA;Image_DataLine_C45 = PORTA;Image_DataLine_C46 = PORTA;Image_DataLine_C47 =

20、PORTA;Image_DataLine_C48 = PORTA;Image_DataLine_C49 = PORTA;Image_DataLine_C50 = PORTA;Image_DataLine_C51 = PORTA;Image_DataLine_C52 = PORTA;Image_DataLine_C53 = PORTA;Image_DataLine_C54 = PORTA;Image_DataLine_C55 = PORTA;Image_DataLine_C56 = PORTA;Image_DataLine_C57 = PORTA;Image_DataLine_C58 = POR

21、TA;Image_DataLine_C59 = PORTA;Image_DataLine_C60 = PORTA;Image_DataLine_C61 = PORTA;Image_DataLine_C62 = PORTA;Image_DataLine_C63 = PORTA;Image_DataLine_C64 = PORTA;Image_DataLine_C65 = PORTA;Image_DataLine_C66 = PORTA;Image_DataLine_C67 = PORTA;Image_DataLine_C68 = PORTA;Image_DataLine_C69 = PORTA;

22、Image_DataLine_C70 = PORTA;Image_DataLine_C71 = PORTA;Image_DataLine_C72 = PORTA;Image_DataLine_C73 = PORTA;Image_DataLine_C74 = PORTA;Image_DataLine_C75 = PORTA;Image_DataLine_C76 = PORTA;Image_DataLine_C77 = PORTA;Image_DataLine_C78 = PORTA;Image_DataLine_C79 = PORTA;Image_DataLine_C80 = PORTA;Ima

23、ge_DataLine_C81 = PORTA;Image_DataLine_C82 = PORTA;Image_DataLine_C83 = PORTA;Image_DataLine_C84 = PORTA;Image_DataLine_C85 = PORTA;Image_DataLine_C86 = PORTA;Image_DataLine_C87 = PORTA;Image_DataLine_C88 = PORTA;Image_DataLine_C89 = PORTA;Image_DataLine_C90 = PORTA;Image_DataLine_C91 = PORTA;Image_

24、DataLine_C92 = PORTA;Image_DataLine_C93 = PORTA;Image_DataLine_C94 = PORTA;Image_DataLine_C95 = PORTA;Image_DataLine_C96 = PORTA;Image_DataLine_C97 = PORTA;Image_DataLine_C98 = PORTA;Image_DataLine_C99 = PORTA;Image_DataLine_C100 = PORTA;Image_DataLine_C101 = PORTA;Image_DataLine_C102 = PORTA;Image_

25、DataLine_C103 = PORTA;Image_DataLine_C104 = PORTA;Image_DataLine_C105 = PORTA;Image_DataLine_C106 = PORTA;Image_DataLine_C107 = PORTA;Image_DataLine_C108 = PORTA;Image_DataLine_C109 = PORTA;Image_DataLine_C110 = PORTA;Image_DataLine_C111 = PORTA;Image_DataLine_C112 = PORTA;Image_DataLine_C113 = PORT

26、A;Image_DataLine_C114 = PORTA;Image_DataLine_C115 = PORTA;Image_DataLine_C116 = PORTA;Image_DataLine_C117 = PORTA;Image_DataLine_C118 = PORTA;Image_DataLine_C119 = PORTA; Image_DataLine_C120 = PORTA;Image_DataLine_C121 = PORTA;Image_DataLine_C122 = PORTA;Image_DataLine_C123 = PORTA;Image_DataLine_C1

27、24 = PORTA;Image_DataLine_C125 = PORTA;Image_DataLine_C126 = PORTA;Image_DataLine_C127 = PORTA;Image_DataLine_C128 = PORTA;Image_DataLine_C129 = PORTA;Image_DataLine_C130 = PORTA;Image_DataLine_C131 = PORTA;Image_DataLine_C132 = PORTA;Image_DataLine_C133 = PORTA;Image_DataLine_C134 = PORTA;Image_Dat

28、aLine_C135 = PORTA;Image_DataLine_C136 = PORTA;Image_DataLine_C137 = PORTA;Image_DataLine_C138 = PORTA;Image_DataLine_C139 = PORTA;Image_DataLine_C140 = PORTA; Image_DataLine_C141 = PORTA;Image_DataLine_C142 = PORTA;Image_DataLine_C143 = PORTA;Image_DataLine_C144 = PORTA;Image_DataLine_C145 = PORTA;

29、Image_DataLine_C146 = PORTA;Image_DataLine_C147 = PORTA;Image_DataLine_C148 = PORTA;Image_DataLine_C149 = PORTA; Image_DataLine_C150 = PORTA;Image_DataLine_C151 = PORTA;Line_C+;Line_Flag = 0;/-场中断处理函数-/interrupt 9 void VSYN_Interrupt(void)TFLG1_C1F = 1; /清场中断TFLG1_C0F = 1; /清行中断Line_C = 0; /行计数器m=0;VSYN_C = +VSYN_C; #pragma CODE_SEG DEFAULT

展开阅读全文
相关资源
猜你喜欢
相关搜索

当前位置:首页 > 企业管理 > 管理学资料

本站链接:文库   一言   我酷   合作


客服QQ:2549714901微博号:道客多多官方知乎号:道客多多

经营许可证编号: 粤ICP备2021046453号世界地图

道客多多©版权所有2020-2025营业执照举报