資源描述:
《EDA數字鐘程序代碼.doc》由會員上傳分享,免費在線閱讀,更多相關內容在教育資源-天天文庫。
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)--)--1HZ--toti
2、merthennum:=1;qout<=notqout;elsenum:=num+1;endif;if(num1=1)--)--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:out
3、std_logic_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'event
4、andkey_que='0'thenflag<=notflag;endif;endprocess;process(clk2,keys)--如果用撥碼開關,就將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
5、:=min+1;elsescn:=scn+1;endif;ifmin=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:=
6、0;elsehor:=hor+1;endif;--keys<="00";when"101"=>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;--除法,特別是取余數運算會占用很多邏輯資源hH<="0000"+h;hL<="0000"+(hor-
7、10*h);m:=min/10;mH<="0000"+m;mL<="0000"+(min-10*m);s:=scn/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;archit
8、ecturekey_qudouofqudouisbeginprocess(clk)--5msvariablenum:integer:=0;variables:integer:=0;beginifclk'ev