智能车制作

标题: 我们XS128采集的7620的图像的问题,求助! [打印本页]

作者: xinchen    时间: 2012-4-8 14:44
标题: 我们XS128采集的7620的图像的问题,求助!
我们7620摄像头发回的数据怎么全是1或者全是0?摄像头移动了数据也没变化。如果不二值化,发挥的数据全是50 70这些……附上源代码
#include <hidef.h> /* common defines and macros */
#include "derivative.h" /* derivative-specific definitions */
#include <MC9S12XS128.h>
//-----------函数声明-----------------//
void IOC_Contrl(void);
void SCI0_Transmit(void);

#define COLUMN  120
unsigned char Image_Data[38][COLUMN];
unsigned char Point_C, VSYN_C, Line_Flag, m = 0,n=0;
unsigned int Line_C=0;
unsigned char Interval;
unsigned char  THRESHOLD=0x20;
/***************************************************
** 函数名称: PLL_Init
** 功能描述: 时钟初始化函数
** 说明: 48mhz
****************************************************/
void PLL_Init(void)
{
  CLKSEL=0x00;
  PLLCTL_PLLON=1;
  SYNR=0XC0 | 0X05;
  REFDV=0X80 | 0X01;
  POSTDIV=0X00;
  _asm(nop);
  _asm(nop);             //_asm(nop);
  while(0==CRGFLG_LOCK); //锁相环锁定
  CLKSEL_PLLSEL=1; //选定PLL时钟
}
/***************************************************
** 函数名称: TIM_Init
** 功能描述: 行场中断初始化函数
** 说明:
****************************************************/
void TIM_Init(void)
{
TIOS =0x00;        //定时器通道0,1 为输入捕捉
TSCR1=0x80;        //定时器使能
TCTL4=0x09;        //通道0 捕捉上升沿,通道1 捕捉下降沿
TIE=0x03;          //通道0,1 中断使能
TFLG1=0xFF;        //清中断标志位
}
/***************************************************
** 函数名称: SCI0_Init
** 功能描述: 串口0初始化函数
** 说明:
****************************************************/
void SCI0_Init()
{
SCI0BD = 312;                                        //9600bps,Baud Rate=BusClock/(16*SCIBD)
SCI0CR1 = 0X00;                                      /*normal,no parity正常8 位模式,无奇偶校验*/
SCI0CR2 = 0X2C;                                      /*RIE=1,TE=1,RE=1, */
}
//---------------------中断定义---------------------
#pragma CODE_SEG NON_BANKED
/**************************************************
** 函数名称: 中断处理函数
** 功能描述: 行中断处理函数
** 输    入: 无
** 输    出: 无
** 说明:捕捉上升沿  
***************************************************/
interrupt 8 void HREF_Count(void)
{
  TFLG1_C0F = 1;
  Line_Flag = 0;
  m++;
  if ( m<12 || m>288 )
  {
    return;//判断是否从新的一场开始
  }
  if(m<=132)              Interval=12;
  else if(m>132&&m<=200)  Interval=8;
  else if(m>200&&m<=248)  Interval=6;
  else                    Interval=4;
  if(m%Interval==0)
  {
    IOC_Contrl();
    SCI0_Transmit();
    Line_C++;
  }
}
/**************************************************
** 函数名称: 中断处理函数
** 功能描述: 场中断处理函数
** 输    入: 无
** 输    出: 无
** 说明:  捕捉下降沿
***************************************************/
interrupt 9 void VSYN_Interrupt(void)
{
  TFLG1_C1F = 1; //清场中断
  TFLG1_C0F = 1; //清行中断
  Point_C = 0;
  Line_C = 0; //行计数器
  VSYN_C++;
  
  SCI0DRL = 0X0A;       //换行
  while (!(SCI0SR1&0x80));
  SCI0DRL = 0X0D;       //回车
  while (!(SCI0SR1&0x80));
  
  
}
#pragma CODE_SEG DEFAULT
/**************************************************
** 函数名称: 串口发射端程序
** 功能描述: 发送赛道信息 1为黑线 0为白板
** 输    入: 无
** 输    出: 无
** 说明:  
***************************************************/
void SCI0_Transmit(void)
{
  byte i, temp;
  temp = SCI0SR1;
  SCI0DRH = 0;    //清零
  for(i = 0;i < COLUMN ;i++)
  {
    if(Image_Data[Line_C][i]>0x34 && Image_Data[Line_C][i+1]>0x34 && Image_Data[Line_C][i-1]>0x34)  SCI0DRL = 0x30;
    else SCI0DRL = 0X31;    //黑线
    while (!(SCI0SR1&0x80));
  }
  
  SCI0DRL = 0X0A;           //换行
  while (!(SCI0SR1&0x80));
  SCI0DRL = 0X0D;           //回车
  while (!(SCI0SR1&0x80));
}
/**************************************************
** 函数名称: 图像灰度值采集
** 功能描述: 采集像素值
** 输    入: 无
** 输    出: 无
** 说明:  
***************************************************/
void IOC_Contrl(void)
{
Image_Data[Line_C][0] = PORTA;
Image_Data[Line_C][1] = PORTA;
Image_Data[Line_C][2] = PORTA;
Image_Data[Line_C][3] = PORTA;
Image_Data[Line_C][4] = PORTA;
Image_Data[Line_C][5] = PORTA;
Image_Data[Line_C][6] = PORTA;
Image_Data[Line_C][7] = PORTA;
Image_Data[Line_C][8] = PORTA;
Image_Data[Line_C][9] = PORTA;
Image_Data[Line_C][10] = PORTA;
Image_Data[Line_C][11] = PORTA;
Image_Data[Line_C][12] = PORTA;
Image_Data[Line_C][13] = PORTA;
Image_Data[Line_C][14] = PORTA;
Image_Data[Line_C][15] = PORTA;
Image_Data[Line_C][16] = PORTA;
Image_Data[Line_C][17] = PORTA;
Image_Data[Line_C][18] = PORTA;
Image_Data[Line_C][19] = PORTA;
Image_Data[Line_C][20] = PORTA;
Image_Data[Line_C][21] = PORTA;
Image_Data[Line_C][22] = PORTA;
Image_Data[Line_C][23] = PORTA;
Image_Data[Line_C][24] = PORTA;
Image_Data[Line_C][25] = PORTA;
Image_Data[Line_C][26] = PORTA;
Image_Data[Line_C][27] = PORTA;
Image_Data[Line_C][28] = PORTA;
Image_Data[Line_C][29] = PORTA;
Image_Data[Line_C][30] = PORTA;
Image_Data[Line_C][31] = PORTA;
Image_Data[Line_C][32] = PORTA;
Image_Data[Line_C][33] = PORTA;
Image_Data[Line_C][34] = PORTA;
Image_Data[Line_C][35] = PORTA;
Image_Data[Line_C][36] = PORTA;
Image_Data[Line_C][37] = PORTA;
Image_Data[Line_C][38] = PORTA;
Image_Data[Line_C][39] = PORTA;
Image_Data[Line_C][40] = PORTA;
Image_Data[Line_C][41] = PORTA;
Image_Data[Line_C][42] = PORTA;
Image_Data[Line_C][43] = PORTA;
Image_Data[Line_C][44] = PORTA;
Image_Data[Line_C][45] = PORTA;
Image_Data[Line_C][46] = PORTA;
Image_Data[Line_C][47] = PORTA;
Image_Data[Line_C][48] = PORTA;
Image_Data[Line_C][49] = PORTA;
Image_Data[Line_C][50] = PORTA;
Image_Data[Line_C][51] = PORTA;
Image_Data[Line_C][52] = PORTA;
Image_Data[Line_C][53] = PORTA;
Image_Data[Line_C][54] = PORTA;
Image_Data[Line_C][55] = PORTA;
Image_Data[Line_C][56] = PORTA;
Image_Data[Line_C][57] = PORTA;
Image_Data[Line_C][58] = PORTA;
Image_Data[Line_C][59] = PORTA;
Image_Data[Line_C][60] = PORTA;
Image_Data[Line_C][61] = PORTA;
Image_Data[Line_C][62] = PORTA;
Image_Data[Line_C][63] = PORTA;
Image_Data[Line_C][64] = PORTA;
Image_Data[Line_C][65] = PORTA;
Image_Data[Line_C][66] = PORTA;
Image_Data[Line_C][67] = PORTA;
Image_Data[Line_C][68] = PORTA;
Image_Data[Line_C][69] = PORTA;
Image_Data[Line_C][70] = PORTA;
Image_Data[Line_C][71] = PORTA;
Image_Data[Line_C][72] = PORTA;
Image_Data[Line_C][73] = PORTA;
Image_Data[Line_C][74] = PORTA;
Image_Data[Line_C][75] = PORTA;
Image_Data[Line_C][76] = PORTA;
Image_Data[Line_C][77] = PORTA;
Image_Data[Line_C][78] = PORTA;
Image_Data[Line_C][79] = PORTA;
Image_Data[Line_C][80] = PORTA;
Image_Data[Line_C][81] = PORTA;
Image_Data[Line_C][82] = PORTA;
Image_Data[Line_C][83] = PORTA;
Image_Data[Line_C][84] = PORTA;
Image_Data[Line_C][85] = PORTA;
Image_Data[Line_C][86] = PORTA;
Image_Data[Line_C][87] = PORTA;
Image_Data[Line_C][88] = PORTA;
Image_Data[Line_C][89] = PORTA;
Image_Data[Line_C][90] = PORTA;
Image_Data[Line_C][91] = PORTA;
Image_Data[Line_C][92] = PORTA;
Image_Data[Line_C][93] = PORTA;
Image_Data[Line_C][94] = PORTA;
Image_Data[Line_C][95] = PORTA;
Image_Data[Line_C][96] = PORTA;
Image_Data[Line_C][97] = PORTA;
Image_Data[Line_C][98] = PORTA;
Image_Data[Line_C][99] = PORTA;
Image_Data[Line_C][100] = PORTA;
Image_Data[Line_C][101] = PORTA;
Image_Data[Line_C][102] = PORTA;
Image_Data[Line_C][103] = PORTA;
Image_Data[Line_C][104] = PORTA;
Image_Data[Line_C][105] = PORTA;
Image_Data[Line_C][106] = PORTA;
Image_Data[Line_C][107] = PORTA;
Image_Data[Line_C][108] = PORTA;
Image_Data[Line_C][109] = PORTA;
Image_Data[Line_C][110] = PORTA;
Image_Data[Line_C][111] = PORTA;
Image_Data[Line_C][112] = PORTA;
Image_Data[Line_C][113] = PORTA;
Image_Data[Line_C][114] = PORTA;
Image_Data[Line_C][115] = PORTA;
Image_Data[Line_C][116] = PORTA;
Image_Data[Line_C][117] = PORTA;
Image_Data[Line_C][118] = PORTA;
Image_Data[Line_C][119] = PORTA;
}

