EDA 实验报告——多功能电子钟姓名:张红义班级:10级电科五班学号:1008101143指导老师:贾树恒电子钟包括:主控模块,计时模块,闹钟模块,辅控模块,显示模块,蜂鸣器模块,分频器模块。
1.主控模块:主要功能:控制整个系统,输出现在的状态,以及按键信息。
源代码:libraryieee;use ieee.std_logic_1164.all;useieee.std_logic_arith.all;useieee.std_logic_unsigned.all;entity mc isport(functionswitch,k,set,lightkey: in std_logic;chose21,setout: out std_logic;lightswitch:bufferstd_logic;modeout,kmodeout : out std_logic_vector(1 downto 0);setcs,setcm,setch,setas,setam,setah:outstd_logic);end mc;architecture work of mc issignalmode,kmode:std_logic_vector(1 downto 0);signal light,chose21buf:std_logic;signalsetcount:std_logic_vector(5 downto 0);beginprocess(functionswitch,k,set,lightkey)beginiffunctionswitch'event and functionswitch='1' thenmode<=mode+'1';end if;iflightkey'event and lightkey='1' thenlightswitch<=not lightswitch;end if;if mode="01" thenchose21buf<='0';else chose21buf<='1';end if;ifk'event and k='1' thenif mode="01" or mode="11" thenkmode<=kmode+'1';end if;end if;if set='1' thenif mode = "01" thenifkmode="01" then setcount<="000001";elsifkmode="10" thensetcount<="000010";elsifkmode="11" thensetcount<="000100";elsesetcount<="000000";end if;elsif mode = "11" thenifkmode="01" thensetcount<="001000";elsifkmode="10" thensetcount<="010000";elsifkmode="11" thensetcount<="100000";elsesetcount<="000000";end if;end if;end if;if set='0' thensetcount<="00000”;end if;setout<=set;modeout<=mode;kmodeout<=kmode;chose21<=chose21buf;setcs<=setcount(0);setcm<=setcount(1);setch<=setcount(2); setas<=setcount(3);setam<=setcount(4);setah<=setcount(5); end process;end work;仿真波形:2. 计时模块主要功能:记录时间,正常计时。
60进制libraryieee;use ieee.std_logic_1164.all;useieee.std_logic_arith.all;useieee.std_logic_unsigned.all;entity count60 isport(clk ,clr :in std_logic;co : out std_logic;outh :out std_logic_vector(7 downto 4);outl :out std_logic_vector(3 downto 0));end count60 ;architecture work of count60 issignal bufh:std_logic_vector(7 downto 4);signal bufl:std_logic_vector(3 downto 0);beginprocess(clk)beginifclr='0' thenbufh<="0000";bufl<="0000";elsif(clk'event and clk='1')thenif(bufh="0101"and bufl="1001")then co<='1';bufh<="0000";bufl<="0000";elsif(bufl="1001")thenbufl<="0000";bufh<=bufh+1;elsebufl<=bufl+1;co<='0'; end if;end if;outh<=bufh;outl<=bufl;end process;end work;24进制libraryieee;use ieee.std_logic_1164.all;useieee.std_logic_arith.all;useieee.std_logic_unsigned.all;entity count24 isport(clk :in std_logic; co: out std_logic;outh :out std_logic_vector(7 downto 4);outl :out std_logic_vector(3 downto 0));end count24 ;architecture a of count24 issignal bufh:std_logic_vector(7 downto 4);signal bufl:std_logic_vector(3 downto 0);beginprocess(clk)beginif(clk'event and clk='1')thenif(bufh="0010"and bufl="0011")thenco<='1';bufh<="0000";bufl<="0000";elsif(bufl="1001")thenbufl<="0000";bufh<=bufh+1;elsebufl<=bufl+1;co<='0';end if;end if;outh<=bufh;outl<=bufl;end process;end a;keyen.vhdlibraryieee;use ieee.std_logic_1164.all;entitykeyen isport(en, keyin:instd_logic;keyout: out std_logic);endkeyen;architecture work of keyen isbeginprocess(en,keyin)beginif en='1' then keyout<=keyin;elsekeyout<='0';end if;end process;end work;chose21.vhdlibraryieee;use ieee.std_logic_1164.all;entity chose21 isport(clk,add,chose : in std_logic;co : out std_logic);end chose21;architecture work of chose21 isbeginprocess(chose,clk,add)beginif chose='1' then co<=clk;elseco<=add;end if;end process;end work;3. 闹钟模块:主要功能记录闹钟时间信息,输出闹钟时间信息源代码:同上:keyen.vhdcount60.vhdcount24.vhd4. 辅控模块:主要功能处理显示,以及蜂鸣器的信号。
时钟输入与闹钟输入相比较,组成闹钟功能,以及整点报时功能。
源代码Ac.vhdlibraryieee;use ieee.std_logic_1164.all;useieee.std_logic_unsigned.all;entity ac isport(clk,lightonoff:instd_logic;mode,kmode:instd_logic_vector(1 downto 0);csh,csl,cmh,cml,chh,chl,ash,asl,amh,aml,ahh,ahl:instd_logic_vector(3 downto 0);q0,q1,q2,q3,q4,q5,q6,q7:outstd_logic_vector(3 downto 0);lightswitch,sound512,sound1024,timeok:out std_logic);end ac;architecture work of ac issignal q0b,q1b,q2b,q3b,q4b,q5b,q6b,q7b: std_logic_vector(3 downto 0);beginprocess(chh,cmh,csh,ash,ahh,amh,chl,cml,csl,asl,ahl,aml,mode,km ode,clk)beginif mode="00" or mode="01" then --闪烁功能开始q0b<=csl;q1b<=csh;q2b<="1010";q3b<=cml;q4b<=cmh;q5b<="1010";q6b<=chl;q7b<=chh;elsif mode="10" or mode="11" then q0b<=asl;q1b<=ash;q2b<="1010";q3b<=aml;q4b<=amh;q5b<="1010";q6b<=ahl;q7b<=ahh;end if;ifclk ='1' thenif mode="00" or mode="10" then q0<=q0b;q1<=q1b;q2<=q2b;q3<=q3b;q4<=q4b;q5<=q5b;q6<=q6b;q7<=q7b;elsecasekmode iswhen "01" =>q0<="1111";q1<="1111";q2<=q2b;q3<=q3b;q4<=q4b;q5<=q5b;q6<=q6b;q7<=q7b;when "10" =>q0<=q0b;q1<=q1b;q2<=q2b;q3<="1111";q4<="1111";q5<=q5b;q6<=q6b;q7<=q7b;when "11" =>q0<=q0b;q1<=q1b;q2<=q2b;q3<=q3b;q4<=q4b;q5<=q5b;q6<="1111";q7<="1111";when others =>q0<="1111";q1<="1111";q2<="1111";q3<="1111";q4<="1111";q5<="1111";q6<="1111";q7<="1111";end case;end if;elseq0<=q0b;q1<=q1b;q2<=q2b;q3<=q3b;q4<=q4b;q5<=q5b;q6<=q6b;q7<=q7b;end if;--闪烁功能完毕--整点报时功能开始ifcmh="0101" and cml="1001" thenifcsh="0101" thenifcsl="0001" or csl="0010" or csl="0101" orcsl="0111" thensound512<='1' ;elsifcsl="1001" thensound1024<='1';elsesound512<='0';sound1024<='0';end if;end if;end if;--正点报时功能完--显示开关功能开始iflightonoff='1' thenlightswitch<='0';elselightswitch<='1';end if;--显示开关功能完毕--闹钟功能开始ifchh=ahh and cmh=amh and chl=ahl and cml=aml then timeok<='1';elsetimeok<='0';end if;--闹钟功能完毕end process;end work;5. 显示模块:主要功能处理辅控传来的显示信号,在数码管上直接的显示数字。