0v7670窗口显示异常

2019-12-27 19:04发布

在320X240的液晶上显示qvga,一切正常。打算让摄像头显示在窗口280X200,怎么都是错位。
void OV_HW(unsigned int  hstart, unsigned int hstop, unsigned int vstart, unsigned int vstop)
{
    uint8_t v;
    OV7670_WriteReg(0x17, (hstart >> 3) & 0xff); //HSTART
    OV7670_WriteReg(0x18, (hstop >> 3) & 0xff); //HSTOP
    OV7670_ReadReg(0x32,&v);
    v = (v & 0xc0) | ((hstop & 0x7) << 3) | (hstart & 0x7);
    OV7670_WriteReg(0x32, v); //HREF

    OV7670_WriteReg(0x19, (vstart >> 2) & 0xff); //VSTART 开始高8位
    OV7670_WriteReg(0x1a, (vstop >> 2) & 0xff); //VSTOP        结束高8位
     OV7670_ReadReg(0x03,&v );
    v = (v & 0xf0) | ((vstop & 0x3) << 2) | (vstart & 0x3);
   OV7670_WriteReg(0x03, v); //VREF
    OV7670_WriteReg(0x11, 0x00);
}
19条回答
heitu103
2019-12-28 00:30 .采纳回答
给个参考,亲测可用

  1. //输出窗口设置
  2. void OV7670_config_window(u16 startx,u16 starty,u16 width,u16 height)
  3. {
  4.     u16 endx=(startx+width)%784;   //QVGA输出的话改成 u16 endx=(startx+width*2)%784;   
  5.     u16 endy=(starty+height);            // u16 endy=(starty+height*2);

  6.      u8 x_reg,y_reg;
  7.      u8 state,temp;
  8.      state=ov7660_read_reg(0x32,&x_reg);
  9.     x_reg&=0xC0;
  10.     state=ov7660_read_reg(0x03,&y_reg);
  11.     y_reg&=0xF0;
  12.                
  13.     //HREF
  14.     temp=x_reg|((endx&0x7)<<3)|(startx&0x7);
  15.     state=ov7670_write_reg(0x32,temp);
  16.     temp=(startx&0x7F8)>>3;
  17.      state=ov7670_write_reg(0x17,temp);
  18.      temp=(endx&0x7F8)>>3;
  19.       state=ov7670_write_reg(0x18,temp);
  20.                
  21.     //VREF
  22.      temp=y_reg|((endy&0x3)<<2)|(starty&0x3);
  23.      state=ov7670_write_reg(0x03,temp);
  24.      temp=(starty&0x3FC)>>2;
  25.     state=ov7670_write_reg(0x19,temp);
  26.      temp=(endy&0x3FC)>>2;
  27.      state=ov7670_write_reg(0x1A,temp);
  28. }
复制代码

一周热门 更多>