在Verilog中执行后续图像处理操作之前,我需要将像素方阵值加载到二维方阵中。 以下面给出的4x4像素正方形数组值为例:
19 d 9 99
fc 5e 1f c
32 26 47 5a
b 6c 2a 41
可以看出,十进制值已转换为十六进制。我将像素数组存储在名为“ 16pixels_h.txt”的.txt文件中。我计划使用系统任务$readmemh
执行所需的操作。所以我创建了一个像这样的模块:
`timescale 1ns/1ps
module readmemh(i,mem_out);
input i;
output [7:0] mem_out;
reg [7:0] mem_2d [1:4] [1:4]; //the square array should have 4 rows and 4 volumes
initial
begin
$readmemh("16pixels_h_vertical.txt", mem_2d);
end
assign mem_out=i?mem_2d[2][3]:mem_2d[3][4];
endmodule
测试台如下所示:
`timescale 1ns / 1ps
module readmemh_tb;
reg i;
wire [7:0] mem_out;
initial
begin
i=0;
#10 i=1;
#10 i=0;
#10 i=1;
#20 $stop;
$display($time,"mem_out=%d",mem_out);
end
readmemh inst1(i,mem_out);
endmodule
模拟后,我得到了: enter image description here
像素值未加载到二维正方形数组mem_2d
中。我正在网上搜索很长时间。但是没用。请提供帮助或尝试提供一些实现方法的建议。