智能车制作

 找回密码
 注册

扫一扫,访问微社区

查看: 1786|回复: 7
打印 上一主题 下一主题

[摄像头] 自己写的一份程序,但是不知道为什么不能跑...

[复制链接]

1

主题

29

帖子

0

精华

高级会员

Rank: 4

积分
760
威望
383
贡献
249
兑换币
248
注册时间
2013-1-16
在线时间
64 小时
毕业学校
广州大学
跳转到指定楼层
1#
发表于 2013-1-29 10:25:09 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式
1贡献
本帖最后由 时空幻影 于 2013-1-29 10:28 编辑

自己写的一份程序,但是不知道为什么不能跑...是不是我摄像头采集写得不对?不是说有场信号和行信号吗?我在示波器上面看不到...虽然说黑线提取那部分写得不怎么样,但是我在纠结究竟是黑线写得不好,还是我采集根本没写对...可以的话,各位哥哥姐姐能不能给我解释一下ov7620摄像头怎么发送数据给MC9s12xs128啊?帮我看看我的问题所在吧...

#include <hidef.h>      /* common defines and macros */
#include "derivative.h"      /* derivative-specific definitions */
#include "MC9S12XS128.h"
#define  ROW 40//采集行数
#define  COLUMN 120//最多采集点
#define hangjiange 6//采集行间隔数
#define     hangzuiduo  120
#define     fa_zhi 60
unsigned char m,hangshu,hang,chang,x;
int k1,k2;
unsigned char Image[ROW][COLUMN];
unsigned char L[40];
unsigned int l1,l2,l3;//三段式
unsigned char x1,x2; //检查到黑白跳变的瞬间行列点
unsigned char kx;       //舵机参数
unsigned int angle[9]={666,833,1055,1277,1500,1722,1944,2166,2333};    //角度
                  //-75 -60  -40  -20  0   20   40  60   75
unsigned char speed;   //电机参数

void PLLINIT(void) //时钟PLL初始化
{
CLKSEL=0x00; //48mhz 总线是24mhz
SYNR=0xC5;
REFDV=0xC3;
PLLCTL_PLLON=1;
POSTDIV=0x00;
asm(nop);
asm(nop);
while(0==CRGFLG_LOCK);
CLKSEL_PLLSEL=1;
}
void PWMINIT(void)//pwm初始化
{
//PWM45舵机控制                       
PWMCTL_CON45=1;     //4,5通道级联
PWMCAE_CAE5=0;      //左对齐
PWMCNT45=0;          //计数器从0开始
PWMPOL_PPOL5=1;     //先输高电平
PWMPRCLK=0;         //A,B不分频,A=B=24MHz
PWMSCLA=12;         //SA分频,SA=1MHz
PWMPER45=5000;     //周期
PWMCLK_PCLK5=1;    //SA为时钟源
PWMDTY45=1500;      //行直线
PWME_PWME5=1;      //PWM5通道使能

//PWM01,IN1驱动电机控制
PWMCTL_CON01=1;     //0,1通道级联
PWMCAE_CAE1=0;      //左对齐
PWMCNT01=0;          //计数器从0开始
PWMPOL_PPOL1=0;     //先输低电平
PWMPER01=2400;     //频率10KHz
PWMCLK_PCLK1=0;    //A为时钟源
PWMDTY01=2400;   
PWME_PWME1=1;      //PWM1通道使能

//PWM23,IN2驱动电机控制
PWMCTL_CON23=1;     //2,3通道级联
PWMCAE_CAE3=0;      //左对齐
PWMCNT23=0;          //计数器从0开始
PWMPOL_PPOL3=0;     //先输低电平
PWMPER23=2400;     //频率10KHz
PWMCLK_PCLK3=0;    //B为时钟源
PWMDTY23=1700;      
PWME_PWME3=1;      //PWM3通道使能

}
void changhangINIT(void)//行场中断初始化
{
TIOS=0X00;//定时器通道1,0为输入捕捉
TSCR1=0X08;//定时器使能
TCTL4=0X09;//通道0捕捉上升沿 通道1捕捉下降沿
TIE=0X03;//通道0,1中断使能
TFLG1=0XFF;//清中断标志位
}
void er_zhi_hua(void)
{
for(hangshu=0;hangshu<ROW;hang++)
{
   for(x=0;x<hangzuiduo;x++)
   {
     if(Image[hangshu][x]>fa_zhi)
              Image[hangshu][x]=1;
     else
     Image[hangshu][x]=0;//暂时不知道白色的数值是多少,现在是大于阀值=0,小于阀值=1  bai=0
   }
}
}
void hei_xian_ti_qv(void)
{
  for(hangshu=0;hangshu<ROW;hangshu++)
  {
    for(x1=0;x1<=120;x1++)
    {
      if(Image[hangshu][x1]==1)              //寻找跳变,两点跳变的中点即道路中心
           break;
    }
    for(x2=120;x2>=0;x2++)
    {
     if(Image[hangshu][x2]==1)
           break;
    }
    L[hangshu]=(x1+x2)/2;
  }
     l1=(L[0]+L[1]+L[2]+L[3]+L[4]+L[5]+L[6]+L[7]+L[8]+L[9]+L[10]+L[11]+L[12] )/13;
     l2=(L[13]+L[14]+L[15]+L[16]+L[17]+L[18]+L[19]+L[20]+L[21]+L[22]+L[23]+L[24]+L[25]+L[26])/14;
     l3=(L[27]+L[28]+L[29]+L[30]+L[31]+L[32]+L[33]+L[34]+L[35]+L[36]+L[37]+L[38]+L[39])/13;
     k1=l1-l2;
     k2=l2-l3;
     if(k1<2&&k2<2)
     {  
        kx=8;
     }
     else if(k1>2&&k2>2)
     {
        kx=0;
     }
     else
      kx=4;
        
}

