找回密碼
 立即注冊(cè)

QQ登錄

只需一步,快速開(kāi)始

搜索
查看: 1671|回復(fù): 0
收起左側(cè)

ModelSim仿真源代碼

[復(fù)制鏈接]
ID:294494 發(fā)表于 2018-3-20 15:23 | 顯示全部樓層 |閱讀模式
Counter的源代碼:
module lin(clk,rst,in1,in2,cin,count,sum);
input [7:0]in1,in2;
input clk,rst,cin;
output [7:0]sum;
output count;
reg [7:0]sum;
reg count;
always @(posedge clk)
begin
if(!rst)
begin
count<=0;
sum<=8'b0;
end
else
sum<=in1+in2+cin;
if(sum>=8'b11111111)
count<=1;
else
count<=0;
end
endmodule
Tcounter的源代碼:
`timescale 10ns/1ns
module tcounter;
reg clk1, rst1,cin1;
reg[7:0] din1,din2;
wire count1;
wire[7:0] sum1;
lin  adder (  .cin   (cin1),
             .in1  (din1),
             .in2  (din2),
             .clk   (clk1),
             .rst  (rst1),
             .sum   (sum1),
             .count (count1)
             );
initial   // Clock generator
  begin
    clk1 = 0;
  forever #10 clk1 = ~clk1;
  end
   
   initial                                               
                begin
                        #0                rst1 = 1'b0;       
                        #0.5                rst1 = 1'b1;       
                        #22                rst1 = 1'b0;       
                end
always @ ( negedge clk1 )       
                begin
                        din1 = $random%256;       
         din2 = $random%256;
         cin1  = $random%2;
                end
                endmodule   

評(píng)分

參與人數(shù) 1黑幣 +50 收起 理由
admin + 50 共享資料的黑幣獎(jiǎng)勵(lì)!

查看全部評(píng)分

回復(fù)

使用道具 舉報(bào)

本版積分規(guī)則

小黑屋|51黑電子論壇 |51黑電子論壇6群 QQ 管理員QQ:125739409;技術(shù)交流QQ群281945664

Powered by 單片機(jī)教程網(wǎng)

快速回復(fù) 返回頂部 返回列表