日历源程序:
module finddays (year,month,num_days);
input year;
input[3:0] month;
output[4:0] num_days;
reg[4:0] num_days;
always @(month)
begin
case (month)
4'b0001, 4'b0011, 4'b0101, 4'b0111, 4'b1000, 4'b1010,4'b1100: num_days =
5'b11111;//31 days
4'b0010: num_days = year ? 5'b11101 : 5'b11100;//2 month
4'b1100, 4'b1101, 4'b1110, 4'b1111 : num_days = 5'b00000;
default : num_days = 5'b11110;//30day
endcase
end
endmodule
测试程序:
`timescale 1ns/100ps
module test_days;
reg[3:0] test_month;
reg cyears;
wire[4:0] sday;
initial
begin
test_month = 1;
cyears = 0;
end
always #10 test_month = test_month+1;
always #150 cyears=~cyears;
finddays test1(cyears,test_month,sday);
endmodule
测试结果: