图像采集程序及其初始化
0赞
发表于 12/9/2011 8:07:16 PM
阅读(15085)
下面就给一下图像采集的程序,图像采集的主函数很少,最重要的是对图功能函数的初始化。
CMOS摄像头采取图像:
#include //BF533 Register Pointer Definition
#include
#include //Interrupt Handling Header
#include
#include
#include "../dm_bf5xx.h"
section ("sdram0_bank1") unsigned char Sensor_Reg[SENSOR_REG_SIZE];
section ("sdram0_bank1") volatile unsigned short VideoInputFrame[PIXEL_PER_LINE][LINES_PER_FRAME];
section ("sdram0_bank1") volatile unsigned short *pDestAddr;
void main()
{
pDestAddr = &VideoInputFrame[0][0];
Init_Platform();
printf( "\nPlatform initialize success!\n" );
init_OV9650();
printf( "\OV9653 initialize success!\n" );
Video_Frame_Capture( (void*) pDestAddr );
while(1);
}
以上就是主函数了,但是这还不够,还要对功能进行初始化。
#include "dm_cmos_i2c.h"
#include "../dm_bf5xx.h"
#include "../dm_types.h"
#include
#include
#include
#include
#define OV9650_ADDRESS 0x60
static i2c_device mcu_i2c;
void init_OV9650(void);
int ov9650_write(uint8_t addr, uint8_t dat);
int ov9650_read(uint8_t addr, uint8_t * buf);
/****************************************************************************
* 名称 :ov9650_write
* 功能 : 写ov9650寄存器函数
****************************************************************************/
int ov9650_write(uint8_t addr, uint8_t dat)
{
int ret = -1;
i2c_start(&mcu_i2c);
//send slave address
if(i2c_write(&mcu_i2c, OV9650_ADDRESS, 1)){
i2c_stop(&mcu_i2c);
return ret;
}
//send sub-address to device
if(i2c_write(&mcu_i2c, addr, 1)){
i2c_stop(&mcu_i2c);
return ret;
}
//send data to device
i2c_write(&mcu_i2c, dat, 1);
i2c_stop(&mcu_i2c);
return 0;
}
/****************************************************************************
* 名称 :ov9650_read
* 功能 : 读ov9650寄存器函数
* 入口参数 :addr:寄存器偏移地址****************************************************************************/
int ov9650_read(uint8_t addr, uint8_t * buf)
{
uint8_t *p = buf;
int ret = -1;
i2c_start(&mcu_i2c);
//send slave address
if(i2c_write(&mcu_i2c, OV9650_ADDRESS, 1)){
i2c_stop(&mcu_i2c);
return ret;
}
//send sub-address of slave
if(i2c_write(&mcu_i2c, addr, 1)){
i2c_stop(&mcu_i2c);
return ret;
}
i2c_stop(&mcu_i2c);
i2c_start(&mcu_i2c);
// send slave address (+1 read mode)
if(i2c_write(&mcu_i2c, OV9650_ADDRESS+1, 1)){
i2c_stop(&mcu_i2c);
return ret;
}
if(i2c_wait_slave(&mcu_i2c, 1000)){
i2c_stop(&mcu_i2c);
return ret;
}
i2c_read(&mcu_i2c, p++, 1); // send ack
i2c_stop(&mcu_i2c);
return 0;
}
/****************************************************************************
* 名称 :Init_OV9650
* 功能 : CMOS 130万 内部寄存器配置信息
****************************************************************************/
void init_OV9650(void)
{
uint8_t i;
*pCtrOut_Flag_A =CMOS_RST ;
ssync(); //复位CMOS SENSOR
*pCtrOut_Flag_A =0x00;
ssync();
mcu_i2c.sclk = PF0; //时钟PF脚
mcu_i2c.sdata = PF1; //数据PF脚
mcu_i2c.low_ns = 7000; //低电平延时 ns
mcu_i2c.high_ns = 6000; //高电平延时 ns
i2c_init(&mcu_i2c);
ov9650_write(0x12,0x80); //reset all register
ov9650_write(0x11,0x81); // PCLK=MCLK F(internal clk)= Finput /2
ov9650_write(0x6b,0x0a);
ov9650_write(0x6a,0x1f);
ov9650_write(0x3b,0x01);
ov9650_write(0x13,0xe0);
ov9650_write(0x01,0x80);
ov9650_write(0x02,0x80);
ov9650_write(0x00,0x00);
ov9650_write(0x10,0x00);
ov9650_write(0x13,0xe5);
ov9650_write(0x39,0x43);
ov9650_write(0x38,0x12);
ov9650_write(0x37,0x00);
ov9650_write(0x35,0x91);
ov9650_write(0x0e,0xa0);
ov9650_write(0x1e,0x04);
ov9650_write(0xA8,0x80);
ov9650_write(0x12,0x10);
ov9650_write(0x04,0x00);
ov9650_write(0x0C,0x04);
ov9650_write(0x0D,0x00);
ov9650_write(0x18,0xc6);
ov9650_write(0x17,0x26);
ov9650_write(0x32,0xAD);
ov9650_write(0x03,0x36);
ov9650_write(0x1A,0x1e);
ov9650_write(0x19,0x00);
ov9650_write(0x3F,0xA6);
ov9650_write(0x14,0x2e);
ov9650_write(0x15,0x02);
ov9650_write(0x41,0x02);
ov9650_write(0x42,0x08);
ov9650_write(0x1B,0x00);
ov9650_write(0x16,0x06);
ov9650_write(0x33,0xE2);
ov9650_write(0x34,0xBF);
ov9650_write(0x96,0x04);
ov9650_write(0x3A,0x00);
ov9650_write(0x8E,0x00);
ov9650_write(0x3C,0x77);
ov9650_write(0x8B,0x06);
ov9650_write(0x94,0x88);
ov9650_write(0x95,0x88);
ov9650_write(0x40,0xC1);
ov9650_write(0x29,0x3F);
ov9650_write(0x0F,0x42);
ov9650_write(0x3D,0x92);
ov9650_write(0x69,0x40);
ov9650_write(0x5C,0xB9);
ov9650_write(0x5D,0x96);
ov9650_write(0x5e,0x10);
ov9650_write(0x59,0xC0);
ov9650_write(0x5A,0xAF);
ov9650_write(0x5B,0x55);
ov9650_write(0x43,0xF0);
ov9650_write(0x44,0x10);
ov9650_write(0x45,0x68);
ov9650_write(0x46,0x96);
ov9650_write(0x47,0x60);
ov9650_write(0x48,0x80);
ov9650_write(0x5F,0xE0);
ov9650_write(0x60,0x8C);
ov9650_write(0x61,0x20);
ov9650_write(0xA5,0xD9);
ov9650_write(0xA4,0x74);
ov9650_write(0x8D,0x02);
ov9650_write(0x13,0xE7);
ov9650_write(0x4F,0x3A);
ov9650_write(0x50,0x3D);
ov9650_write(0x51,0x03);
ov9650_write(0x52,0x12);
ov9650_write(0x53,0x26);
ov9650_write(0x54,0x38);
ov9650_write(0x55,0x40);
ov9650_write(0x56,0x40);
ov9650_write(0x57,0x40);
ov9650_write(0x58,0x0D);
ov9650_write(0x8C,0x23);
ov9650_write(0x3E,0x02);
ov9650_write(0xA9,0xB8);
ov9650_write(0xAA,0x92);
ov9650_write(0xAB,0x0A);
ov9650_write(0x8F,0xDF);
ov9650_write(0x90,0x00);
ov9650_write(0x91,0x00);
ov9650_write(0x9F,0x00);
ov9650_write(0xA0,0x00);
ov9650_write(0x3A,0x01);
ov9650_write(0x24,0x70);
ov9650_write(0x25,0x64);
ov9650_write(0x26,0xC3);
ov9650_write(0x6c,0x40);
ov9650_write(0x6d,0x30);
ov9650_write(0x6e,0x4b);
ov9650_write(0x6f,0x60);
ov9650_write(0x70,0x70);
ov9650_write(0x71,0x70);
ov9650_write(0x72,0x70);
ov9650_write(0x73,0x70);
ov9650_write(0x74,0x60);
ov9650_write(0x75,0x60);
ov9650_write(0x76,0x50);
ov9650_write(0x77,0x48);
ov9650_write(0x78,0x3a);
ov9650_write(0x79,0x2e);
ov9650_write(0x7a,0x28);
ov9650_write(0x7b,0x22);
ov9650_write(0x7c,0x04);
ov9650_write(0x7d,0x07);
ov9650_write(0x7e,0x10);
ov9650_write(0x7f,0x28);
ov9650_write(0x80,0x36);
ov9650_write(0x81,0x44);
ov9650_write(0x82,0x52);
ov9650_write(0x83,0x60);
ov9650_write(0x84,0x6c);
ov9650_write(0x85,0x78);
ov9650_write(0x86,0x8c);
ov9650_write(0x87,0x9e);
ov9650_write(0x88,0xbb);
ov9650_write(0x89,0xd2);
ov9650_write(0x8a,0xe6);
ov9650_write(0x2A,0x10);
ov9650_write(0x2B,0x40);
ov9650_write(0x66,0x01);
ov9650_write(0x64,0x08);
ov9650_write(0x65,0x50);
ov9650_write(0x62,0x00);
ov9650_write(0x63,0x00);
ov9650_write(0x64,0x06);
ov9650_write(0x65,0x40);
ov9650_write(0x9D,0x06);
ov9650_write(0x9E,0x08);
ov9650_write(0x66,0x05);
}