------------------------------------------------------------------------------- -- MaxDaySelector.vhd -- Sydney Tang -- 1998 October 17 -- -- Entity to select the maximum number of days according to the year and month. -- -- This entity takes as its inputs the value of the month (1 to 12) and the -- first two bits of the value of the year. It outputs the number of days that -- there are in the given month. -- -- Leap years are detected by reading the two least significant bits in the -- year. Any number that is divisible by 4 would have "00" for these two bits. ------------------------------------------------------------------------------- library ieee; use ieee.std_logic_1164.all; use ieee.std_logic_arith.all; use ieee.std_logic_unsigned.all; library work; use work.BCD_Package.all; use work.Time_Package.all; entity MaxDaySelector is port( Month: in std_logic_vector(1+BCD_WIDTH-1 downto 0); Century2LSB: in std_logic_vector(1 downto 0); Year2LSB: in std_logic_vector(1 downto 0); DecadeYear: in std_logic_vector(2*BCD_WIDTH-1 downto 0); MaxDay: out std_logic_vector(2*BCD_WIDTH-1 downto 0) ); end MaxDaySelector; architecture selector of MaxDaySelector is begin SelectMaxDay: process(Month) is begin case Month is when JAN => MaxDay <= THIRTY_ONE_DAYS; when FEB => case Year2LSB is when "00" => -- year is divisible by 4 -> possible leap year if DecadeYear = "00000000" then case Century2LSB is when "00" => -- century MaxDay <= TWENTY_NINE_DAYS; when others => MaxDay <= TWENTY_EIGHT_DAYS; end case; else MaxDay <= TWENTY_NINE_DAYS; end if; when others => -- not divisible by 4 -> normal year MaxDay <= TWENTY_EIGHT_DAYS; end case; when MAR => MaxDay <= THIRTY_ONE_DAYS; when APR => MaxDay <= THIRTY_DAYS; when MAY => MaxDay <= THIRTY_ONE_DAYS; when JUN => MaxDay <= THIRTY_DAYS; when JUL => MaxDay <= THIRTY_ONE_DAYS; when AUG => MaxDay <= THIRTY_ONE_DAYS; when SEP => MaxDay <= THIRTY_DAYS; when OCT => MaxDay <= THIRTY_ONE_DAYS; when NOV => MaxDay <= THIRTY_DAYS; when DEC => MaxDay <= THIRTY_ONE_DAYS; when others => MaxDay <= ONE_DAY; end case; end process SelectMaxDay; end selector;