2020年6月13日 星期六

Convert Binary to 7-Segment Display in Verilog

Convert   Binary to   7-Segment Display in Verilog


module Bin_to_7seg(x,z);

input  [3:0]x;

output reg [6:0]z; 

   

always @(x) begin

case (x)

4'b0000 :      //Hexadecimal 0

z = 7'b1111110;

4'b0001 :    //Hexadecimal 1

z = 7'b0110000  ;

4'b0010 :  // Hexadecimal 2

z = 7'b1101101 ; 

4'b0011 : // Hexadecimal 3

z = 7'b1111001 ;

4'b0100 : // Hexadecimal 4

z = 7'b0110011 ;

4'b0101 : // Hexadecimal 5

z = 7'b1011011 ;  

4'b0110 : // Hexadecimal 6

z = 7'b1011111 ;

4'b0111 : // Hexadecimal 7

z = 7'b1110000;

4'b1000 :      //Hexadecimal 8

z = 7'b1111111;

4'b1001 :    //Hexadecimal 9

z = 7'b1111011 ;

4'b1010 :  // Hexadecimal A

z = 7'b1110111 ; 

4'b1011 : // Hexadecimal B

z = 7'b0011111;

4'b1100 : // Hexadecimal C

z = 7'b1001110 ;

4'b1101 : // Hexadecimal D

z = 7'b0111101 ;

4'b1110 : // Hexadecimal E

z = 7'b1001111 ;

4'b1111 : // Hexadecimal F

z = 7'b1000111 ;

endcase

end 

endmodule


`timescale 100ns / 100ps
module TB;
// Inputs
reg [3:0] x;
// Outputs
wire [6:0] z;
integer i;
// Instantiate the Unit Under Test (UUT)
Bin_to_7seg uut (.x(x), .z(z));
 
initial begin
// Initialize Inputs
x = 0;
for (i=0;i<=15;i=i+1)
begin
#20
x=i;
    end
#20 
$stop;
end  
endmodule







沒有留言:

張貼留言

2024產專班 作業2 (純模擬)

2024產專班 作業2  (純模擬) 1) LED ON,OFF,TIMER,FLASH 模擬 (switch 控制) 2)RFID卡號模擬 (buttom  模擬RFID UID(不從ESP32) Node-Red 程式 [{"id":"d8886...