LIBRARY IEEE;
USE IEEE.STD_LOGIC_1164.ALL;
USE IEEE.STD_LOGIC_UNSIGNED.ALL;
ENTITY seltime IS
PORT( scan_clk,cclk:IN STD_LOGIC;
ms:IN STD_LOGIC_VECTOR(1 DOWNTO 0);
sezi:IN STD_LOGIC_VECTOR(2 DOWNTO 0);
hour,minute,second,mbmdat,mbfmdat,qbmdat,sgmdat:IN STD_LOGIC_VECTOR(7 DOWNTO
0);
sel:OUT STD_LOGIC_VECTOR(3 DOWNTO 0);
seg:OUT STD_LOGIC_VECTOR(6 DOWNTO 0);
segdap:OUT STD_LOGIC);
END seltime;
ARCHITECTURE BHV OF seltime IS
SIGNAL SCAN_COUNT : STD_LOGIC_VECTOR(1 DOWNTO 0):="00"; -- 扫描计数
SIGNAL SIGN:STD_LOGIC:='0';
SIGNAL dat : STD_LOGIC_VECTOR(3 DOWNTO 0):="0000";
BEGIN
-- 位选扫描进程
scan : PROCESS(scan_clk,ms) BEGIN
IF scan_clk'EVENT AND scan_clk = '1' THEN
IF(SCAN_COUNT > "11") THEN SCAN_COUNT <= "00";
ELSE SCAN_COUNT <= SCAN_COUNT + 1;
END IF;
END IF;
CASE SCAN_COUNT & ms IS
WHEN "0000" => dat <= minute(3 DOWNTO 0);
WHEN "0100" => dat <= minute(7 DOWNTO 4);
WHEN "1000" => dat <= hour(3 DOWNTO 0);
WHEN "1100" => dat <= hour(7 DOWNTO 4);
--模式 0
WHEN "0001" => dat <= second(3 DOWNTO 0);
WHEN "0101" => dat <= second(7 DOWNTO 4);
WHEN "1001" => dat <= minute(3 DOWNTO 0);
WHEN "1101" => dat <= minute(7 DOWNTO 4);
--模式 1
WHEN "0010" => dat <= mbfmdat(3 DOWNTO 0);
WHEN "0110" => dat <= mbfmdat(7 DOWNTO 4);
WHEN "1010" => dat <= mbmdat(3 DOWNTO 0);
WHEN "1110" => dat <= mbmdat(7 DOWNTO 4);
--模式 2
WHEN "0011" => dat <= sgmdat(3 DOWNTO 0);