用VHDL编数字时钟

合集下载
  1. 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
  2. 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
  3. 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。

LIBRARY IEEE;

USE IEEE.STD_LOGIC_1164.ALL;

USE IEEE.STD_LOGIC_UNSIGNED.ALL;

USE IEEE.STD_LOGIC_SIGNED.ALL;

USE IEEE.STD_LOGIC_ARITH.ALL;

ENTITY Clock IS

PORT( CLK5:IN STD_LOGIC;

CLK3:IN STD_LOGIC; --时钟控制

SET1:IN STD_LOGIC;

SET2:IN STD_LOGIC; --模式控制

SEG_SEL:OUT STD_LOGIC_VECTOR(2 DOWNTO 0);

SEG_DA :OUT STD_LOGIC_VECTOR(7 DOWNTO 0)

);

END Clock;

ARCHITECTURE ADO OF Clock IS

SIGNAL SEG_BUF1,SEG_BUF2,SEG_BUF3,SEG_BUF4:STD_LOGIC_VECTOR(3 DOWNTO 0); SIGNAL SEG_BUF5,SEG_BUF6,SEG_BUF7,SEG_BUF8:STD_LOGIC_VECTOR(3 DOWNTO 0); SIGNAL SEG_CNT :STD_LOGIC_VECTOR(2 DOWNTO 0);

SIGNAL SEG_TEMP:STD_LOGIC_VECTOR(3 DOWNTO 0);

BEGIN

PROCESS (CLK3) --扫描累加

BEGIN

IF CLK3'EVENT AND CLK3='1' THEN

SEG_CNT<=SEG_CNT+1;

END IF;

END PROCESS;

SEG_SEL<=SEG_CNT;

SEG_BUF3<="1111";

SEG_BUF6<="1111";

PROCESS(SEG_CNT,SEG_BUF1,SEG_BUF2,SEG_BUF3,SEG_BUF4,SEG_BUF5,SEG_BUF6,SEG_BUF7 ,SEG_BUF8)

BEGIN

CASE SEG_CNT IS

WHEN "000" => SEG_TEMP<=SEG_BUF1;

WHEN "001" => SEG_TEMP<=SEG_BUF2;

WHEN "010" => SEG_TEMP<=SEG_BUF3;

WHEN "011" => SEG_TEMP<=SEG_BUF4;

WHEN "100" => SEG_TEMP<=SEG_BUF5;

WHEN "101" => SEG_TEMP<=SEG_BUF6;

WHEN "110" => SEG_TEMP<=SEG_BUF7;

WHEN "111" => SEG_TEMP<=SEG_BUF8;

WHEN OTHERS => NULL;

END CASE;

END PROCESS;

PROCESS (SEG_TEMP) --显示转换

BEGIN

CASE SEG_TEMP IS

WHEN "0000" => SEG_DA<=x"3F";

WHEN "0001" => SEG_DA<=x"06";

WHEN "0010" => SEG_DA<=x"5B";

WHEN "0011" => SEG_DA<=x"4F";

WHEN "0100" => SEG_DA<=x"66";

WHEN "0101" => SEG_DA<=x"6D";

WHEN "0110" => SEG_DA<=x"7D";

WHEN "0111" => SEG_DA<=x"07";

WHEN "1000" => SEG_DA<=x"7F";

WHEN "1001" => SEG_DA<=x"6F";

WHEN "1010" => SEG_DA<=x"77";

WHEN "1011" => SEG_DA<=x"7B";

WHEN "1100" => SEG_DA<=x"39";

WHEN "1101" => SEG_DA<=x"3E";

WHEN "1110" => SEG_DA<=x"79";

WHEN "1111" => SEG_DA<=x"00";

END CASE;

END PROCESS;

PROCESS(Clk5,SET1,SET2)

BEGIN

if(SET1='1' AND SET2='1') then --系统复位

SEG_BUF1<="0000";

SEG_BUF2<="0000";

SEG_BUF4<="0000";

SEG_BUF5<="0000";

SEG_BUF7<="0000";

SEG_BUF8<="0000";

elsif(Clk5'event and Clk5='1') then

if(SET1='1' and SET2='0') then --调节小时

if(SEG_BUF7=9) then

SEG_BUF7<="0000";

SEG_BUF8<=SEG_BUF8+1;

elsif(SEG_BUF8>=2 and SEG_BUF7>=3) then

SEG_BUF7<="0000";

SEG_BUF8<="0000";

else

SEG_BUF7<=SEG_BUF7+1;

end if;

elsif(SET1='0' and SET2='1') then --调节分钟

if(SEG_BUF4=9) then

SEG_BUF4<="0000";

if(SEG_BUF5=5) then

SEG_BUF5<="0000";

else

SEG_BUF5<=SEG_BUF5+1;

end if;

else

SEG_BUF4<=SEG_BUF4+1;

end if;

elsif(SET1='0' and SET2='0') then --正常计数

SEG_BUF1<=SEG_BUF1;

SEG_BUF2<=SEG_BUF2;

SEG_BUF4<=SEG_BUF4;

SEG_BUF5<=SEG_BUF5;

SEG_BUF7<=SEG_BUF7;

SEG_BUF8<=SEG_BUF8;

if(SEG_BUF1=9) then

SEG_BUF1<="0000";

if(SEG_BUF2=5) then

SEG_BUF2<="0000";

if(SEG_BUF4=9) then

SEG_BUF4<="0000";

if(SEG_BUF5=5) then

SEG_BUF5<="0000";

if(SEG_BUF7=9) then

SEG_BUF7<="0000";

SEG_BUF8<=SEG_BUF8+1;

elsif(SEG_BUF8>=2 and SEG_BUF7>=3) then

SEG_BUF7<="0000";

SEG_BUF8<="0000";

else

SEG_BUF7<=SEG_BUF7+1;

end if;

else

SEG_BUF5<=SEG_BUF5+1;

end if;

else

相关文档
最新文档