資源描述:
《EDA數(shù)字鐘程序代碼》由會員上傳分享,免費在線閱讀,更多相關(guān)內(nèi)容在教育資源-天天文庫。
1、--分頻器libraryieee;useieee.std_logic_1164.all;entityfenpinisport(clk:instd_logic;qH:bufferstd_logic;qout:bufferstd_logic);endentity;architecturec20offenpinisbeginprocess(clk)variablenum:integer:=1;variablenum1:integer:=1beginifclk'eventandclk='0'thenif(num=2)--0000000)--1HZ--10000000to
2、timerthennum:=1;qout<=notqout;elsenum:=num+1;endif;if(num1=1)--000000)--1000HZ--10000toweithennum1:=1;qH<=notqH;elsenum1:=num1+1;endif;endif;endprocess;endc20;--timerlibraryieee;useieee.std_logic_1164.all;useieee.std_logic_unsigned.all;entityClock3isport(clk:instd_logic;duan:outstd_l
3、ogic_vector(3downto0);wei:instd_logic_vector(2downto0);wei2:outstd_logic_vector(2downto0));endentity;architecturecloofClock3issignalclk2:std_logic;signalkeys:std_logic_vector(2downto0);beginkeys<=key_h&key_m&key_s;clk2<=clkorflag;process(key_que)beginifkey_que'eventandkey_que='0'then
4、flag<=notflag;endif;endprocess;process(clk2,keys)--如果用撥碼開關(guān),就將clk2改為clkbegincaseflagiswhen'0'=>ifclk2'eventandclk2='0'then---正常計時ifscn=59andmin=59andhor=23thenscn:=0;min:=0;hor:=0;elsifscn=59andmin=59thenscn:=0;min:=0;hor:=hor+1;elsifscn=59thenscn:=0;min:=min+1;elsescn:=scn+1;endif;if
5、min=59---整點報時500hzthenifscn=50orscn=52orscn=54orscn=56orscn=58thenmusic_out<=musicL;elsemusic_out<='0';endif;elsifmin=0andscn=0---整點報時1000HZthenmusic_out<=musicH;elsemusic_out<='0';endif;endif;when'1'=>casekeysiswhen"011"=>ifhor=23thenhor:=0;elsehor:=hor+1;endif;--keys<="00";when"101
6、"=>ifmin=59thenmin:=0;elsemin:=min+1;endif;--keys<="00";when"110"=>ifscn=59thenscn:=0;elsescn:=scn+1;endif;--keys<="00";whenothers=>null;--keys<="00";endcase;endcase;h:=hor/10;--除法,特別是取余數(shù)運算會占用很多邏輯資源hH<="0000"+h;hL<="0000"+(hor-10*h);m:=min/10;mH<="0000"+m;mL<="0000"+(min-10*m);s:=scn
7、/10;sH<="0000"+s;sL<="0000"+(scn-10*s);endprocess;endclo;去抖libraryieee;--去抖電路useieee.std_logic_1164.all;useieee.std_logic_unsigned.all;entityqudouisport(clk,key_in:instd_logic;key_out:outstd_logic);endentity;architecturekey_qudouofqudouisbeginprocess(clk)--5msvariablenum:integer:=0;v
8、ariables:int