ov7670 的verilog代码,有点不明白,高手帮忙分析一下
module cmos_top(osc_24MHZ,
iRST,
//ov7660
ov7660_reset,
ov7660_xclk,
ov7660_pclk,
ov7660_data_8bit,
iVSYNC,
iLVAL,
lcd2_cs,
lcd2_wr,
lcd2_rs,
lcd2_reset,
lcd2_rd,
lcd2_data16,
oDVAL
);
input osc_24MHZ;
input iRST;
//ov7660
output ov7660_reset;
output ov7660_xclk;
input ov7660_pclk;
input ov7660_data_8bit;
input iVSYNC;
input iLVAL;
//tft
output lcd2_cs;
output lcd2_wr;
output lcd2_rs;
output lcd2_reset;
output lcd2_rd;
output lcd2_data16;
///////////////////////////////////
output oDVAL;
assign iCLK = ov7660_pclk;
assign lcd2_wr = reg_lcd2_wr;
assign lcd2_rs = 1'b1;
assign lcd2_rd = 1'b1;
assign lcd2_cs = 1'b0;
assign lcd2_reset = 1'b1;
assign lcd2_data16 = ov7660_data_16bit;
reg Pre_FVAL;
reg mCCD_FVAL;
reg mCCD_LVAL;
reg mCCD_DATA;
reg X_Cont;
reg Y_Cont;
assign oX_Cont = X_Cont;
assign oY_Cont = Y_Cont;
//assign i0v7660_data_8bit = mCCD_DATA;
assign i0v7660_data_8bit = ov7660_data_8bit;
//assign oDVAL = mCCD_FVAL&mCCD_LVAL;
assign oDVAL = mCCD_FVAL&iLVAL;
wire i0v7660_data_8bit;
////////////////////////////////
//
assign iFVAL = iVSYNC;
reg temp_count;
always@(posedge iCLK or negedge iRST)
begin
if(!iRST)
begin
Pre_FVAL <= 0;
mCCD_FVAL <= 0;
mCCD_LVAL <= 0;
mCCD_DATA <= 8'h00;
X_Cont <= 0;
Y_Cont <= 0;
end
else
begin
Pre_FVAL <= iFVAL;
if( {Pre_FVAL,iFVAL}==2'b10)
mCCD_FVAL <= 1;
else if({Pre_FVAL,iFVAL}==4'b01)
mCCD_FVAL <= 0;
mCCD_LVAL <= iLVAL;
// mCCD_DATA <= ov7660_data_8bit;
if(mCCD_FVAL)
begin
if(mCCD_LVAL)
begin
if(X_Cont<639)
X_Cont <= X_Cont+1;
else
begin
X_Cont <= 0;
Y_Cont <= Y_Cont+1;
end
end
end
else
begin
X_Cont <= 0;
if(temp_count == 3) //这里的temp_count是什么作用
begin
Y_Cont <= 0;
temp_count <= 2'b00;
end
else
temp_count <= temp_count + 1'b1;
end
end
end
///////////////////////////////////////////////////////
//ov7660 data 8 bit to 16 bit
//功 能:将输入的8位数据转换成16位,同时进行位转换。
//由OV7660 RGB565 的输出格式 RRRRRGGGGGGBBBBB 改为 BBBBBGGGGGGRRRRR 格式
//转换后的数据符合TFT 数据输入格式
regstate1;
reg pre_i0v7660_data_8bit;
reg ov7660_data_16bit;
always@(posedge iCLK or negedge iRST)
if(!iRST)
begin
state1 <= 1'b0;
end
else
begin
if(iLVAL)
case(state1)
1'b0 : begin
pre_i0v7660_data_8bit <= i0v7660_data_8bit;
state1 <= 1'b1;
end
1'b1 : begin
ov7660_data_16bit <= {pre_i0v7660_data_8bit,i0v7660_data_8bit};
//{pre_i0v7660_data_8bit,i0v7660_data_8bit};
//{i0v7660_data_8bit,pre_i0v7660_data_8bit,pre_i0v7660_data_8bit,i0v7660_data_8bit};
//{i0v7660_data_8bit,pre_i0v7660_data_8bit,i0v7660_data_8bit,pre_i0v7660_data_8bit};//{pre_i0v7660_data_8bit,i0v7660_data_8bit};
state1 <= 1'b0;
end
default : state1 <= 1'b0;
endcase
end
reg temp1;
reg temp2;
always@(posedge iCLK or negedge iRST)
if(!iRST)
begin
temp1 <= 1'b0;
temp2 <= 1'b0;
end
else
begin
temp1 <= iLVAL;
temp2 <= temp1;
end
reg reg_lcd2_wr;
reg write_state;
always@(negedge iCLK or negedge iRST)
if(!iRST)
begin
reg_lcd2_wr <= 1'b1;
write_state <= 1'b0;
end
else
case(write_state)
0 : if(temp2&(Y_Cont == 0)&tft_outenable)
begin
reg_lcd2_wr <= ~reg_lcd2_wr;
write_state <= 1'b1;
end
else
reg_lcd2_wr <= 1'b1;
1 : begin
if(temp2)
reg_lcd2_wr <= ~reg_lcd2_wr;
else
reg_lcd2_wr <= 1'b1;
if(Y_Cont < 240)
write_state <= 1'b1;
else
write_state <= 1'b0;
end
endcase
reg Frame_Cont;
reg tft_outenable;
always@(posedge iCLK or negedge iRST)
begin
if(!iRST)
Frame_Cont <= 0;
else
begin
if({Pre_FVAL,iFVAL}==2'b10) //这里是当iVSYNC下降沿时让Frame_cont 加1吗,为什么要加到小于5呢?
if(Frame_Cont < 5)
begin
Frame_Cont <= Frame_Cont+1;
tft_outenable <= 1'b0;
end
else
tft_outenable <= 1'b1;
end
end
endmodule 好长啊!等会回实验室用电脑看下! 这块是ov7670数据读取,然后送到tft上显示出来,Frame_Cont 这个量是控制什么呢? 应该是禁止最前面5帧输出,利用iVSYNC下降沿使Frame_cont加1来对帧同步信号计数。 mark! 没有电路???没有fifo??控制思想是什么??一头雾水,lz先介绍点背景的说 这是从网上看的一个利用nios配置好ov7670和lcd以后,然后在用verilog读取ov7670里的数据直接送到tft上显示,这是verilog读取数据并送lcd显示的一段代码?里面包括了读取ov7670的数据,然后将读取的8位数据转换成16位数据送lcd显示,就这样的,下面是一个完整的工程。 点击此处下载 ourdev_703922LOBDYK.rar(文件大小:14.83M) (原文件名:N_ov.rar) 留个qq2319786543,不知道坛里还有没有人做这个,可以讨论讨论。 有点诡异,没看懂。我写的代码直接让TFT暴走了。不知道是什么原因。哎 mark 这种方式是让OV7670输出格式为RGB565,而这个格式正好和LCD的RGB565输入格式相同,所以直接写入就可以显示图像了。 顶,我也想知到fpag怎么实现数据的正确处理 好吧,这代码写的。。。
页:
[1]