1、 use ieeestd logic_l164.all; use ieee std logiconsigned all;entity freq is port (CLK: in std logic ;qlKHz: buffer std logic; q500Hz: q2Hz: qlHz: out std logic): end freq;architecture bhv of freq is beginP1KHZ:process(CLK) variable cout:integer:=0; beginif CLK1 event and CLK二T then cout:=cout+l;if co
2、ut=25000 then qlKHz=0; elsif cout50000 then qlKHz=,1 else cout:end if;end process;P500HZ: process (qlKHz) qlKHz 作为输入信号,分出 qSOOHzvariable cout:beginif q 1 KHzrevent and qlKHz=T thencout:if cout=l then q500Hz 二分频elsif cout=2 then cout:=0:q500Hz=r T;P2HZ:process(q500Hz)if q500Hzrevent and q500Hz二T then
3、 cout:=125 then q2Hzelsif coutflash hflashnnflashss-eLsfwwj instl二选一模块(mux21a. vhd)(1)源程序: use ieee std logic_unsigned. all; entity mux21a is port(a,b,s:in bit;y:out bit);end entity mux21a; architecture one of mux21a isprocess (a,b,s)if s=0, theny=a; 若s=0, y输出a,反之输出b。else yski17.4c.小时计时(hour, vhd)ho
4、ur dk sk33.0J4sMip.4inst6d.闹钟分计时(cntm60b. vhd)Nano33 u, 5.9? 3 8. L3.印 u, IS. IT 18.7? 3 21.2.9 g 3LnjuinirLnarLnnmarLnnnjwnjiRnnrLruwinjumnmnnjuuiruinrBP亘mirrbii en sld03.0Jdk sldip.4Jinst7e.闹钟小时计时(cnth24b. vhd) (1)仿真波形图: -Gnttib en sWO3.O;dk sldip.4J * !irast8 j5、闹钟比较模块(compare, vhd)比校正常计数时间与闹钟定时时
5、间是否相等,若相等,compout 输出T,反之输出“0”。(2) 仿真波形图:1 -compareth17.4j oompouttM3.Ot(nO3.Obhip.4bmf7.,4bh03.,0bmO3.0j inst6、报时模块(bell.vhd)该模块既实现了整点报时的功能,又实现了闹铃的功能,蜂鸣 器通过所选频率的不同,而发出不同的声音。Wane1 ps 5. 1? us 10.4 us 】5.3p us 20 4f8 us 25. us 30 72 us16. 5 ns# openbelcompout1 = ! = = 1 = iqlKKz曲测蒯ill咂测皿测测呱测i删测呱q500Hz
6、jmnjwinjTrLnjTrLnnnjTrLrLnjwuuirLnjirLnjinjinrLnjinjirLrLrL(1 tnl 5j tnO 913 tsl 5 tsO:0XlX2:3X4X5X&X7:6:mX0)(lX2:3)(4X5X6X7:6)(9X0bell lllllWMllll皿L _n_n_ nn . _nn . jitl 一 iiil _j telltellts.tp.4 tmop.ots.O3.O compout qlKHz q5O3Hz opsnbel irrstl 17x控制显示模块(show_con vhd)该模忘实现了数码管既可以显示正常时间,又可以显示闹钟时 间
7、的功能;调时过程的定时闪烁功能也在此模块中真正实现。(2) 源程序:library ieee;use ieeestd logic_l164.all;use ieee std logiconsigned all;entity showcon isseel,mini,hl: out std logic_vector(7 downto 4); sec0,min0,hO: out std logic_vector(3 downto 0): q2Hzt flashs,flashh,flashm,sel_show:in std logic);end show con; architecture rtl o
8、f show con isprocess(thl,tml,tsl,thO,tmO,tsO,bhl,bml,bhO,bmO,q2Hz,f1ashs,f1ashh,fl ashm,sei show)if sel_show=r 0r thenif ( flashh=,11 and q2Hz=,1)then hl,llir,;hO=,llir,; 一显示小时数码管以2Hz闪烁 minl=tml;min0=tm0;secl=tsl;sec0=ts0;elsif (flashm=1and q2Hz=,1)thenhl=thl;=thO; mini=wllllw;minO=wllllff;elsif (fl
9、ashs=minl=tml ; min 0=tni0;=Bllir,;secO=ttllllw;else secl=tsO;elsif sei show二T then若 sei show 为1”,数码管显示闹钟时 间 一 一if (flashh二T and q2Hz二T ) then hi=,iiii,;ho=ffinr,; minl=bml ; minO=:bmO;=tt0000”;sec 0=0000”;elsif ( flashm二T and q2Hz二T)then=bhl;=bhO;=ffllir,;=,,llir,;sec 10000“;mini=bml;=bm0;sec10000
10、”;end if ;end rtl;(3)模块图:show oorath1|7.41sac17.4JLtm17.4)ts17.,4hip.4)thO3.OSfe&33.0wop.0min(X3.0rts-93.O)bMp.4)bm17.4JbW|3.Ojq2Hzfias-hhfl35-hmsel_5howinstil)8 动态扫描显示模块(scarified, vhd)由4组输入信号和输出信号进而实现了时钟时、分的动态显示。use ieee std logic_unsigned all; entity scan_led isport (clkl:in std logic;hO:in std l
11、ogic_vector(3 downto 0): hl:in std logic_vector(7 downto 4); minO: mini: in std logic_vector(7 downto 4);ML:outMH:HL:HH:out );std logic_vector(7 std logic_vector(7 std logic_vector(7 std logic_vector(7downto downto downto downto0)end scan led; architecture one of sean led issignalt4:std logic_vector
12、(l downto 0): signal a: std logic_vector(3 downto 0);pl:process(clkl)if clklrevent and clkl 二i then t4=cnt4+l;ift4=3 thent4case minO iswhen 0000 w=ML=T11110010010 ”=T 0100100 ”;0011ff=10110000tt;when H0100M=M10011001when h0101m=m10010010m;when ”0110”=”10000010when ,01ir=M11111000M;when M1000 H=hl 00
13、00000r,;when m1001m=m10010000m; when othersNULL;end case;01case mini iswhen ff0000w=MH=Millll00r; when 0011 ,r= T 0110000 ”;0100 ”=T 0011001”;0101=T0010010”;0110”=T0000010”;Oil 1”=T1111000”; when T000”=T0000000”; when T001”= TOO 10000when T0case hO is0000”=HL10110000ff;0100”=T0011001=T00100100111”=
14、when M1001M=M10010000M; when others=NULL;when ,H,=case hl isHH01111001”=T0010000when others =null;end process p2; end one;j scan_teddklML7.O-4HX3.0MH7.OTh17.4jHL7.Omirv33. .0Bmin17.4inst17五、端口设定k: button2 , set: buttonl , reset: buttonO ;Bell: SW1用于开关蜂鸣器;=Q 忤Qa 就 rwls()pe)AST iiTTaTGrep) as*2 irfifl
15、Q卩吨asp 匹“(ir) asz SFTT3 哪)asp orTiaOrcpjftsi SHF(4FW)A5*Z STiTGfchp) As*i on ihOfvp) ast rhfzsm - t . r; : . -0PW)AS7 tGOPOPP)AS7 【心(myftwz wra珂 tS25単呼呼制 ligg缈呷仮 TiigSSi: -i j.=TiS(W 卿)便 onTzflQP 卿Wl INiQ与綱A? fSTZaOrep) as- onTI6pw) as*z 537JOrvp) AS*Z OnTF4Fep)ft$-Z STTb*ftpcw) AS*Z DNZfl3 沖)as 丘 on7b“却 A 2ON LB4叽即)EON ZQ却 AST:DhTZBOfCp)AS7otTzb-Q 咛p)AST| : OF VP) ASTorrisqQMPP”讥I2d 2CMd ToJd uTSod bud ba TaTEd TbTHj eFmjrczojncxinoE;P)gpFG-noinch:Mis o iTS石呼 QOkins4 更 T 丘 ZE ZE uZH N3d :I汀皿 【Ed nHMd : nsMJd nrwid nrwjd nTNJd 就VMM nrwid a3Njd
copyright@ 2008-2022 冰豆网网站版权所有
经营许可证编号:鄂ICP备2022015515号-1