/***************************************************
** 函数名称: main
** 功能描述: 主函数
** 说明:
****************************************************/  
void main(void)
{
/* put your own code here */
  DisableInterrupts;
  DDRA = 0X00;
  PLL_Init();
  SCI0_Init();
  TIM_Init();
  EnableInterrupts;
  for(;;)
  {
  //_FEED_COP(); /* feeds the dog */
  } /* loop forever */
/* please make sure that you never leave main */
}

作者: kotami    时间: 2012-5-1 11:11
LZ。。。。。串口数据传输函数为何要放在行中断里呢???
作者: xinmengwangran    时间: 2012-5-1 12:24
SCI0_Transmit();
这个放到主函数中试一试!
作者: xinmengwangran    时间: 2012-5-1 12:31
SCI0_Transmit();
这个放到主函数中试一试!
作者: 赵仁煊    时间: 2012-5-16 20:11
kotami 发表于 2012-5-1 11:11
LZ。。。。。串口数据传输函数为何要放在行中断里呢???

放行中断可以立即才处理数据吧!放主函数,有没有滞后,图像不真实。可不可以贴下你的串口程序,研究下。谢谢!
作者: 赵仁煊    时间: 2012-5-16 20:14
xinmengwangran 发表于 2012-5-1 12:31
SCI0_Transmit();
这个放到主函数中试一试!

