智能车制作
标题:
摄像头采集问题
[打印本页]
作者:
sunzhaoxing2012
时间:
2013-3-17 20:54
标题:
摄像头采集问题
摄像头采集来的图像,一行图像正确,再下一行图像就全黑,再一行正确,再一行错误,这样循环,试问我的程序错在哪了,跪求赐教。(不知怎么回事,图传不上去)
#include <hidef.h>
#include "derivative.h"
#include <MC9S12XS128.h>
#define row 40 //定义图像采集行数:40行
#define column 130 //定义图像采集列数:120列
#define Interval 6 //采集有效行数间隔
unsigned char Image_Data[row][column]; //图像数组
unsigned char image_number=0; // 场数统计值
unsigned int row_number=0; // 行数统计值
unsigned int column_number=0; // 列数统计值
unsigned char row_count = 0;
/*---------------------------------------------------
总线频率设定
----------------------------------------------------*/
void SetBusCLK_88M(void)
{
CLKSEL=0X00; //disengage PLL to system
PLLCTL_PLLON=1; //turn on PLL
SYNR =0xc0 | 0x0a;
REFDV=0x80 | 0x01;
POSTDIV=0x00; //pllclock=2*osc*(1+SYNR)/(1+REFDV)=176MHz;
_asm(nop); //BUS CLOCK=88M
_asm(nop);
while(!(CRGFLG_LOCK==1)); //when pll is steady ,then use it;
CLKSEL_PLLSEL =1; //engage PLL to system;
}
/*-----------------------------------------------------
TIM输入捕捉模块初始化
-------------------------------------------------------*/
void TIM_Init(void)
{
TIOS =0x00; //定时器通道0,1 为输入捕捉
TSCR1=0x80; //定时器使能
TCTL4=0x09; //通道0 捕捉上升沿通道1 捕捉下降沿
TIE=0x03; //通道0,1 中断使能
TFLG1=0xFF; //清中断标志位
}
/*--------------------------------------------------------
SCI0初始化函数
----------------------------------------------------------*/
void SCI0_Init()
{
SCI0BDL = 48; // 设定波特率为115200
SCI0CR1 = 0X00;
SCI0CR2 = 0X0C;
}
/*---------------------------------------------------
串口发射端程序
-----------------------------------------------------*/
void SCI0_Transmit(void)
{
byte temp;
unsigned char i,j;
temp = SCI0SR1; //清零
SCI0DRH = 0; //高八位清零
SCI0DRL = 0X00; //上位机数据头
while (!(SCI0SR1&0x80));
SCI0DRL = 0XFF;
while (!(SCI0SR1&0x80));
SCI0DRL = 0X01;
while (!(SCI0SR1&0x80));
SCI0DRL = 0X00;
while (!(SCI0SR1&0x80));
for(i = 0;i< row;i++) //发送数据
{
for(j = 0;j < column ;j++)
{
SCI0DRL = Image_Data[i][j];
while (!(SCI0SR1&0x80));
}
}
}
/*-----------------------------------------------------
main
------------------------------------------------------*/
void main(void)
{
DisableInterrupts;
DDRA = 0X00; // PORTA为输入模式
DDRB = 0xFF; // PORTB为输出模式
PORTB= 0xFF; // PORTB用于标示
SetBusCLK_88M();
SCI0_Init();
TIM_Init();
EnableInterrupts;
for(;;)
{
if(image_number==0)
{
SCI0_Transmit();
EnableInterrupts;
PORTB = ~PORTB; //指示程序运行
}
}
}
//---------------------中断定义---------------------
#pragma CODE_SEG NON_BANKED
/*-------------------------------------------------------
行中断处理函数
--------------------------------------------------------*/
interrupt 8 void HREF_Count(void)
{
TFLG1_C0F = 1;
row_count++;
if(image_number) {
if(row_count%Interval==0)
{
for(column_number=0;column_number<130;column_number++)
{
Image_Data[row_number][column_number] = PORTA;
// _asm(); _asm();
}
if(row_count==240) {
image_number=0;
DisableInterrupts;
}
}
row_number++;
}
}
/*---------------------------------------------------
场中断处理函数
----------------------------------------------------*/
interrupt 9 void VSYN_Interrupt(void)
{
TFLG1_C1F = 1; //清场中断
TFLG1_C0F = 1; //清行中断
row_number = 0; //行计数器清零
image_number=1; //场标志位为一
}
#pragma CODE_SEG DEFAULT
作者:
happyzn75
时间:
2013-5-28 19:49
88M 不会出错才怪
欢迎光临 智能车制作 (http://dns.znczz.com/)
Powered by Discuz! X3.2