void duo_ji(void)
{ switch(kx)
  {
    case 0: PWMDTY45=angle[0];speed=1;break;
    case 1: PWMDTY45=angle[1];speed=1;break;
    case 2: PWMDTY45=angle[2];speed=1;break;
    case 3: PWMDTY45=angle[3];speed=1;break;
    case 4: PWMDTY45=angle[4];speed=2;break;
    case 5: PWMDTY45=angle[5];speed=1;break;
    case 6: PWMDTY45=angle[6];speed=1;break;
    case 7: PWMDTY45=angle[7];speed=1;break;
    case 8: PWMDTY45=angle[8];speed=1;break;
   
  }
}
void dianji()
{
switch(speed)
{
  case 0WMDTY01=2400; PWMDTY23=2400;break;
  case 1:PWMDTY01=2400; PWMDTY23=2000;break;
  case 2:PWMDTY01=2400; PWMDTY23=1700;break;
}
}
void qing_0(void)
{
chang=0;
hangshu=0;
}
/************************/
void main(void)
{
  DDRA=0x00; //初始化PA,摄像头数字传输
  DisableInterrupts;//关闭中断
  PLLINIT();//时钟PLL初始化
    PWMINIT();//pwm初始化
  changhangINIT();//行场中断初始化

EnableInterrupts;
while(1)
  {
     if(chang==1)//一场收集完成
     {
      er_zhi_hua();
      hei_xian_ti_qv();
      duo_ji();
      dianji();
      qing_0();
     }
     
  }

}
/***************************************************中断系列*/
#pragma CODE_SEG NON_BANKED
interrupt 8 void hangzhongduan(void)
{
  TFLG1_C0F = 1;
  m++;
  if (m<6 || m>240)      
  {
    return;//判断是否从新的一场开始
  }
  if(m%hangjiange==0)
  {
      

  Image[hangshu][0] = PORTA;
  Image[hangshu][1] = PORTA;
  Image[hangshu][2] = PORTA;
  Image[hangshu][3] = PORTA;
  Image[hangshu][4] = PORTA;
  Image[hangshu][5] = PORTA;
  Image[hangshu][6] = PORTA;
  Image[hangshu][7] = PORTA;
  Image[hangshu][8] = PORTA;
  Image[hangshu][9] = PORTA;
  Image[hangshu][10] = PORTA;
  Image[hangshu][11] = PORTA;
  Image[hangshu][12] = PORTA;
  Image[hangshu][13] = PORTA;
  Image[hangshu][14] = PORTA;
  Image[hangshu][15] = PORTA;
  Image[hangshu][16] = PORTA;
  Image[hangshu][17] = PORTA;
  Image[hangshu][18] = PORTA;
  Image[hangshu][19] = PORTA;
  Image[hangshu][20] = PORTA;
  Image[hangshu][21] = PORTA;
  Image[hangshu][22] = PORTA;
  Image[hangshu][23] = PORTA;
  Image[hangshu][24] = PORTA;
  Image[hangshu][25] = PORTA;
  Image[hangshu][26] = PORTA;
  Image[hangshu][27] = PORTA;
  Image[hangshu][28] = PORTA;
  Image[hangshu][29] = PORTA;
  Image[hangshu][30] = PORTA;
  Image[hangshu][31] = PORTA;
  Image[hangshu][32] = PORTA;
  Image[hangshu][33] = PORTA;
  Image[hangshu][34] = PORTA;
  Image[hangshu][35] = PORTA;
  Image[hangshu][36] = PORTA;
  Image[hangshu][37] = PORTA;
  Image[hangshu][38] = PORTA;
  Image[hangshu][39] = PORTA;
  Image[hangshu][40] = PORTA;
  Image[hangshu][41] = PORTA;
  Image[hangshu][42] = PORTA;
  Image[hangshu][43] = PORTA;
  Image[hangshu][44] = PORTA;
  Image[hangshu][45] = PORTA;
  Image[hangshu][46] = PORTA;
  Image[hangshu][47] = PORTA;
  Image[hangshu][48] = PORTA;
  Image[hangshu][49] = PORTA;
  Image[hangshu][50] = PORTA;
  Image[hangshu][51] = PORTA;
  Image[hangshu][52] = PORTA;
  Image[hangshu][53] = PORTA;
  Image[hangshu][54] = PORTA;
  Image[hangshu][55] = PORTA;
  Image[hangshu][56] = PORTA;
  Image[hangshu][57] = PORTA;
  Image[hangshu][58] = PORTA;
  Image[hangshu][59] = PORTA;
  Image[hangshu][60] = PORTA;
  Image[hangshu][61] = PORTA;
  Image[hangshu][62] = PORTA;
  Image[hangshu][63] = PORTA;
  Image[hangshu][64] = PORTA;
  Image[hangshu][65] = PORTA;
  Image[hangshu][66] = PORTA;
  Image[hangshu][67] = PORTA;
  Image[hangshu][68] = PORTA;
  Image[hangshu][69] = PORTA;
  Image[hangshu][70] = PORTA;
  Image[hangshu][71] = PORTA;
  Image[hangshu][72] = PORTA;
  Image[hangshu][73] = PORTA;
  Image[hangshu][74] = PORTA;
  Image[hangshu][75] = PORTA;
  Image[hangshu][76] = PORTA;
  Image[hangshu][77] = PORTA;
  Image[hangshu][78] = PORTA;
  Image[hangshu][79] = PORTA;
  Image[hangshu][80] = PORTA;
  Image[hangshu][81] = PORTA;
  Image[hangshu][82] = PORTA;
  Image[hangshu][83] = PORTA;
  Image[hangshu][84] = PORTA;
  Image[hangshu][85] = PORTA;
  Image[hangshu][86] = PORTA;
  Image[hangshu][87] = PORTA;
  Image[hangshu][88] = PORTA;
  Image[hangshu][89] = PORTA;
  Image[hangshu][90] = PORTA;
  Image[hangshu][91] = PORTA;
  Image[hangshu][92] = PORTA;
  Image[hangshu][93] = PORTA;
  Image[hangshu][94] = PORTA;
  Image[hangshu][95] = PORTA;
  Image[hangshu][96] = PORTA;
  Image[hangshu][97] = PORTA;
  Image[hangshu][98] = PORTA;
  Image[hangshu][99] = PORTA;
  Image[hangshu][100] = PORTA;
  Image[hangshu][101] = PORTA;
  Image[hangshu][102] = PORTA;
  Image[hangshu][103] = PORTA;
  Image[hangshu][104] = PORTA;
  Image[hangshu][105] = PORTA;
  Image[hangshu][106] = PORTA;
  Image[hangshu][107] = PORTA;
  Image[hangshu][108] = PORTA;
  Image[hangshu][109] = PORTA;
  Image[hangshu][110] = PORTA;
  Image[hangshu][111] = PORTA;
  Image[hangshu][112] = PORTA;
  Image[hangshu][113] = PORTA;
  Image[hangshu][114] = PORTA;
  Image[hangshu][115] = PORTA;
  Image[hangshu][116] = PORTA;
  Image[hangshu][117] = PORTA;
  Image[hangshu][118] = PORTA;
  Image[hangshu][119] = PORTA;
    hangshu++;
  }
}
  
