2020年3月1日 星期日

EX6-1 BCD code to 2-4-2-1 code circuit

EX6-1 BCD code to 2-4-2-1 code circuit

//=============================
// Ch6.1 BCD code to 2-4-2-1 code circuit 

module EX10_9( a ,b, c, d, w, x , y ,z);

input  a ,b, c ,d; // 1位元輸入

output  reg  w, x , y ,z  ; // Output    1位元輸出

always@ ( a ,b, c, d) begin
case ({a,b,c,d}) 
4'b0000: {w,x,y,z}=4'b0000;
4'b0001: {w,x,y,z}=4'b0001;
4'b0010: {w,x,y,z}=4'b0010;
4'b0011: {w,x,y,z}=4'b0011;
4'b0100: {w,x,y,z}=4'b0100;
4'b0101: {w,x,y,z}=4'b1011;
4'b0110: {w,x,y,z}=4'b1100;
4'b0111: {w,x,y,z}=4'b1101;
4'b1000: {w,x,y,z}=4'b1110;
4'b1001: {w,x,y,z}=4'b1111;
4'b1010: {w,x,y,z}=4'bzzzz;
4'b1011: {w,x,y,z}=4'bzzzz;
4'b1100: {w,x,y,z}=4'bzzzz;
4'b1101: {w,x,y,z}=4'bzzzz;
4'b1110: {w,x,y,z}=4'bzzzz;
4'b1111: {w,x,y,z}=4'bzzzz;
endcase

end

endmodule

//=============================
// 時間單位 100ns, 時間精確度100 ps
`timescale 100ns/100ps     
module Test_bench;
    // Inputs
    reg a ,b, c ,d;

    // Outputs
    wire w, x , y ,z  ;

    // Instantiate the Unit Under Test (UUT)
    //  Ch6.1 BCD code to 2-4-2-1 code circuit 
     EX10_9  UUT (
        .a(a), 
        .b(b), 
        .c(c), 
        .d(d),
        .w(w), 
        .x(x), 
        .y(y), 
        .z(z)
    );

    initial begin
        $monitor( a ,b, c, d, w, x , y ,z);

        //Apply inputs
a=1'b0; b=1'b0; c=1'b0; d=1'b0;
        #100;
{a,b,c,d}=4'b0001;
        #100;
{a,b,c,d}=4'b0010;
        #100;
{a,b,c,d}=4'b0011;
        #100;
{a,b,c,d}=4'b0100;
        #100;
{a,b,c,d}=4'b0101;
        #100;
{a,b,c,d}=4'b0110;
        #100;
{a,b,c,d}=4'b0111;
        #100;
{a,b,c,d}=4'b1000;
        #100;
{a,b,c,d}=4'b1001;
        #100;
{a,b,c,d}=4'b1010;
        #100;
{a,b,c,d}=4'b1011;
        #100;
{a,b,c,d}=4'b1100;
        #100;
{a,b,c,d}=4'b1101;
        #100;
{a,b,c,d}=4'b1110;
        #100;
{a,b,c,d}=4'b1111;
        #100;
   
    end
    initial begin
#1600  $stop;
end

endmodule


沒有留言:

張貼留言

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

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