大连理工大学本科实验报告题目:数电课设——多功能数字钟课程名称:数字电路课程设计学院(系):电信学部专业:电子与通信工程班级:学生姓名: ***************学号:***************完成日期:成绩:2010 年 12 月 17 日题目:多功能数字时钟一.设计要求1)具有‘时’、‘分’、‘秒’的十进制数字显示(小时从00~23)2)具有手动校时校分功能3)具有整点报时功能,从59分50秒起,每隔2秒钟提示一次4)具有秒表显示、计时功能(精确至百分之一秒),可一键清零5)具有手动定时,及闹钟功能,LED灯持续提醒一分钟6)具有倒计时功能,可手动设定倒计时范围,倒计时停止时有灯光提示,可一键清零二.设计分析及系统方案设计1. 数字钟的基本功能部分,包括时、分、秒的显示,手动调时,以及整点报时部分。
基本模块是由振荡器、分频器、计数器、译码器、显示器等几部分组成。
利用DE2硬件中提供的50MHZ晶振,经过分频得到周期为1s的时钟脉冲。
将该信号送入计数器进行计算,并把累加结果以“时”“分”“秒”的形式通过译码器由数码管显示出来。
进入手动调时功能时,通过按键改变控制计数器的时钟周期,使用的时钟脉冲进行调时计数(KEY1调秒,LOAD2调分,LOAD3调时),并通过译码器由七位数码管显示。
从59分50秒开始,数字钟进入整点报时功能。
每隔两秒提示一次。
(本设计中以两个LED灯代替蜂鸣器,进行报时)2. 多功能数字钟的秒表功能部分,计时范围从00分秒至59分秒。
可由输入信号(RST1)异步清零,并由按键(EN1)控制计时开始与停止。
将DE2硬件中的50MHZ晶振经过分频获得周期为秒的时钟脉冲,将信号送入计数器进行计算,并把累计结果通过译码器由七位数码管显示。
3.多功能数字钟的闹钟功能部分,通过按键(KEY1,KEY2,KEY3)设定闹钟时间,当时钟进入闹钟设定的时间(判断时钟的时信号qq6,qq5与分信号qq4,qq3分别与闹钟设定的时信号r6,r5与分信号r4,43是否相等),则以LED灯连续提示一分钟。
4. 多功能数字钟的倒计时功能部分,可通过按键(LOAD7调秒,LOAD8调分,LOAD9调时)设定倒计时开始时刻。
倒计时的时钟与数字钟的时钟相同,每迎到一个时钟上升沿,则计数器减一。
计数器减至00时,分钟位、秒钟位恢复至59,时钟位恢复至23。
倒计时结束时(即00时00分00秒),控制LED灯亮,表示倒计时结束。
本设计通过数据选择器控制译码器,使数码管独立显示,各功能之间互不影响。
当LOAD4为高电平,则对秒表信号进行译码,数码管显示秒表数据;当LOAD4为低电平,LOAD5为高电平,则对闹钟信号进行译码,数码管显示闹钟数据;当LOAD4,LOAD5为低电平,LOAD6为高电平,则对倒计时信号进行译码,数码管显示倒计时信号数据;当LOAD4,LOAD5,LOAD6全为低电平,则对正常时钟信号进行译码,数码管显示时钟信号数据。
附图1:系统总体结构框图附图2系统硬件电路设计下载时选择的开发系统模式以及管脚定义四系统的VHDL设计源程序:--代码共372行library ieee;use clock isport( load9,load8,load7,load6,load5,load4,load3,load2,load1:instd_logic;clk,rst1,rst2,en1,en2,key1,key2,key3:in std_logic;q1,q2,q3,q4,q5,q6:out std_logic_vector(6 downto 0);led1,led2,led3,led4,led5:out std_logic);end;architecture a of clock issignal qq1,qq2,qq3,qq4,qq5,qq6:std_logic_vector(3 downto 0);--数字钟计数器信号signal vis1,vis2,vis3,vis4,vis5,vis6:std_logic_vector(3 downto 0);signal cp1,cp2,cp3,cp4,cp5:std_logic;signal p1:integer range 0 to 49;signal p2:integer range 0 to 999;signal p3:integer range 0 to 999;signal clfsa:integer range 0 to 499;signal a,b,c,d,e,f,g: std_logic_vector(3 downto 0);--秒表计数器信号signal r1,r2,r3,r4,r5,r6:std_logic_vector(3 downto 0);--闹钟信号signal z1,z2,z3,z4,z5,z6:std_logic_vector(3 downto 0);--倒计时计数器信号signal alz1,alz2,alz3,alz4,alz5:std_logic;Begin-----------------------------------------------------------------------分频模块-------------------------------------------------------------------------------------process(clk) --分频1beginif rising_edge(clk) thenif p1=49 thenp1<=0;cp1<='1';elsep1<=p1+1;cp1<='0';end if;end if;end process;process(cp1) --分频2beginif rising_edge(cp1) thenif p2=999 thenp2<=0;cp2<='1';elsep2<=p2+1;cp2<='0';end if;end if;end process;process(cp2) --得到周期为1秒的信号beginif rising_edge(cp2) thenif p3=999 thenp3<=0;cp3<='1';elsep3<=p3+1;cp3<='0';end if;end if;end process;process(cp2) --得到周期为百分之一秒的信号beginif rising_edge(cp2) thenif a="1001" then a<="0000";a1<='1';else a<=a+1;a1<='0';end if;e nd if;process(cp2) --得到周期为秒的信号beginif rising_edge(cp2) thenif clfsa=499 thenclfsa<=0;hlfs<='1';elseclfsa<=clfsa+1;hlfs<='0';end if;end if;end process;-----------------------------------------------------------------------数字钟模块----------------------------------------------------------------------------------process(cp3,load1,key1) --数字钟秒钟计数器beginif rising_edge(cp3) thenif load1='1' thenif key1='0' then --秒钟手动调节if qq2="0101" and qq1="1001"then qq1<="0000"; qq2<="0000";elsif qq1="1001" thenqq1<="0000";qq2<=qq2+1;else qq1<=qq1+1;end if;end if;else if load1='0' thenif qq2="0101" and qq1="1001"then qq1<="0000"; qq2<="0000";cp4<='1';elsif qq1="1001" thenqq1<="0000";qq2<=qq2+1;cp4<='0';else qq1<=qq1+1;cp4<='0';end if;if qq2="0101" and en='1' then --整点报时case qq1 iswhen "0001"=>led2<='1';when "0011"=>led2<='1';when "0101"=>led2<='1';when "0111"=>led2<='1';when "1001"=>led3<='1';when others =>led2<='0';led3<='0';end case;else led2<='0';led3<='0';end if;end if;end if;end if;process(hlfs,cp4,load2) --数字钟分钟计数器beginif load2='1' then clkx<=hlfs;else clkx<=cp4;end if; --当load2为高电平时,进行分调节if rising_edge(clkx)thenif qq4="0101" and qq3="1001"then qq3<="0000"; qq4<="0000";cp5<='1';elsif qq3="1001" thenqq3<="0000";qq4<=qq4+1;cp5<='0';else qq3<=qq3+1;cp5<='0';end if;end if;i f qq3="1001" and qq4="0101" then en<='1';else en<='0';end if;end process;process(hlfs,cp5,load1) --数字钟时钟计数器beginif load3='1' then clkx1<=hlfs;else clkx1<=cp5;end if; --当load3为高电平时,进行小时调节if rising_edge(clkx1) thenif qq5="0011" and qq6="0010" thenqq5<="0000"; qq6<="0000";elsif qq5="1001" thenqq5<="0000";qq6<=qq6+1;else qq5<=qq5+1;end if;end if;end process;-----------------------------------------------------------------------闹钟模块-------------------------------------------------------------------------------------process(hlfs,load5,key1) --闹钟秒计数器beginif rising_edge(hlfs) thenif load5='1' thenif key1='0' then --手动进行闹钟秒设定if r2="0101" and r1="1001"then r1<="0000"; r2<="0000";elsif r1="1001" thenr1<="0000";r2<=r2+1;else r1<=r1+1;end if;end if;end if;end if;end process;process(hlfs,load5,key2) --闹钟分计数器beginif rising_edge(hlfs) thenif key2='0' then --手动进行闹钟分设定if r4="0101" and r3="1001"then r3<="0000"; r4<="0000";elsif r3="1001" thenr3<="0000";r4<=r4+1;else r3<=r3+1;end if;end if;end if;end if;end process;process(hlfs,load5,key3) --闹钟小时计数器beginif rising_edge(hlfs) thenif load5='1' thenif key3='0' then --手动进行闹钟小时设定 if r6="0010" and r5="0011"then r5<="0000"; r6<="0000";elsif r5="1001" thenr5<="0000";r6<=r6+1;else r5<=r5+1;end if;end if;end if;end if;end process;process(cp3,qq1,qq2,qq3,qq4,qq5,qq6,r1,r2,r3,r4,r5,r6) --数字钟与闹钟相符,以LED灯进行提示beginif rising_edge(cp3) thenif qq3=r3 and qq4=r4 and qq5=r5 and qq6=r6then led1<='1';else led1<='0';end if;end if;end process;-----------------------------------------------------------------------秒表模块-------------------------------------------------------------------------------------process(a1,rst1,en1) --秒表计数器beginif rst1='1' then b<="0000";c<="0000"; --秒表异步清零elsif rising_edge(a1) thenif en1='1' thenif b="1001" and c="1001"then b<="0000";c<="0000";c1<='1';elsif b="1001" thenb<="0000";c<=c+1;c1<='0';else b<=b+1;c1<='0';end if;e nd if;end process;process(c1,rst1,en1)beginif rst1='1' then d<="0000";e<="0000";elsif rising_edge(c1) thenif en1='1' thenif d="1001" and e="0101"then d<="0000";e<="0000";e1<='1';elsif d="1001" thend<="0000";e<=e+1;e1<='0';else d<=d+1;e1<='0';end if;end if;end if;end process;process(e1,rst1,en1)beginif rst1='1' then f<="0000";g<="0000";elsif rising_edge(e1) thenif en1='1' thenif f="1001" and g="0101"then f<="0000";g<="0000";elsif f="1001" thenf<="0000";g<=g+1;else f<=f+1;end if;end if;e nd if;e nd process;-----------------------------------------------------------------------倒计时模块----------------------------------------------------------------------------------process(cp3,rst2,en2,clkx2,load7,hlfs) --倒计时计数器beginif load7='1' then clkx2<=hlfs; else clkx2<=cp3;end if;if rst2='1' then z2<="0000";z1<="0000";alz1<='1'; --倒计时异步清零elsif rising_edge(clkx2) thenif en2='1' thenif z2="0000" and z1="0000"then z2<="0101";z1<="1001";alz1<='1';elsif z1="0000" thenz1<="1001";z2<=z2-1;alz1<='0';else z1<=z1-1;alz1<='0';end if;if z1="0001" and z2="0000"then led4<='1';else led4<='0';end if;end if;end if;e nd if;end process;process(alz1,rst2,en2,load8,clkx3,hlfs)beginif load8='1' then clkx3<=hlfs;else clkx3<=alz1;end if;if rst2='1' then z4<="0000";z3<="0000";alz2<='1';elsif rising_edge(clkx3) thenif z4="0000" and z3="0000"then z4<="0101";z3<="1001";alz2<='1';elsif z3="0000" thenz3<="1001";z4<=z4-1;alz2<='0';else z3<=z3-1;alz2<='0';end if;i f alz4='1' theni f z4<="0000" and z3<="0000"then alz5<='1';e lse alz5<='0';end if;end if;e nd if;end process;process(clkx4,alz2,rst2,en2,load9,hlfs)beginif load9='1' then clkx4<=hlfs;else clkx4<=alz2;end if;if rst2='1' then z6<="0000";z5<="0000";elsif rising_edge(clkx4) thenif z6="0000" and z5="0000"then z6<="0010";z5<="0011";elsif z5="0000" thenz5<="1001";z6<=z6-1;else z5<=z5-1;end if;i f z5="0000" and z6="0000" then alz4<='1';else alz4<='0';end if;e nd if;end process;process(z1,z2,z3,z4,z5,z6,hlfs,l)beginif rising_edge(hlfs)then if z1="0000" and z2="0000" and z3="0000" and z4="0000" and z5="0000" and z6="0000" thenl<=not l;else l<='0';end if;end if;led5<=l;------------------------------------------------------------------------------------------------------数据选择器,选择对数字钟,秒表,倒计时,闹钟其中之一进行译码显示------------------------------------------------------------------------------------------------------process(qq1,qq2,qq3,qq4,qq5,qq6,b,c,d,e,f,g,load4,load5,load6,r1,z1,r 2,z2,r3,z4,r5,z5,r6,z6)beginif load4='1' then vis1<=b;vis2<=c;vis3<=d;vis4<=e;vis5<=f;vis6<=g; else if load5='1' thenvis1<=r1;vis2<=r2;vis3<=r3;vis4<=r4;vis5<=r5;vis6<=r6;elsif load6='1' thenvis1<=z1;vis2<=z2;vis3<=z3;vis4<=z4;vis5<=z5;vis6<=z6;elsevis1<=qq1;vis2<=qq2;vis3<=qq3;vis4<=qq4;vis5<=qq5;vis6<=qq6;end if;end if;end process;------------------------------------------------------------------显示模块------------------------------------------------------------------------process(vis1,vis2,vis3,vis4,vis5,vis6)begincase vis1 iswhen "0000"=>q1<="1000000";when "0001"=>q1<="1111001";when "0010"=>q1<="0100100";when "0011"=>q1<="0110000";when "0100"=>q1<="0011001";when "0101"=>q1<="0010010";when "0110"=>q1<="0000010";when "0111"=>q1<="1111000";when "1000"=>q1<="0000000";when "1001"=>q1<="0010000";when others => null;end case;case vis2 iswhen "0000"=>q2<="1000000";when "0001"=>q2<="1111001";when "0010"=>q2<="0100100";when "0011"=>q2<="0110000";when "0100"=>q2<="0011001";when "0101"=>q2<="0010010";when "0110"=>q2<="0000010";when "0111"=>q2<="1111000";when "1000"=>q2<="0000000";when others => null;end case;case vis3 iswhen "0000"=>q3<="1000000"; when "0001"=>q3<="1111001"; when "0010"=>q3<="0100100"; when "0011"=>q3<="0110000"; when "0100"=>q3<="0011001"; when "0101"=>q3<="0010010"; when "0110"=>q3<="0000010"; when "0111"=>q3<="1111000"; when "1000"=>q3<="0000000"; when "1001"=>q3<="0010000"; when others => null;end case;case vis4 iswhen "0000"=>q4<="1000000"; when "0001"=>q4<="1111001"; when "0010"=>q4<="0100100"; when "0011"=>q4<="0110000"; when "0100"=>q4<="0011001"; when "0101"=>q4<="0010010"; when "0110"=>q4<="0000010"; when "0111"=>q4<="1111000"; when "1000"=>q4<="0000000"; when "1001"=>q4<="0010000"; when others => null;end case;case vis5 iswhen "0000"=>q5<="1000000"; when "0001"=>q5<="1111001"; when "0010"=>q5<="0100100"; when "0011"=>q5<="0110000"; when "0100"=>q5<="0011001"; when "0101"=>q5<="0010010"; when "0110"=>q5<="0000010"; when "0111"=>q5<="1111000"; when "1000"=>q5<="0000000"; when "1001"=>q5<="0010000"; when others => null;end case;case vis6 iswhen "0000"=>q6<="1000000"; when "0001"=>q6<="1111001"; when "0010"=>q6<="0100100"; when "0011"=>q6<="0110000";when "0101"=>q6<="0010010";when "0110"=>q6<="0000010";when "0111"=>q6<="1111000";when "1000"=>q6<="0000000";when "1001"=>q6<="0010000";when others => null;end case;end process;end;五结论以及结果说明系统的运行环境为DE2,主芯片为Cyclone II EP2C35F672C6NK.输入时钟信号选择50MHz。