1 /********************************************************************************* 2 * Company : 3 * Engineer : 空气微凉 4 * 5 * Create Date : 00:00:00 22/03/2013 6 * Design Name : 7 * Module Name : 8 * Project Name : 9 * Target Devices : 10 * Tool versions : 11 * Description : 12 * http://www.cnblogs.com/kongqiweiliang/ 13 * Dependencies : 14 * 15 * Revision : 16 * Revision : 0.01 - File Created 17 * Additional Comments :基础实验_09_计数器 :摸4、8、16计数器各一 18 ********************************************************************************/ 19 `timescale 1ns/1ps 20 `define UD #1 21 /*******************************************************************************/ 22 module COUNT 23 ( 24 //system interface 25 input iCLK_50 ,//50MHz 26 input iRESET ,//system interface 27 //Interface package 28 input iM4_EN ,// 29 input iM8_EN ,// 30 input iM16_EN ,// 31 32 output reg [1:0] oM4 ,// 33 output reg [2:0] oM8 ,// 34 output reg [3:0] oM16 // 35 ); 36 //------------------------------------------------------------------------------- 37 reg [1:0] oM4_N ;// 38 reg [2:0] oM8_N ;// 39 reg [3:0] oM16_N ;// 40 //M4 41 always@(posedge iCLK_50 or negedge iRESET)begin 42 if(!iRESET) 43 oM4 <= 2'h0; 44 else 45 oM4 <= oM4_N; 46 end 47 always@(*)begin 48 if(iM4_EN == 1'h1) 49 oM4_N = oM4 + 1'h1; 50 else 51 oM4_N = oM4; 52 end 53 //M8 54 always@(posedge iCLK_50 or negedge iRESET)begin 55 if(!iRESET) 56 oM8 <= 3'h0; 57 else 58 oM8 <= oM8_N; 59 end 60 always@(*)begin 61 if(iM4_EN == 1'h1) 62 oM8_N = oM8 + 1'h1; 63 else 64 oM8_N = oM8; 65 end 66 //M16 67 always@(posedge iCLK_50 or negedge iRESET)begin 68 if(!iRESET) 69 oM16 <= 4'h0; 70 else 71 oM16 <= oM16_N; 72 end 73 always@(*)begin 74 if(iM16_EN == 1'h1) 75 oM16_N = oM16 + 1'h1; 76 else 77 oM16_N = oM16; 78 end 79 //------------------------------------------------------------------------------- 80 endmodule