38译码器Verilog编写及调试
1、设计输入与输出
3个输入信号,1个8位输出信号
2、RTL设计代码编写
module Decoder_3_8( //模块端口列表
input a,
input b,
input c,
output reg [7:0] out //在always语句块中赋值
); //变量需为reg型
always@* //对a,b,c信号变化敏感
begin
case({a,b,c}) //多路分支,同时{}进行位拼接
3'b000 : out = 8'b00000001; //状态赋值
3'b001 : out = 8'b00000010;
3'b010 : out = 8'b00000100;
3'b011 : out = 8'b00001000;
3'b100 : out = 8'b00010000;
3'b101 : out = 8'b00100000;
3'b110 : out = 8'b01000000;
3'b111 : out = 8'b10000000;
endcase
end
endmodule
3、分析综合
Run Synthesis
4、功能仿真
testbench文件书写
`timescale 1ns/1ns //延时精度
module Decoder_3_8_tb(); //测试平台无需与外界交互,无端口
reg a; //reg型表激励信号
reg b;
reg c;
wire [7:0] out; //wire型表导线
Decoder_3_8 Decoder_3_8( //例化
.a(a), //接线
.b(b),
.c(c),
.out(out)
);
initial begin
a=0;b=0;c=0;
#200;
a=0;b=0;c=1;
#200;
a=0;b=1;c=0;
#200;
a=0;b=1;c=1;
#200;
a=1;b=0;c=0;
#200;
a=1;b=0;c=1;
#200;
a=1;b=1;c=0;
#200;
a=1;b=1;c=1;
#200;
$stop; //延时结束
end
endmodule
Run Simulation
5、布局布线
IO Planning
注:使用的为蓝桥杯开发板,开发板型号为xc7s6ftgb196-2
6、生成比特流文件并烧录
generate bitstream