interrupt 9 void changzhongduan(void)
{
  TFLG1_C1F = 1; //清场中断
  TFLG1_C0F = 1; //清行中断
  hang = 0; //行计数器
  chang = 1;
   
  
}
#pragma CODE_SEG DEFAULT

1

主题

29

帖子

0

精华

高级会员

Rank: 4

积分
760
威望
383
贡献
249
兑换币
248
注册时间
2013-1-16
在线时间
64 小时
毕业学校
广州大学
2#
 楼主| 发表于 2013-1-29 10:27:52 | 只看该作者
不知道为什么会有几个笑脸,怎么改都改不了,那些笑脸是";p”":p"来的
回复

使用道具 举报

7

主题

85

帖子

0

精华

金牌会员

Rank: 6Rank: 6

积分
1067
威望
569
贡献
310
兑换币
299
注册时间
2012-10-29
在线时间
94 小时
3#
发表于 2013-1-29 11:04:03 | 只看该作者
x2应该是减减,
还有情况考虑的有点少,假如有一边找不到跳变点呢。
回复

使用道具 举报

1

主题

29

帖子

0

精华

高级会员

Rank: 4

积分
760
威望
383
贡献
249
兑换币
248
注册时间
2013-1-16
在线时间
64 小时
毕业学校
广州大学
4#
 楼主| 发表于 2013-1-29 11:07:40 | 只看该作者
