|
我在网上搜了一下OV7660,有网页介绍初始化如下:
Gamma校正
7670
OV7660 的设置 2009-06-25 14:58
分类:图像处理 字号: 大大 中中 小小 OV7660 的设置
2008年11月01日 星期六 下午 07:23
//----------------------------------------------------------
//
// FILE NAME : ov7660.c
// TARGET DEVICE : atmage128
// CREATED ON : 2008-09-10
// CREATED BY : dzrjojo
//
//
typedef struct
{
uint8_t need;
uint8_t addr;
uint8_t data;
} OV_reg_t;
static OV_reg_t ov_reg[]={
{ 0 , 0x00 , 0x00 },
{ 0 , 0x01 , 0x80 },
{ 0 , 0x02 , 0x80 },
{ 0 , 0x03 , 0x00 }, //default : 0x00 ; //V窗口
{ 0 , 0x04 , 0x00 }, //default : 0x00
{ 0 , 0x05 , 0x00 },
{ 0 , 0x06 , 0x00 },
{ 0 , 0x07 , 0x00 },
{ 0 , 0x08 , 0x00 },
{ 0 , 0x09 , 0x01 },
{ 0 , 0x0c , 0x00 }, //?
{ 0 , 0x0d , 0x40 },
{ 0 , 0x0e , 0x04 }, //default : 0x01 ; -0x04 for nothing
{ 0 , 0x0f , 0x62 }, //default : 0x43 ; -0x62 for disable ADBLC//black level calibration
{ 0 , 0x10 , 0x40 },
{ 1 , 0x11 , 0x40 }, //default : 0x00 ; 0x40 for external clock
{ 1 , 0x12 , 0x10 }, //default : 0x00 ; 0x10 for QVGA ;0x08 for QCIF//
{ 1 , 0x13 , 0x8f }, //default : 0x8f ; -0x40 for disable fast agc/aec & step size = aec & agc=1,awb=0,aec=0// -0xce for disable aec
{ 0 , 0x14 , 0x48 }, //default : 0x4a ; ?-0x78 for maxAGC & disable drop frame
{ 0 , 0x15 , 0x40 }, //default : 0x00 ; ?-0x40 for href changes to hsync //更改则不工作
{ 0 , 0x17 , 0x11 }, //default : 0x11 for HStart=140; 0x00 for HSTART = 0 //HStart窗口
{ 0 , 0x18 , 0x39 }, //default : 0x61 for HStop=780; 0x28 for HSTOP = 320 ;0x50 for 640 ;0x39 for HStop=460 for 320//HStop窗口
{ 0 , 0x19 , 0x02 }, //default : 0x02 for VStart=16; 0x00 for VSTART = 0 //VStart窗口
{ 0 , 0x1a , 0x3e }, //default : 0x7a for VStop=976; 0x3c for VSTOP = 240 ;0x1e for 240 ;0x3e for VStop=496 for 240//VStop窗口
{ 1 , 0x1b , 0x01 }, //default : 0x00 ; -0x01 for pixel delay select
{ 0 , 0x1e , 0x30 }, //default : 0x00 ; -0x01 for nothing ; -0x20 for Hmirror -0x30 for HVmirror
{ 0 , 0x20 , 0x80 },
{ 0 , 0x21 , 0x80 },
{ 0 , 0x22 , 0x80 },
{ 0 , 0x23 , 0x80 },
{ 0 , 0x24 , 0x78 },
{ 0 , 0x25 , 0x68 },
{ 0 , 0x26 , 0xd4 },
{ 0 , 0x27 , 0x80 },
{ 0 , 0x28 , 0x80 },
{ 0 , 0x29 , 0x20 }, //RSVD for nothing
{ 0 , 0x2a , 0x00 },
{ 0 , 0x2b , 0x00 },
{ 0 , 0x2c , 0x80 },
{ 0 , 0x2d , 0x00 },
{ 0 , 0x2e , 0x00 },
{ 0 , 0x2f , 0x00 },
{ 0 , 0x30 , 0x08 },
{ 0 , 0x31 , 0x30 },
{ 0 , 0x32 , 0xa4 }, //default : 0xa4=0b10 100 100 ; 0b 10 000 000 for 640//H窗口
{ 0 , 0x33 , 0x00 }, //CHLF for noting
{ 0 , 0x34 , 0x07 }, //default : 0x03 ; 0x07 for nothing
{ 0 , 0x35 , 0x84 }, //RSVD for nothing
{ 0 , 0x36 , 0x00 }, //RSVD for nothing
{ 0 , 0x37 , 0x04 },
{ 0 , 0x38 , 0x13 }, //default : 0x12 ; -0x13 for nothing
{ 0 , 0x39 , 0x43 }, //default : 0x00 ; ?-0x43 for line buffer power down(set to 1 before chip power down) //影响亮度
{ 0 , 0x3a , 0x0c }, //default : 0x0c ; -0x04 for YVYU //应该是0x0c for UYVY
{ 1 , 0x3b , 0xa0 }, //default : 0x00 ; 0xa0 for night mode //有效果
{ 0 , 0x3c , 0x68 }, //default : 0x40 ; -0x68 for nothing
{ 0 , 0x3d , 0x19 }, //default : 0x99 ; -0x19 for disallow gamma-signal //影响不大
{ 0 , 0x3e , 0x0e },
{ 0 , 0x3f , 0x88 },
{ 0 , 0x40 , 0xc1 }, //default : 0xc0 ; -0xc1 for nothing
{ 0 , 0x41 , 0x10 },
{ 0 , 0x42 , 0x08 },
{ 0 , 0x4f , 0x58 },
{ 0 , 0x50 , 0x48 },
{ 0 , 0x51 , 0x10 },
{ 0 , 0x52 , 0x28 },
{ 0 , 0x53 , 0x48 },
{ 0 , 0x54 , 0x70 },
{ 0 , 0x55 , 0x40 },
{ 0 , 0x56 , 0x40 },
{ 0 , 0x57 , 0x40 },
{ 0 , 0x58 , 0x0f },
{ 0 , 0x62 , 0x80 }, //default : 0x00 ; -lens1 = 0x80
{ 0 , 0x63 , 0x80 }, //default : 0x00 ; -lens2 = 0x80
{ 0 , 0x64 , 0x09 }, //default : 0x10 ; -lens3 = 0x09
{ 0 , 0x65 , 0x80 }, //default : 0x80 ; -lens4 = 0x10
{ 0 , 0x66 , 0x01 }, //default : 0x00 ; -0x01 for lens correction enable
{ 0 , 0x67 , 0x80 },
{ 0 , 0x68 , 0x80 },
{ 0 , 0x69 , 0x80 }, //default : 0x00 ; -0x80 for B channel pre-gain
{ 0 , 0x6b , 0x0a }, //default : 0x3a ; -0x0a for notihing
{ 0 , 0x92 , 0x00 },
{ 0 , 0x93 , 0x00 },
{ 0 , 0x9d , 0x99 },
{ 0 , 0x9e , 0x7f },
{ 0 , 0xa0 , 0x00 },
{ 0xff , 0 , 0x00 }
};
//(140,16,640,480) is good for VGA
//(272,16,320,240) is good for QVGA
void OV7660_config_window(uint16_t startx,uint16_t starty,uint16_t width, uint16_t height)
{
uint16_t endx=(startx+width);
uint16_t endy=(starty+height*2);// "v*2"必须
uint8_t temp_reg1, temp_reg2;
uint8_t state,temp;
state = TWI_poll( TWI_CHIP_OV7660|TWI_READ, 0x03, &temp_reg1 );
temp_reg1 &= 0xC0;
state = TWI_poll( TWI_CHIP_OV7660|TWI_READ, 0x32, &temp_reg2 );
temp_reg2 &= 0xC0;
// Horizontal
temp = 0x80|((endx&0x7)<<3)|(startx&0x7);
state = TWI_poll( TWI_CHIP_OV7660|TWI_WRITE, 0x32, &temp );
temp = (startx&0x7F8)>>3;
state = TWI_poll( TWI_CHIP_OV7660|TWI_WRITE, 0x17, &temp );
temp = (endx&0x7F8)>>3;
state = TWI_poll( TWI_CHIP_OV7660|TWI_WRITE, 0x18, &temp );
// Vertical
temp = temp_reg1|((endy&0x7)<<3)|(starty&0x7);
state = TWI_poll( TWI_CHIP_OV7660|TWI_WRITE, 0x03, &temp );
temp = (starty&0x7F8)>>3;
state = TWI_poll( TWI_CHIP_OV7660|TWI_WRITE, 0x19, &temp );
temp = (endy&0x7F8)>>3;
state = TWI_poll( TWI_CHIP_OV7660|TWI_WRITE, 0x1A, &temp );
} /* config_OV7660_window */
uint8_t OV7660_init(void)
{
uint8_t temp;
uint8_t i;
uint8_t ovidmsb;
uint8_t ovidlsb;
temp=0x80;
TWI_poll( TWI_CHIP_OV7660|TWI_WRITE, 0x12, &temp); //Reset SCCB
my_delay_ms(100);
TWI_poll( TWI_CHIP_OV7660|TWI_READ, 0x0a, &ovidmsb );
if(ovidmsb !=0x76)
return ovidmsb;
TWI_poll( TWI_CHIP_OV7660|TWI_READ, 0x0b, &ovidlsb );
if(ovidlsb !=0x60)
return ovidlsb;
for(i=0;ov_reg.need != 0xff;i++)
{
if(ov_reg.need == 1)
{
temp = TWI_poll( TWI_CHIP_OV7660|TWI_WRITE, (ov_reg.addr), &(ov_reg.data) );
if( temp )
{
return temp;
}
}
}
txnum=0;
for(i=0;ov_reg.need != 0xff;i++)
{
if(ov_reg.need == 1)
{
temp = TWI_poll( TWI_CHIP_OV7660|TWI_READ, (ov_reg.addr), &(txPacket[txnum++]) );
if( temp )
{
return temp;
}
}
}
// uartDebug_txPacket(txPacket,txnum);
my_delay_ms(200);
return 0x00; //ok
} /* OV7660_init() */
http://blog.163.com/hym131690/blog/static/6425531620095252587636/ |
|