2020年4月16日 星期四

BCD(8421) to Excess-3 Behavioral Level in Verilog (Case)

BCD(8421) to Excess-3  Behavioral Level in Verilog (Case)







module BCD_EXCESS3(B,Y);

input  [3:0]B;  // B  4位元輸入
output [3:0]Y;   // Y    4位元輸出
reg [3:0]Y;

always@(*)begin
 case (B)  
    4'd0: Y=4'b0011;  
    4'd1: Y=4'b0100; 
    4'd2: Y=4'b0101;  
    4'd3: Y=4'b0110;  
    4'd4: Y=4'b0111; 
    4'd5: Y=4'b1000;   
    4'd6: Y=4'b1001; 
    4'd7: Y=4'b1010;  
    4'd8: Y=4'b1011; 
    4'd9: Y=4'b1100;
    default: Y=4'bZZZZ;      
 endcase 

end

endmodule


// 時間單位 100ns, 時間精確度100 ps
`timescale 100ns/100ps 
module TB;
/*
module BCD_EXCESS3(B,Y);
input  [3:0]B;  // B  4位元輸入
output [3:0]Y;   // Y    4位元輸出
*/
reg [3:0]B= 4'b0000;   //  暫存器資料初值為‘0’

wire [3:0]Y;

integer i;

BCD_EXCESS3 DUT(B,Y);

initial begin
    for (i=0; i<16; i=i+1) begin
         B = i;
         #20;
    end
    #20
     $stop;
end

endmodule



沒有留言:

張貼留言

ESP32-Flutter-MQTT-IoT-Controller

 ESP32-Flutter-MQTT-IoT-Controller 這套系統包含了 Flutter 跨平台 App 、 ESP32 韌體 與 MQTT 雲端傳輸機制 。 專案中採用的 功能命名原則與對應關係 整理如下: 1. 核心功能名稱對照表 功能區塊 Python / ...