中级会员
积分 367
威望 398
贡献 59
兑换币 0
注册时间 2010-12-29
在线时间 94 小时
5 贡献
我们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 */
}
我来回答