练习题代码

来源:互联网 发布:linux init 0 编辑:程序博客网 时间:2024/06/05 07:10
module count2(CLK,RST,CNT,con,);input RST,  CLK;output [3:0]CNT,con;reg [3:0]CNT,con,cnt=6;reg OV;always @(posedge CLK or posedge RST) begin//主计数器  if(RST)begin     con=0;  end  else begin if(CNT<cnt)begincon = CNT + 1'b1;endelse begin        con=0;    end  endendalways @ (posedge CLK or posedge RST) begin  if(RST)     CNT <= 0;  else    CNT <= con;endalways @(CNT) begin  if(CNT == 0)     OV = 1;  else    OV = 0;endalways@(posedge OV or posedge RST)begin//控制计数器   if(RST)begin      cnt=6;   end   else if(cnt<9)begin     cnt=cnt+1'b1;   end   else   cnt=6;endendmodule



                                             
0 0