可不可以贴个串口的程序,谢谢了!

作者: 林牛牛    时间: 2012-5-16 22:09
这个程序的DENOK工作室的例程,参考源例程就可以,可以找DEMOK工作室拿拿看。。
作者: xinmengwangran    时间: 2012-5-17 07:01
本帖最后由 xinmengwangran 于 2012-5-17 07:02 编辑
赵仁煊 发表于 2012-5-16 20:14
可不可以贴个串口的程序,谢谢了!

/*****串口初始化*****/
/**/void InitCom()
{
SCI0BD=(uint)(128000000UL/16/9600/2);//budclk=64M,9600bps
SCI0CR1=0;   //普通操作使能"等待模式"  传输为8个数 据位 一个停止位 无校验
SCI0CR2=0x0c;  //使能发送和接收器 开接收中断使能 关发送中断
}
/*****串口发送*****/

void SendChar( char text)/**/
{   
while (!(SCI0SR1&0x80));
  SCI0DRH=0;
  SCI0DRL =text;
}



作者: 赵仁煊    时间: 2012-5-17 15:11
xinmengwangran 发表于 2012-5-17 07:01
/*****串口初始化*****/
/**/void InitCom()
{

谢谢,已经解决了!
作者: xinmengwangran    时间: 2012-5-17 18:05
o  呵呵 那就好
作者: xinmengwangran    时间: 2012-5-17 18:05
赵仁煊 发表于 2012-5-17 15:11
谢谢,已经解决了!

哦 呵呵 那就好

作者: 赵仁煊    时间: 2012-5-18 08:53
xinmengwangran 发表于 2012-5-17 18:05
哦 呵呵 那就好

谢谢!
作者: 寒路独行、    时间: 2012-5-18 16:49
赵仁煊 发表于 2012-5-17 15:11
谢谢,已经解决了!

请教楼主是怎么解决的,貌似我的小车也是这样,无论拍什么传回来的数据都不会变。

作者: czrushman    时间: 2012-5-18 17:40
赵仁煊 发表于 2012-5-17 15:11
谢谢,已经解决了!

是什么情况?

作者: schullar    时间: 2012-7-28 11:19
采集到的图像不在中间,好像是左上角的
作者: Roy罗先森    时间: 2012-10-30 20:14
怎么解决的呀,我也出现了同样的问题
作者: Roy罗先森    时间: 2012-10-30 20:51
xinmengwangran 发表于 2012-5-1 12:31
SCI0_Transmit();
这个放到主函数中试一试!

我也出现了同上面一样的问题,但是当我把摄像头盖住的时候,发生了明显的变化,也就是说采集到啦数据,但是呢,对于7620的行消隐的精确时间是多少,我不知道,你可以帮我解决一下吗?




欢迎光临 智能车制作 (http://dns.znczz.com/) Powered by Discuz! X3.2