心静0189 发表于 2013-1-29 11:04
x2应该是减减,
还有情况考虑的有点少,假如有一边找不到跳变点呢。

刚刚做了一下测试,程序根本就没入中断,我HREF接的是单片机的Pt0,VSYN接的是单片机的PT1,应该没写错吧?但是就是看不到中断发生...
回复

使用道具 举报

7

主题

85

帖子

0

精华

金牌会员

Rank: 6Rank: 6

积分
1067
威望
569
贡献
310
兑换币
299
注册时间
2012-10-29
在线时间
94 小时
5#
发表于 2013-1-29 11:17:51 | 只看该作者
看看摄像头有莫有正常工作。
回复

使用道具 举报

1

主题

29

帖子

0

精华

高级会员

Rank: 4

积分
760
威望
383
贡献
249
兑换币
248
注册时间
2013-1-16
在线时间
64 小时
毕业学校
广州大学
6#
 楼主| 发表于 2013-1-29 11:31:58 | 只看该作者
心静0189 发表于 2013-1-29 11:17
看看摄像头有莫有正常工作。

请问您是用什么看摄像头是不是正常工作的?我试过用示波器看,但是是一堆杂波...按照资料记载,应该是方波才对啊...纠结纠结...
回复

使用道具 举报

7

主题

85

帖子

0

精华

金牌会员

Rank: 6Rank: 6

积分
1067
威望
569
贡献
310
兑换币
299
注册时间
2012-10-29
在线时间
94 小时
7#
发表于 2013-1-29 11:39:11 | 只看该作者
你可以看一下这个

本帖子中包含更多资源

您需要 登录 才可以下载或查看,没有帐号?注册

x
回复

使用道具 举报

1

主题

29

帖子

0

精华

高级会员

Rank: 4

积分
760
威望
383
贡献
249
兑换币
248
注册时间
2013-1-16
在线时间
64 小时
毕业学校
广州大学
8#
 楼主| 发表于 2013-3-7 19:07:22 | 只看该作者
谢谢啦!
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 注册

本版积分规则

关于我们|联系我们|小黑屋|智能车制作 ( 黑ICP备2022002344号

GMT+8, 2024-6-17 02:23 , Processed in 0.053254 second(s), 29 queries , Gzip On.

Powered by Discuz! X3.2

© 2001-2013 Comsenz Inc.

快速回复 返回顶部 返回列表