MEGA16+ov7670图像花屏,大神进!!急!!!!
我最近在调试摄像头ov7670模块输出图像,但是总是有问题。想说一下我的架构。然后在阐释问题。架构:我是用ATmega16 单片机控制ov7670进行图像采集的,ov7670的模块是买的现成的,就是ov7670+AL422(FIFO)哪个开发板的。采集图像再经过串口发到上位机,用串口调试工具接收到数据之后,用matlab还原(没有找到合适的软件,那位大神有可以推荐一个,小弟不胜感激)。
结果是:当我采用输出八个彩条时是正常的,见图一。但是当我要输出图像时,就花屏了。具体见图二。我是在是不知道怎么回事了。不知道那位大神能帮小弟解决一下。(对了 我现在的系统是用杜邦线把摄像头连接到单片机系统上的可能会有部分影响,但应该不是我这个问题的根本原因吧)
附上我的程序吧:
main:
void main(void)
{
//uchar i;
uint i,j,k;
uint m;
uint N=0;
uchar fifo_data;
char data,temp;
CLI();
Board_init( ); //初始化开发板
Uart_init(38400); //初始化串口,设置波特率
//Uart_sentstr("开始\r\n"); //发送字符串
Delayms(40);
init_gpio(); //摄像头IO初始化
fifo_init(); //摄像头FIFO初始化
int0_init(); //外部中断0初始化
Delayms(400);
SEI();
VsyncCnt =0;
DDRB=0x00;
fifo_ready =0;
//Uart_sentstr("第一步…\r\n");//发送字符串
while (1) //ov7670初始化
{
if (OV7670_init())
{
break;
}
}
//Uart_sentstr("第一步完成,第二步……\r\n");//发送字符串
while (1)
{ //Uart_sentstr("\r\n第");Uart_sentstr("N");Uart_sentstr("次\r\n");
if ((fifo_ready==1))
{ //Uart_sendB(2);
//fifo_init();
//PORTA&=~BIT(FIFO_RCLK_BIT);//FIFO_RCLK_BIT=0;
//PORTA&=~BIT(FIFO_OE_BIT);//FIFO_OE_BIT=0;
FIFO_RRST_L; //读指针复位
FIFO_RCLK_L; //至少需要一个时钟周期的跳变才能复位
FIFO_RCLK_H;
FIFO_RCLK_L; //至少需要一个时钟周期的跳变才能复位
FIFO_RCLK_H;
FIFO_RRST_H;
FIFO_OE_L; //必须在读指针复位后使能OE和RE才能从
//0地址读数据,硬件已将OE和RE连在一起
for (i=0;i<240;i++)//120
{
for (j=0;j<320;j++)//160
{
//for(k=0;k<2;k++)
//{
/*PORTA|=BIT(FIFO_RCLK_BIT);//FIFO_RCLK_BIT=1;
;;;;;;;;//for(m=0;m<8;m++) ;//自己添加测试
fifo_data=FIFO_DATA_PIN;
//Uart_sendB(3); //测试
//if(k==0)
// {
/*if(fifo_data>122)
{fifo_data=255;}
else
{fifo_data=0; }//二值化
*/
//fifo_data = (fifo_data & 0xf0);
//if(k==0)
//{
/*Uart_sendB(fifo_data);//发送底八位,灰度值
//}
//}
PORTA&=~BIT(FIFO_RCLK_BIT); //FIFO_RCLK_BIT=0;
;;;;;;;;*/
//delay_us(1000);
FIFO_RCLK_L;
FIFO_RCLK_H;
data = FIFO_DATA_PIN;
//data <<= 8; //先读高位
Uart_sendB(data);
FIFO_RCLK_L;
FIFO_RCLK_H;
temp = FIFO_DATA_PIN;//再读低位
Uart_sendB(temp);
//}
}
}
FIFO_OE_H; //关闭读使能,同时数据口为高阻态
FIFO_WEN_L; //按照手册上说明,复位时WEN要置高,但
FIFO_WRST_L; //MCU的WEN和HREF是做与非逻辑后再输入
NOP(); //到AL422B的,所以MCU的WEN置低则输出
NOP(); //到422的WEN一定为低
NOP(); //写指针复位需要一定的延时
FIFO_WRST_H;
VsyncCnt = 0; //开始下一帧数据采集
//VsyncCnt =0;
GICR|=0b01000000; //开启int0中断
//rec_flag=0;
//while (rec_flag==0);
}
N++;
break;
}
}
我的寄存器设置为:
{0x3a, 0x04},
{0x12, 0x14},
//{0x40, 0xd0},
//RGB555/565 option(must set COM7 = 1 and COM7 = 0)
{0x40, 0xd0},//RGB565,effective only when RGB444 is low
{0x8c, 0x00},
{0x32, 0x80},
{0x17, 0x16},
{0x18, 0x04},
{0x19, 0x02},
{0x1a, 0x7b},//0x7a,
{0x03, 0x06},//0x0a,
{0x0c, 0x00},
{0x3e, 0x00},//PCLK 分频0011
{0x6b, 0x0a},//PLL 8000
{0x70, 0x00},//00
{0x71, 0x00},//0x85测试
//{0x42, 0x08},
{0x72, 0x11},
{0x73, 0x00},//pclk 设置 00 01
{0xa2, 0x02},
{0x11, 0x80},//clkrc内部时钟80
{0x7a, 0x20},
{0x7b, 0x1c},
{0x7c, 0x28},
{0x7d, 0x3c},
{0x7e, 0x55},
{0x7f, 0x68},
{0x80, 0x76},
{0x81, 0x80},
{0x82, 0x88},
{0x83, 0x8f},
{0x84, 0x96},
{0x85, 0xa3},
{0x86, 0xaf},
{0x87, 0xc4},
{0x88, 0xd7},
{0x89, 0xe8},
{0x13, 0xe0},
{0x00, 0x00},//AGC
{0x10, 0x00},
{0x0d, 0x00},
{0x14, 0x20},//0x38, limit the max gain
{0xa5, 0x05},
{0xab, 0x07},
{0x24, 0x75},
{0x25, 0x63},
{0x26, 0xA5},
{0x9f, 0x78},
{0xa0, 0x68},
{0xa1, 0x03},//0x0b,
{0xa6, 0xdf},//0xd8,
{0xa7, 0xdf},//0xd8,
{0xa8, 0xf0},
{0xa9, 0x90},
{0xaa, 0x94},
{0x13, 0xe5},
{0x0e, 0x61},
{0x0f, 0x4b},
{0x16, 0x02},
{0x1e, 0x37},//0x07,
{0x21, 0x02},
{0x22, 0x91},
{0x29, 0x07},
{0x33, 0x0b},
{0x35, 0x0b},
{0x37, 0x1d},
{0x38, 0x71},
{0x39, 0x2a},//
{0x3c, 0x78},
{0x4d, 0x40},
{0x4e, 0x20},
{0x69, 0x0c},///////////////////////
{0x74, 0x19},
{0x8d, 0x4f},
{0x8e, 0x00},
{0x8f, 0x00},
{0x90, 0x00},
{0x91, 0x00},
{0x92, 0x00},//0x19,//0x66
{0x96, 0x00},
{0x9a, 0x80},
{0xb0, 0x84},
{0xb1, 0x0c},
{0xb2, 0x0e},
{0xb3, 0x82},
{0xb8, 0x0a},
{0x43, 0x14},
{0x44, 0xf0},
{0x45, 0x34},
{0x46, 0x58},
{0x47, 0x28},
{0x48, 0x3a},
{0x59, 0x88},
{0x5a, 0x88},
{0x5b, 0x44},
{0x5c, 0x67},
{0x5d, 0x49},
{0x5e, 0x0e},
{0x64, 0x04},
{0x65, 0x20},
{0x66, 0x05},
{0x94, 0x04},
{0x95, 0x08},
{0x6c, 0x0a},
{0x6d, 0x55},
{0x6e, 0x11},
{0x6f, 0x9f},//0x9e for advance AWB
{0x6a, 0x00},
{0x01, 0x80},
{0x02, 0x80},
{0x13, 0xe7},
{0x15, 0x02},//
{0x4f, 0x80},
{0x50, 0x80},
{0x51, 0x00},
{0x52, 0x22},
{0x53, 0x5e},
{0x54, 0x80},
{0x58, 0x9e},
{0x41, 0x08},
{0x3f, 0x00},
{0x75, 0x05},
{0x76, 0xe1},
{0x4c, 0x00},
{0x77, 0x01},
{0x3d, 0xc2}, //0xc0,
{0x4b, 0x09},
{0xc9, 0x60},
{0x41, 0x38},
{0x56, 0x40},//0x40,change according to Jim's request
{0x34, 0x11},
{0x3b, 0x02},//0x00,//0x02,
{0xa4, 0x89},//0x88,
{0x96, 0x00},
{0x97, 0x30},
{0x98, 0x20},
{0x99, 0x30},
{0x9a, 0x84},
{0x9b, 0x29},
{0x9c, 0x03},
{0x9d, 0x4c},
{0x9e, 0x3f},
{0x78, 0x04},
{0x79, 0x01},
{0xc8, 0xf0},
{0x79, 0x0f},
{0xc8, 0x00},
{0x79, 0x10},
{0xc8, 0x7e},
{0x79, 0x0a},
{0xc8, 0x80},
{0x79, 0x0b},
{0xc8, 0x01},
{0x79, 0x0c},
{0xc8, 0x0f},
{0x79, 0x0d},
{0xc8, 0x20},
{0x79, 0x09},
{0xc8, 0x80},
{0x79, 0x02},
{0xc8, 0xc0},
{0x79, 0x03},
{0xc8, 0x40},
{0x79, 0x05},
{0xc8, 0x30},
{0x79, 0x26},
{0x09, 0x03},
{0x55, 0x00},
{0x56, 0x40},
{0x3b, 0xC2},//0x82,//0xc0,//0xc2, //night mode
其他的程序是采用现成的,所以应该没有什么问题。
真心求解啊!!!!!!!!!!!!!!!!!!!!!! 花的很有规律。很规整。硬件似乎没问题吧。
哪儿笔误了吧。 我觉得硬件应该没有问题,否则我彩条不可能出来。但问题是就是照相不出图像。所以向找牛人帮我看看程序那里有问题。 液晶屏上有没有写明响应时间,图像更新过快也会花屏的
页:
[1]