当前位置:文档之家› 多功能数字电子钟_VHDL

多功能数字电子钟_VHDL


四、各功能模块的源程序代码 :
-- CONTOR 模块 library ieee; use ieee.std_logic_1164.all; use ieee.std_logic_unsigned.all; use ieee.std_logic_arith.all; entity contor is
1 )“小时” 校时状态: 进入“小时”校时状态后,显示 “小时” 的数码管闪烁,每按动“ k” 键一次,“小时” +1,若不按动“ k”键 则小时数不变,一直按下“ k” 键则小时数一 4Hz 的频率递增计数。
2 )“分”校时状态:进入“分”校时状态后,显示“分”的数 码管闪烁,每按动“ k” 键一次,“分” +1,若不按动“ k”键则分数 不变,一直按下“ k” 键则分数一 4Hz的频率递增计数。
chs,cms,css,f4 :in std_logic; bsg,bmg,bhg,bsd,bmd,bhd :buffer std_logic_vector(3 downto 0); comout :out std_logic); end time_com; architecture time_comx of time_com is begin com:process(hh,mh,sh,hl,ml) begin if(bhg=hh and bhd=hl and bmg=mh and bmd=ml and bsg=sh)then comout<='1'; else comout<='0'; end if; end process; set:process(f4) begin if(f4'event and f4='1')then if(chs='1'and k='0')then if(bhg="0010" and bhd="0011")then bhd<="0000";bhg<="0000"; elsif(bhd="1001")then bhd<="0000";bhg<=bhg+1; elsif(bhd="0000"or bhd="0001" or bhd="0010"or bhd="0011"or bhd="0100"or bhd="0101"or bhd="0110"or bhd="0111"or bhd="1000")then bhd<=bhd+1; end if; end if; end if; end process; process(f4) begin if(f4'event and f4='1')then if(cms='1'and k='0')then if(bmg="0101" and bmd="1001")then
if(sel='0')then y<=d0; elsif(sel='1'and en='0')then y<=d1 ;
end if; end process; end mux2_1_arch;
--*************cnt60 模块 ***** library ieee; use ieee.std_logic_1164.all; use ieee.std_logic_unsigned.all; entity cnt60 is port(clkin :in std_logic;
port(clk,k,set,reset,mode : in std_logic; chs,cht,cms,cmt,css,cst,flashh,flashm,flashs,sel_sh:oowut std_logic);
end contor; architecture contor_arch of contor is
next_state<=s2; end if; when s3=> flashh<='0';flashm<='0';flashs<='1';cht<='0';cmt<='0'; cst<='1';chs<='0';cms<='0';css<='0';sel_show<='1'; if ( set='0' ) then
type states is(s0,s1,s2,s3,s4,s5,s6,s7); signal current_state,next_state :states; begin process (reset,clk,next_state) begin if (reset='1')then
current_state<=s0; elsif (clk'event and clk='1')then
next_state<=s0; elsif ( k='1'and set='0' ) then
next_state<=s5; else next_state<=s4; end if; when s5=> flashh<='1';flashm<='0';flashs<='0';cht<='0';cmt<='0';cst<='0'; chs<='1';cms<='0';css<='0';sel_show<='0'; if (set='0') then next_state<=s6; else next_state<=s5; end if; when s6=> flashh<='0';flashm<='1';flashs<='0';cht<='0';cmt<='0'; cst<='0';chs<='0';cms<='1';css<='0';sel_show<='0'; if (set='0' ) then next_state<=s7; else next_state<=s6; end if; when s7=> flashh<='0';flashm<='0';flashs<='1';cht<='0';cmt<='0';
模块 ********************
--********MUX2-1 模块 ******** library ieee; use ieee.std_logic_1164.all; entity mux2_1 is port(d0,d1,en :in std_logic;
sel :in std_logic; y :out std_logic); end mux2_1; architecture mux2_1_arch of mux2_1 is begin process(d0,d1,sel) begin
3 )“秒”校时状态:进入“秒”校时状态后,显示“秒”的数 码管闪烁,每按动“ k” 键一次,“秒” +1,若不按动“ k”键则秒数 不变,一直按下“ k” 键则秒数一 4Hz的频率递增计数。
整点报时: 蜂鸣器在“ 59”分钟的第 51、53、55、57 秒发出 频率为 512Hz 的低音,在“ 59”秒发出频率为 1024Hz 的高音,结束 时为整点。
三、实验要求及设计方案 1. 设计一个具有 24 进制计时、 显示、整点报时、 时间设置和闹
钟功能的数字钟,要求时钟的最小分辨率时间为 1s。 2. 数字钟的设计方案如下: 系统输入: mode为计时显示和闹钟定时显示转换输入; set 为
校时和定时设置的时、分、秒转换输入; k 为校时和定时设置的时、 分、秒手动加 1 输入; clk 为时钟信号; reset 为系统复位信号。输 入信号均由按键产生。
显示:采用 8 个 LED数码管分别显示时、分、秒并且他们之间 用“—”隔开。
闹钟: 闹钟定时时间到,蜂鸣器发出周期为 1s 的滴、滴声, 持续时间为 10 秒;闹钟定时显示。
闹钟定时设置: 在闹钟显示状态下,按下“ set 键”,进入“小 时”校时状态,再次按下“ set 键”,进入“分”校时状态,继续按 下“set 键”,进入“秒”校时状态,第四次按下“ set 键”又回复到 闹钟显示状态。
current_state<=next_state; end if; end process; process(current_state,k,set) begin case current_state is
when s0=> flashh<='0';flashm<='0';flashs<='0';cht<='0';cmt<='0';cst<='0'; chs<='0';cms<='0';css<='0';sel_show<='1'; if(mode='0')then next_stat9;and set='0' ) then
相关主题