数字电子时钟.docx
- 文档编号:30716897
- 上传时间:2023-08-19
- 格式:DOCX
- 页数:13
- 大小:16.40KB
数字电子时钟.docx
《数字电子时钟.docx》由会员分享,可在线阅读,更多相关《数字电子时钟.docx(13页珍藏版)》请在冰豆网上搜索。
数字电子时钟
libraryIEEE;
useIEEE.STD_LOGIC_1164.ALL;
useIEEE.STD_LOGIC_ARITH.ALL;
useIEEE.STD_LOGIC_UNSIGNED.ALL;
----Uncommentthefollowinglibrarydeclarationifinstantiating
----anyXilinxprimitivesinthiscode.
--libraryUNISIM;
--useUNISIM.VComponents.all;
entityclockis
port(
clk:
instd_logic;
rst:
instd_logic;
inc_min:
instd_logic;
sub_min:
instd_logic;
inc_hour:
instd_logic;
sub_hour:
instd_logic;
sel:
outstd_logic_vector(3downto0);
q:
outstd_logic_vector(7downto0));
endclock;
architectureBehavioralofclockis
signalsec_counter1:
std_logic_vector(3downto0);
signalsec_counter2:
std_logic_vector(3downto0);
signalmin_counter1:
std_logic_vector(3downto0);
signalmin_counter2:
std_logic_vector(3downto0);
signalhour_counter1:
std_logic_vector(3downto0);
signalhour_counter2:
std_logic_vector(3downto0);
signaldivcounter:
std_logic_vector(27downto0);
signaldiv_clk:
std_logic;
signalscancounter:
std_logic_vector(10downto0);
signalscan_clk:
std_logic;
signalscan_out:
std_logic_vector(2downto0);
signalsecseg1,secseg2,minseg1,minseg2,hourseg1,hourseg2:
std_logic_vector(7downto0);
begin
--计数时钟,对外部输入时钟分频,此处只适用于仿真,实际进行时间计数时,分频后时钟应该满足1HZ。
process(rst,clk)
begin
if(rst='0')then
divcounter<=(others=>'0');
div_clk<='0';
elsif(rising_edge(clk))then
if(divcounter=X"17D7840")then
divcounter<=(others=>'0');
div_clk<=notdiv_clk;
else
divcounter<=divcounter+'1';
endif;
endif;
endprocess;
--仿真时数码管扫描?
?
钟,实?
?
中?
韪菥咛迩榭鼋械鹘馐敝悠德?
process(rst,clk)
begin
if(rst='0')then
scancounter<=(others=>'0');
scan_clk<='0';
elsif(rising_edge(clk))then
if(scancounter="00011111111")then
scancounter<=(others=>'0');
scan_clk<=notscan_clk;
else
scancounter<=scancounter+'1';
endif;
endif;
endprocess;
--时钟计数部分主进程
--时钟复位
clock:
process(div_clk,rst)
begin
if(rst='0')then
sec_counter1<=X"0";
sec_counter2<=X"0";
min_counter1<=X"0";
min_counter2<=X"0";
hour_counter1<=X"0";
hour_counter2<=X"0";
--手动调分,递增
elsif(rising_edge(div_clk))then
if(inc_min='0')then
if(min_counter1=X"9")then
min_counter1<=X"0";
if(min_counter2>=X"5")then
min_counter2<=X"0";
else
min_counter2<=min_counter2+1;
endif;
else
min_counter1<=min_counter1+1;
endif;
--手动调分,递减
elsif(sub_min='0')then
if(min_counter1=X"0")then
min_counter1<=X"9";
if(min_counter2=X"0")then
min_counter2<=X"5";
else
min_counter2<=min_counter2-1;
endif;
else
min_counter1<=min_counter1-1;
endif;
--手动调时,增时
elsif(inc_hour='0')then
if(hour_counter2=X"2")then
if(hour_counter1=X"3")then
hour_counter1<=X"0";
hour_counter2<=X"0";
else
hour_counter1<=hour_counter1+1;
endif;
else
if(hour_counter1=X"9")then
hour_counter1<=X"0";
hour_counter2<=hour_counter2+1;
else
hour_counter1<=hour_counter1+1;
endif;
endif;
--手动调时,减时
elsif(sub_hour='0')then
if(hour_counter1=X"0")then
if(hour_counter2=X"0")then
hour_counter1<=X"3";hour_counter2<=X"2";
else
hour_counter2<=hour_counter2-1;
hour_counter1<=X"9";
endif;
else
hour_counter1<=hour_counter1-1;
endif;
--时分秒正常计数
else
if(sec_counter1>=X"9")then
sec_counter1<=X"0";
if(sec_counter2>=X"5")then
sec_counter2<=X"0";
if(min_counter1>=X"9")then
min_counter1<=X"0";
if(min_counter2>=X"5")then
min_counter2<=X"0";
if(hour_counter2=X"2")then
if(hour_counter1=X"3")then
hour_counter1<=X"0";
hour_counter1<=X"0";
hour_counter2<=X"0";
hour_counter2<=X"0";
hour_counter1<=hour_counter1+1;
endif;
else
if(hour_counter1=X"9")then
hour_counter1<=X"0";
hour_counter2<=hour_counter2+1;
else
hour_counter1<=hour_counter1+1;
endif;
endif;
else
min_counter2<=min_counter2+1;
endif;
else
min_counter1<=min_counter1+1;
endif;
else
sec_counter2<=sec_counter2+1;
endif;
else
sec_counter1<=sec_counter1+1;
endif;
endif;
endif;
endprocessclock;
--生成扫描时钟
process(rst,scan_clk)
begin
if(rst='0')then
scan_out<="000";
elsif(rising_edge(scan_clk))then
if(scan_out="011")then
scan_out<="000";
else
scan_out<=scan_out+1;
endif;
endif;
endprocess;
--扫描输出进程
process(scan_out)
begin
casescan_outis
when"000"=>q<=secseg1;sel<="0001";
when"001"=>q<=secseg2;sel<="0010";
when"010"=>q<=minseg1;sel<="0100";
when"011"=>q<=minseg2;sel<="1000";
--when"100"=>q<=hourseg1;--sel<="100";
--when"101"=>q<=hourseg2;--sel<="101";
whenothers=>q<="00000000";sel<="0000";
endcase;
endprocess;
--秒低位显示
second_counter1:
process(sec_counter1)
begin
casesec_counter1is
when"0000"=>secseg1<="10111111";
when"0001"=>secseg1<="10000110";
when"0010"=>secseg1<="11011011";
when"0011"=>secseg1<="11001111";
when"0100"=>secseg1<="11100110";
when"0101"=>secseg1<="11101101";
when"0110"=>secseg1<="11111101";
when"0111"=>secseg1<="10000111";
when"1000"=>secseg1<="11111111";
when"1001"=>secseg1<="11101111";
whenothers=>secseg1<="11111111";
endcase;
endprocesssecond_counter1;
--秒高位显示
second_counter2:
process(sec_counter2)
begin
casesec_counter2is
when"0000"=>secseg2<="00111111";
when"0001"=>secseg2<="00000110";
when"0010"=>secseg2<="01011011";
when"0011"=>secseg2<="01001111";
when"0100"=>secseg2<="01100110";
when"0101"=>secseg2<="01101101";
whenothers=>secseg2<="01111111";
endcase;
endprocesssecond_counter2;
--分低位显示
minute_counter1:
process(min_counter1)
begin
casemin_counter1is
when"0000"=>minseg1<="10111111";
when"0001"=>minseg1<="10000110";
when"0010"=>minseg1<="11011011";
when"0011"=>minseg1<="11001111";
when"0100"=>minseg1<="11100110";
when"0101"=>minseg1<="11101101";
when"0110"=>minseg1<="11111101";
when"0111"=>minseg1<="10000111";
when"1000"=>minseg1<="11111111";
when"1001"=>minseg1<="11101111";
whenothers=>minseg1<="11111111";
endcase;
endprocessminute_counter1;
--分高位显示
minute_counter2:
process(min_counter2)
begin
casemin_counter2is
when"0000"=>minseg2<="00111111";
when"0001"=>minseg2<="00000110";
when"0010"=>minseg2<="01011011";
when"0011"=>minseg2<="01001111";
when"0100"=>minseg2<="01100110";
when"0101"=>minseg2<="01101101";
whenothers=>minseg2<="01111111";
endcase;
endprocessminute_counter2;
--小时低位显示
hor_counter1:
process(hour_counter1)
begin
casehour_counter1is
when"0000"=>hourseg1<="10111111";
when"0001"=>hourseg1<="10000110";
when"0010"=>hourseg1<="11011011";
when"0011"=>hourseg1<="11001111";
when"0100"=>hourseg1<="11100110";
when"0101"=>hourseg1<="11101101";
when"0110"=>hourseg1<="11111101";
when"0111"=>hourseg1<="10000111";
when"1000"=>hourseg1<="11111111";
when"1001"=>hourseg1<="11101111";
whenothers=>hourseg1<="11111111";
endcase;
endprocess;
--小时高位显示
hor_counter2:
process(hour_counter2)
begin
casehour_counter2is
when"0000"=>hourseg2<="00111111";
when"0001"=>hourseg2<="00000110";
when"0010"=>hourseg2<="01011011";
whenothers=>hourseg2<="01111111";
endcase;
endprocess;
endBehavioral;
------------------引脚(.ucf文件)如下-------------------
#clk:
instd_logic;
#rst:
instd_logic;
#inc_min:
instd_logic;
#sub_min:
instd_logic;
#inc_hour:
instd_logic;
#sub_hour:
instd_logic;
#sel:
outstd_logic_vector(2downto0);
#q:
outstd_logic_vector(7downto0));
#PACE:
StartofConstraintsgeneratedbyPACE
#PACE:
StartofPACEI/OPinAssignments
NET"clk"LOC="p80";
NET"inc_hour"LOC="p20"|PULLUP;#SW3
NET"inc_min"LOC="p32";#SW1
NET"q<0>"LOC="p47";#Bank=1,Pinname=IO_L10P_1,Type=I/O,Schname=JD4(a)
NET"q<1>"LOC="p50";#Bank=1,Pinname=IO_L19P_1,Type=I/O,Schname=JD5(b)
NET"q<2>"LOC="p48";#Bank=1,Pinname=IO_L23P_1/HDC,Type=DUAL,Schname=JD6(c)
NET"q<3>"LOC="p41";#Bank=1,Pinname=IO_L23N_1/LDC0,Type=DUAL,Schname=JD7(d)
NET"q<4>"LOC="p45";#Bank=1,Pinname=IO_L20P_1,Type=I/O,Schname=JD8(e)
NET"q<5>"LOC="p42";#Bank=1,Pinname=IO_L13P_1/A6/RHCLK4/IRDY1,Type=RHCLK/DUAL,Schname=JD3(f)
NET"q<6>"LOC="p49";#Bank=1,Pinname=IO_L17P_1,Type=I/O,Schname=JD1(g)
NET"q<7>"LOC="p40";
NET"rst"LOC="p43";#SW0
NET"sel<0>"LOC="p34";#Bank=1,Pinname=IO_L19N_1,Type=I/O,Schname=SEG_SELIN1
NET"sel<1>"LOC="p35";#Bank=1,Pinname=IO_L16N_1/A0,Type=DUAL,Schname=SEG_SELIN2
NET"sel<2>"LOC="p36";#Bank=1,Pinname=IO_L24P_1/LDC1,Type=DUAL,Schname=SEG_SELIN3
NET"sel<3>"LOC="p39";#Bank=1,Pinname=IO_L21P_1,Type=I/O,Schname=SEG_SELIN4
NET"sub_hour"LOC="p14"|PULLUP;#SW4
NET"sub_min"LOC="p26";#SW2
#PACE:
StartofPACEAreaConstraints
#PACE:
StartofPACEProhibitConstraints
#PACE:
EndofConstraintsgeneratedbyPACE
- 配套讲稿:
如PPT文件的首页显示word图标,表示该PPT已包含配套word讲稿。双击word图标可打开word文档。
- 特殊限制:
部分文档作品中含有的国旗、国徽等图片,仅作为作品整体效果示例展示,禁止商用。设计者仅对作品中独创性部分享有著作权。
- 关 键 词:
- 数字 电子 时钟