将stm32f4与ov7670连接时出错

时间:2015-11-30 01:46:20

标签: c# camera stm32 stm32f4discovery

我正在使用stm32f4连接到ov7670(没有FIFO)来捕获图像(176x144,RGB565)。捕获图像后,stm将通过UART-COM将数据发送到PC。我用C#编写了一个程序,用于从com端口读取数据并显示为图像。但我得到的问题是我有问题:

image is sent in computer

这是我的C#代码:

using System.Drawing;
using System.Windows.Forms;

namespace camview
    {
    public partial class Form1 : Form
    {
        Bitmap bmp = new Bitmap(176, 144);
        public Form1()
        {
            InitializeComponent();

            serialPort1.Open();
        }

        void setbmp(Bitmap bmp, int x, int y, int a, int b)
        {
            int tmp = (a << 8) | b;

            int red = tmp >> 11;
            int green = (tmp >> 5) & 0x3f;
            int blue = tmp & 0x1f;

            bmp.SetPixel(x, y, Color.FromArgb(red * 8, green * 4, blue * 8));

        }

        private void button1_Click(object sender, System.EventArgs e)
        {
            string s = "";
            while (s != "OK\r")
            {
                s = serialPort1.ReadLine();
                richTextBox1.Text += s;
            }

            richTextBox1.Text += "Start\n";
            for (int i = 0; i < 144; i++)
                for (int j = 0; j < 176; j++)
                {
                    int a = serialPort1.ReadByte();
                    int b = serialPort1.ReadByte();
                    //richTextBox1.Text += a + ' ' + b + ' ';
                    setbmp(bmp, j, i, a, b);
                }

            pictureBox1.Image = bmp;
        }
    }
}

这是我对ov7670 reg的配置:

I2C_writereg(0x12, 0x80); // reset all reg
I2C_writereg(0x11, 0xc0); //set CLKRC
I2C_writereg(0x12, 0x0c); // set output QCIF, RGB
I2C_writereg(0x70, 0x3a); // scaling
I2C_writereg(0x71, 0x35); 
I2C_writereg(0x8c, 0x00); // disable RGB444
I2C_writereg(0x40, 0xd0); // enable RGB565, output range from 00 to FF
I2C_writereg(0x0c, 0x4c); // 

0 个答案:

没有答案