`timescale 1ns / 1ps
module tb_yuv2rgb;
// Inputs
reg clk;
reg rstn; //复位输入,低电平复位
reg [7:0] y_in;
reg [7:0] cb_in;
reg [7:0] cr_in;
reg ena_in;
// Outputs
wire [7:0] R_out;
wire [7:0] G_out;
wire [7:0] B_out;
wire ena_out;
// Instantiate the Unit Under Test (UUT)
yuv2rgb uut (
.clk(clk),
.rstn(rstn),
.y_in(y_in),
.cb_in(cb_in),
.cr_in(cr_in),
.ena_in(ena_in),
.R_out(R_out),
.G_out(G_out),
.B_out(B_out),
.ena_out(ena_out)
);
localparam PIXNUM_1080P =(1920*1080*3);
localparam PIXNUM_720P =(1280*720*3);
//read pixel from .txt file
reg[7:0] mem_imgpixel[0:2**24];
reg [31:0] pixaddr;
integer fid,i;
initial begin //读取图片的YUV数据
$readmemh("Penguins_720p.txt",mem_imgpixel);
pixaddr = 0;
#PIXNUM_1080P begin //等待图片的数据转换完成
fid = $fopen("Penguins_720pRGBout.txt","w");
for(i=0; i<PIXNUM_720P; i=i+1)
$fdisplay(fid,"%2x",mem_rgbout[i]);//输出转换的RGB数据
$fclose(fid);
$stop;
end
end
//clk的上升沿给输入的yuv数据
always @(posedge clk or negedge rstn) begin
if(!rstn) begin
y_in <= 8'b0;
cb_in <= 8'b0;
cr_in <= 8'b0;
ena_in <= 1'b0;
pixaddr<= 0;
end
else begin
y_in <= mem_imgpixel[pixaddr];
cb_in <= mem_imgpixel[pixaddr+1];
cr_in <= mem_imgpixel[pixaddr+2];
ena_in <= 1'b1;
pixaddr<= pixaddr + 3;
end
end
reg[31:0] outaddr;
reg[7:0] mem_rgbout[0:2**24];//clk的下降沿读取转换的rgb数据
always @(negedge clk or negedge rstn) begin
if(!rstn) begin
outaddr <= 0;
end
else begin //存入对应下标
mem_rgbout[outaddr] <= R_out;
mem_rgbout[outaddr+1] <= G_out;
mem_rgbout[outaddr+2] <= B_out;
outaddr <= outaddr + 3; //下标增加3
end
end
initial begin
// Initialize Inputs
clk = 0;
rstn = 1;
y_in = 0;
cb_in = 0;
cr_in =