实验 2
二-十进制译码器
//Decoder: binary-to decimal decoder with an enable control
module b2d(y,en,a) ;
output [7:0] y ;
input en ;
input [3:0] a;
reg[7:0] y ;
always @ (en or a)
// EN 和A 是敏感信号
if(!en)
// 如果使能信号为低,无效
y = 8'b1111_1111;
else
begin
if(a>9)
y<=a+6;
//这里完成了二进制到十进制的译码,
else
y<=a;
end
//为了方便在平台上进行观察验证
///这里把数据的个位和十位分别用 4 个LED 进行显示,均为二进制
Endmodule
实验3
BCD 码—七段数码管显示译码器module decode4_7(decodeout,a);
output[6:0] decodeout;
input[3:0] a;
reg[6:0] decodeout;
always @(a)
begin
case(a)
//用 case 语句进行译码 abcdefg
4'h0:decodeout=7'b1111110;
4'h1:decodeout=7'b0110000;
4'h2:decodeout=7'b1101101;
4'h3:decodeout=7'b1111001;
4'h4:decodeout=7'b0110011;
4'h5:decodeout=7'b1011011;
4'h6:decodeout=7'b1011111;
4'h7:decodeout=7'b1110000;
4'h8:decodeout=7'b1111111;
4'h9:decodeout=7'b1111011;
4'ha:decodeout=7'b1110111;
4'hb:decodeout=7'b0011111;
4'hc:decodeout=7'b1001110;
4'hd:decodeout=7'b0111101;
4'he:decodeout=7'b1001111;
4'hf:decodeout=7'b1000111;
default: decodeout=7'bx;
endcase
end
endmodule
实验4
8-3编码器//a 8-3 coder
module coder(dout,din);
output[2:0] dout;
input [7:0] din;
reg [2:0] dout;
always @(din)
case(din)
8'b1111_1110 : dout<=3'b000;
8'b1111_1101 : dout<=3'b001;
8'b1111_1011 : dout<=3'b010;
8'b1111_0111 : dout<=3'b011;
8'b1110_1111 : dout<=3'b100;
8'b1101_1111 : dout<=3'b101;
8'b1011_1111 : dout<=3'b110;
8'b0111_1111 : dout<=3'b111;
default: dout<=3'bx;
endcase
endmodule |