用Verilog寫一個74LS160


5-10 Verilog設計一個功能類似74ls160的計數器。

1)解題思路

設計一個74ls160,需要知道它的功能表,以及原理圖

 

 

(2)核心模塊代碼

module fidv1 (rd,clk,et,load,datain,dataout,cout,ep);

input rd,et,load,clk,ep;

input [3:0] datain;

output [3:0] dataout ;

output cout;

reg cout;

reg [3:0] q1;

wire rd;

always @ (posedge clk or negedge rd)

if (rd==0) begin q1<=4'd0; end//rd=0時清零

else begin

if(clk==1&load==0) q1=datain;

else if(clk==1&load==1)

begin

if(ep==1&et==1&q1<4'd10) //開始計數

begin q1=q1+1;cout=0;

end

else if((ep&et)==0) begin q1=q1;cout=0;end//保持不變

else if(q1==4'd10) cout=1;//進位輸出

end

end

assign dataout =q1;

endmodule

(3)測試模塊代碼

`timescale 1 ps/ 1 ps

module fidv1_ll();

// constants                                           

// general purpose registers

reg eachvec;

// test vector input registers

reg clk;

reg [3:0] datain;

reg ep;

reg et;

reg load;

reg rd;

// wires                                               

wire cout;

wire [3:0]  dataout;

 

// assign statements (if any)                          

fidv1 i1 (

// port map - connection between master ports and signals/registers   

.clk(clk),

.cout(cout),

.datain(datain),

.dataout(dataout),

.ep(ep),

.et(et),

.load(load),

.rd(rd)

);

always   #2 clk=~clk;

initial                                                

begin                                                  

#0 clk=0;

#0 rd=1;

#0 datain=4'd2;

#2 load=0;

#2 ep=1;

#0 et=1;

#12 load=1;

#16 ep=0;

#0 et=0;

#8 rd=0;

#2 rd=1;

#6 datain=4'd3;

#5 load=0;

                                       

$display("dataout=%d,datain=%d",dataout,datain);  

#2 $stop;                     

end                                                    

                                          

endmodule

(4)RTL View的網表圖

 

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM