在线咨询
eetop公众号 创芯大讲堂 创芯人才网
切换到宽版

EETOP 创芯网论坛 (原名:电子顶级开发网)

手机号码,快捷登录

手机号码,快捷登录

找回密码

  登录   注册  

快捷导航
搜帖子
查看: 1128|回复: 2

[资料] VHDL程序24小时

[复制链接]
发表于 2010-5-17 00:17:45 | 显示全部楼层 |阅读模式

马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。

您需要 登录 才可以下载或查看,没有账号?注册

x
library ieee;
use ieee.std_logic_1164.all;
use ieee.std_logic_unsigned.all;
entity digital_clock is
port(

reset,clk: in std_logic;

hour,minitue,second: out std_logic_vector(7 downto 0);

hex0,hex1,hex2,hex3,hex4,hex5: out std_logic_vector(6 downto 0));
end digital_clock;
architecture one of digital_clock is
signal clk_count: std_logic_vector(22 downto 0);
signal clkm: std_logic;
signal second1,second2: std_logic_vector(3 downto 0);
signal minitue1,minitue2: std_logic_vector(3 downto 0);
signal hour1,hour2: std_logic_vector(3 downto 0);
begin
hour(7 downto 0) <= hour2(3 downto 0) & hour1 (3 downto 0);
minitue(7 downto 0) <= minitue2(3 downto 0) & minitue1(3 downto 0);
second(7 downto 0) <= second2(3 downto 0) & second1(3 downto 0);
process(clk)
begin

if (clk'event and clk ='1') then

clk_count <= clk_count + 1;

end if;
end process;
clkm <= clk_count(22);
------------------------
process(clkm)
begin
if(reset='1')then

hour2 <= "0000";hour1<="0000";minitue2 <="0000"; minitue1 <="0000"; second2<="0000"; second1<="0000";

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

if (hour2 = "0101" and hour1 ="1001" and minitue2 ="0101" and minitue1 ="1001" and second2 ="0101" and second1 ="1001")then

hour2 <= "0000"; hour1 <= "0000"; minitue2 <="0000"; minitue1 <="0000"; second2<="0000"; second1<="0000";

elsif(hour1 ="1001" and minitue2 ="0101" and minitue1 ="1001" and second2 ="0101" and second1 ="1001")then

hour2 <= hour2 +1;hour1 <= "0000";minitue2 <="0000";minitue1 <="0000";second2<="0000";second1<="0000";

elsif(minitue2 ="0101" and minitue1 ="1001" and second2 ="0101" and second1 ="1001")then

hour1 <= hour1 +1;minitue2 <="0000";minitue1 <="0000";second2<="0000";second1<="0000";

elsif(minitue1 ="1001" and second2 ="0101" and second1 ="1001")then

minitue2 <=minitue2 +1;minitue1 <="0000";second2<="0000";second1<="0000";

elsif(second2 ="0101" and second1 ="1001")then

minitue1 <=minitue1 +1;second2<="0000";second1<="0000";

elsif(second1 ="1001")then

second2 <= second2 +1;second1 <= "0000";

else

second1 <= second1 +1;

end if;

end if;
end process;
------------------------
process(hour2,hour1,minitue2,minitue1,second2,second1)
begin

case second1(3 downto 0) is

when "0000" => hex0(6 downto 0) <="1000000";

when "0001" => hex0(6 downto 0) <="1111001";

when "0010" => hex0(6 downto 0) <="0100100";

when "0011" => hex0(6 downto 0) <="0110000";

when "0100" => hex0(6 downto 0) <="0011001";

when "0101" => hex0(6 downto 0) <="0010010";

when "0110" => hex0(6 downto 0) <="0000010";

when "0111" => hex0(6 downto 0) <="1111000";

when "1000" => hex0(6 downto 0) <="0000000";

when "1001" => hex0(6 downto 0) <="0010000";

when others => hex0(6 downto 0) <="1000000";

end case;

case second2(3 downto 0) is

when "0000" => hex1(6 downto 0) <="1000000";

when "0001" => hex1(6 downto 0) <="1111001";

when "0010" => hex1(6 downto 0) <="0100100";

when "0011" => hex1(6 downto 0) <="0110000";

when "0100" => hex1(6 downto 0) <="0011001";

when "0101" => hex1(6 downto 0) <="0010010";

when others => hex1(6 downto 0) <="1000000";

end case;

case minitue1(3 downto 0) is

when "0000" => hex2(6 downto 0) <="1000000";

when "0001" => hex2(6 downto 0) <="1111001";

when "0010" => hex2(6 downto 0) <="0100100";

when "0011" => hex2(6 downto 0) <="0110000";

when "0100" => hex2(6 downto 0) <="0011001";

when "0101" => hex2(6 downto 0) <="0010010";

when "0110" => hex2(6 downto 0) <="0000010";

when "0111" => hex2(6 downto 0) <="1111000";

when "1000" => hex2(6 downto 0) <="0000000";

when "1001" => hex2(6 downto 0) <="0010000";

when others => hex2(6 downto 0) <="1000000";

end case;

case minitue2(3 downto 0) is

when "0000" => hex3(6 downto 0) <="1000000";

when "0001" => hex3(6 downto 0) <="1111001";

when "0010" => hex3(6 downto 0) <="0100100";

when "0011" => hex3(6 downto 0) <="0110000";

when "0100" => hex3(6 downto 0) <="0011001";

when "0101" => hex3(6 downto 0) <="0010010";

when others => hex3(6 downto 0) <="1000000";

end case;

case hour1(3 downto 0) is

when "0000" => hex4(6 downto 0) <="1000000";

when "0001" => hex4(6 downto 0) <="1111001";

when "0010" => hex4(6 downto 0) <="0100100";

when "0011" => hex4(6 downto 0) <="0110000";

when "0100" => hex4(6 downto 0) <="0011001";

when "0101" => hex4(6 downto 0) <="0010010";

when "0110" => hex4(6 downto 0) <="0000010";

when "0111" => hex4(6 downto 0) <="1111000";

when "1000" => hex4(6 downto 0) <="0000000";

when "1001" => hex4(6 downto 0) <="0010000";

when others => hex4(6 downto 0) <="1000000";

end case;

case hour2(3 downto 0) is

when "0000" => hex5(6 downto 0) <="1000000";

when "0001" => hex5(6 downto 0) <="1111001";

when "0010" => hex5(6 downto 0) <="0100100";

when "0011" => hex5(6 downto 0) <="0110000";

when "0100" => hex5(6 downto 0) <="0011001";

when "0101" => hex5(6 downto 0) <="0010010";

when others => hex5(6 downto 0) <="1000000";

end case;
end process;
end one;
-----在DE2板上验证
时钟频率有点高,可以在clk_count中增加位数作调整
发表于 2011-1-3 22:34:19 | 显示全部楼层
了解一下
发表于 2011-1-4 14:20:51 | 显示全部楼层
不 know~非常不know
您需要登录后才可以回帖 登录 | 注册

本版积分规则

关闭

站长推荐 上一条 /1 下一条


小黑屋| 手机版| 关于我们| 联系我们| 在线咨询| 隐私声明| EETOP 创芯网
( 京ICP备:10050787号 京公网安备:11010502037710 )

GMT+8, 2024-11-20 07:47 , Processed in 0.016393 second(s), 9 queries , Gzip On, Redis On.

eetop公众号 创芯大讲堂 创芯人才网
快速回复 返回顶部 返回列表