万年历时钟表.docx
- 文档编号:16421513
- 上传时间:2023-07-13
- 格式:DOCX
- 页数:28
- 大小:1.13MB
万年历时钟表.docx
《万年历时钟表.docx》由会员分享,可在线阅读,更多相关《万年历时钟表.docx(28页珍藏版)》请在冰点文库上搜索。
万年历时钟表
本次课程设计要求显示万年历时钟表。
要求实现正常的时、分、秒计数。
二十四小时的时间计时。
本次课程设计采用黑金AX301开发平台。
相关硬件原理图和PCB图见文件夹。
一.各个设计模块描述
(一)计时模块
1.秒计数是由一个六十进制的计数器构成,生成元器件如下
Clk:
驱动秒计时器的时钟信号
Clr:
校准时间时清零的输入端
En:
使能端
Sec0[3..0]sec1[3..0]:
秒的高位显示,低位显示
Co:
进位输出端,作为分的clk输入
代码如下:
libraryieee;
useieee.std_logic_1164.all;
useieee.std_logic_unsigned.all;
entitysecondis
port(clk,clr,en:
instd_logic;
sec0,sec1:
outstd_logic_vector(3downto0);
co:
outstd_logic);
endsecond;
architecturesecofsecondis
SIGNALcnt1,cnt0:
std_logic_vector(3downto0);
begin
process(clk)
begin
if(clr='0')then
cnt0<="0000";
cnt1<="0000";
elsif(clk'eventandclk='1')then
if(en='1')then
ifcnt1="0101"andcnt0="1000"then
co<='1';
cnt0<="1001";
elsifcnt0<"1001"then
cnt0<=(cnt0+1);
else
cnt0<="0000";
ifcnt1<"0101"then
cnt1<=cnt1+1;
else
cnt1<="0000";
co<='0';
endif;
endif;
endif;
endif;
sec1<=cnt1;
sec0<=cnt0;
endprocess;
endsec;
仿真图如下:
2.分计数是由六十进制的计数器构成,生成元器件如下
Clk:
设置分输入和秒进位的或输入
En:
使能输入
Min1[3..0]min0[3..0]:
分的高位显示,低位显示
Co:
向时的进位输出
代码如下:
libraryieee;
useieee.std_logic_1164.all;
useieee.std_logic_unsigned.all;
entityminuteis
port(clk,en:
instd_logic;
min1,min0:
outstd_logic_vector(3downto0);
co:
outstd_logic);
endminute;
architectureminofminuteis
SIGNALcnt1,cnt0:
std_logic_vector(3downto0);
begin
process(clk)
begin
if(clk'eventandclk='1')then
ifen='1'then
ifcnt1="0101"andcnt0="1001"then
co<='1';
cnt0<="0000";
cnt1<="0000";
elsifcnt0<"1001"then
cnt0<=(cnt0+1);
else
cnt0<="0000";
cnt1<=cnt1+1;
co<='0';
endif;
endif;
endif;
min1<=cnt1;
min0<=cnt0;
endprocess;
endmin;
仿真图如下:
3.时计数是由二十四进制的计数器构成,生成元器件如下
Clk:
设置时间输入和分进位输入的或
en:
使能端
h1[3..0]h0[3..0]:
时的高位显示和低位显示
代码如下:
libraryieee;
useieee.std_logic_1164.all;
useieee.std_logic_unsigned.all;
entityhouris
port(clk,en:
instd_logic;
h1,h0:
outstd_logic_vector(3downto0));
endhour;
architecturebehaofhouris
signalcnt1,cnt0:
std_logic_vector(3downto0);
begin
process(clk)
begin
if(clk'eventandclk='1')then
ifen='1'then
ifcnt1="0010"andcnt0="0011"then
cnt1<="0000";
cnt0<="0000";
elsifcnt0<"1001"then
cnt0<=cnt0+1;
else
cnt0<="0000";
cnt1<=cnt1+1;
endif;
endif;
endif;
h1<=cnt1;
h0<=cnt0;
endprocess;
endbeha;
仿真图如下:
(二)设置时间模块
1.按键去抖动,生成元器件如下
Clk:
256hz频率输入
Reset:
接GND
Din:
接按键
Dout:
输出传给按键选择器
代码如下
libraryieee;
useieee.std_logic_1164.all;
useieee.std_logic_unsigned.all;
useieee.std_logic_arith.all;
entitydebounceis
port(clk,reset:
instd_logic;--200HZ
din:
instd_logic;
dout:
outstd_logic);
enddebounce;
architectureaofdebounceis
typestateis(s0,s1,s2);
signalcurrent:
state;
begin
process(clk,reset,din)
begin
if(reset='1')then
current<=s0;
dout<='1';
elsif(clk'eventandclk='1')then
casecurrentis
whens0=>dout<='1';
if(din='0')then
current<=s1;
else
current<=s0;
endif;
whens1=>dout<='1';
if(din='0')then
current<=s2;
else
current<=s0;
endif;
whens2=>dout<='0';
if(din='0')then
current<=s2;
else
current<=s0;
endif;
whenothers=>dout<='1';
current<=s0;
endcase;
endif;
endprocess;
enda;
仿真图如下:
2.按键选择器,生成元器件如下:
Clk:
16hz输入
Key1:
按键调分的输入
Key2:
按键调时的输入
Key3:
按键秒清零的输入
Led1:
输出信号给分元器件
Led2:
输出信号给时元器件
Led3:
输出清零信号给秒元器件
代码如下:
libraryieee;
useieee.std_logic_1164.all;
useieee.std_logic_unsigned.all;
useieee.std_logic_arith.all;
entityctr1is
port(clk:
instd_logic;--10HZ
key1,key2,key3,key4:
instd_logic;
led1,led2,led3,led4:
outstd_logic);
endctr1;
architectureaofctr1is
begin
process(clk)
begin
if(clk'eventandclk='1')then
if(key1='0')then
led1<='1';led2<='0';led3<='0';led4<='0';
elsif(key2='0')then
led1<='0';led2<='1';led3<='0';led4<='0';
elsif(key3='0')then
led1<='0';led2<='0';led3<='1';led4<='0';
elsif(key4='0')then
led1<='0';led2<='0';led3<='0';led4<='1';
else
led1<='0';led2<='0';led3<='0';led4<='0';
endif;
endif;
endprocess;
enda;
仿真图如下:
(三)整点报时模块
生成元器件如下:
Clk1:
接512hz
Clk2clk:
En:
使能输入
M1[3..0]m0[3..0]:
接分的高位输出和低位输出
S1[3..0]s0[3..0]:
接秒的高位输出和低位输出
Speaker:
连接蜂鸣器
代码如下:
libraryieee;
useieee.std_logic_1164.all;
useieee.std_logic_unsigned.all;
entityxiangis
port(m1,m0,s1,s0:
instd_logic_vector(3downto0);
en,clk1,clk2,clk:
instd_logic;
speaker:
outstd_logic);
endxiang;
architecturesss_arcofxiangis
begin
process(clk,clk1,clk2,m1,m0,s1,s0)
begin
if(en='1')then
speaker<=clk;
elsif(m1="0101"andm0="1001")then
if(s1="0101")then
if(s0="1001")then
speaker<=clk2;--1024HZ
elsif(s0="0001"ors0="0011"ors0="0101"ors0="0111")then
speaker<=clk1;--512HZ
endif;
else
speaker<='0';
endif;
elsif(m0<"1001"orm1<"0101"ors1<"0101")then
speaker<='0';
endif;
endprocess;
endsss_arc;
仿真图如下:
(四)显示时间模块
1.模八的器件控制八个数码管显示的循环,生成元器件如下
Clk:
输入
Clr:
接GND
En:
使能端
Y[2..0]:
输出接数码管三个接受端
代码如下:
libraryieee;
useieee.std_logic_1164.all;
useieee.std_logic_unsigned.all;
entitymo8is
port(clr,clk,en:
instd_logic;
y:
outstd_logic_vector(2downto0));
endmo8;
architecturebehaofmo8is
signalp:
std_logic_vector(2downto0);
begin
process(clk)
begin
ifclk'eventandclk='1'then
ifen='1'then
ifp="111"then
p<="000";
elsifp<"111"then
p<=p+1;
endif;
endif;
endif;
y<=p;
endprocess;
endbeha;
仿真图如下:
2.八选一的器件控制数码管的亮或不亮,生成元器件如下
Sel【2..0】:
连接模八器件
M7[3..0]m6[3..0]:
连接秒的高位和低位输出
M5[3..0]:
接vcc(显示横)
M4[3..0]m3[3..0]:
接分的高位和低位输出
M2[3..0]:
接vcc(显示横)
M1[3..0]m0[3..0]:
连接时的高位低位输出
Y[3..0]:
输出给数码管显示
代码如下:
libraryieee;
useieee.std_logic_1164.all;
entitymux8_1is
port(m0,m1,m2,m3,m4,m5,m6,m7:
instd_logic_vector(3downto0);
sel:
instd_logic_vector(2downto0);
y:
outstd_logic_vector(3downto0));
endmux8_1;
architecturearcofmux8_1is
begin
process(sel)
begin
caseselis
when"000"=>y<=m0;
when"001"=>y<=m1;
when"010"=>y<=m2;
when"011"=>y<=m3;
when"100"=>y<=m4;
when"101"=>y<=m5;
when"110"=>y<=m6;
when"111"=>y<=m7;
whenothers=>y<="XXXX";
endcase;
endprocess;
endarc;
仿真图如下:
3.数码管显示器件,生成元器件如下
Num[3..0]:
接收八选一的输出信号
Y[6..0]:
驱动数码管显示
代码如下:
libraryieee;
useieee.std_logic_1164.all;
entityxianshiis
port(num:
instd_logic_vector(3downto0);
y:
outstd_logic_vector(6downto0));
endxianshi;
architecturebehaofxianshiis
begin
process(num)
begin
casenumis
when"0000"=>y<="0111111";
when"0001"=>y<="0000110";
when"0010"=>y<="1011011";
when"0011"=>y<="1001111";
when"0100"=>y<="1100110";
when"0101"=>y<="1101101";
when"0110"=>y<="1111101";
when"0111"=>y<="0000111";
when"1000"=>y<="1111111";
when"1001"=>y<="1101111";
whenothers=>y<="1000000";
endcase;
endprocess;
endbeha;
仿真图如下:
(五)分频模块
分频器生成的元器件如下:
Clk:
时钟输入
Clk512:
512hz给响铃模块
Clk1:
1hz输出给秒计数器
Clk16:
16hz输出给按键选择器
Clk256:
256hz输出给按键抖动
代码如下:
libraryieee;
useieee.std_logic_1164.all;
useieee.std_logic_unsigned.all;
entityfenpinis
port(clk:
instd_logic;
--q:
outstd_logic_vector(9downto0);
clk512,clk4,clk1,clk16,clk256:
outstd_logic);
endfenpin;
architecturebehaveoffenpinis
signaly:
std_logic_vector(9downto0);
begin
process(clk)
begin
if(clk='1')then
if(y="1111111111")then
y<="0000000000";
clk512<=y(0);
clk256<=y
(1);
clk16<=y(5);
clk4<=y(7);
clk1<=y(9);
else
y<=y+'1';
clk512<=y(0);
clk256<=y
(1);
clk16<=y(5);
clk4<=y(7);
clk1<=y(9);
endif;
endif;
endprocess;
endbehave;
仿真图如下:
闹钟模块
1.比较器,比较当时显示时间与设置的闹钟时间是否相等,如相等,输出信号给蜂鸣器。
生成元器件如下:
Clkclk1:
使能输入
H0[3..0]h1[3..0]:
闹钟设置时间的分输入
H3[3..0]h2[3..0]:
闹钟设置时间的时输入
S0[3..0]s1[3..0]:
现在时间的分的输入
S2[3..0]s3[3..0]:
现在时间的时的输入
Y:
输出信号给蜂鸣器
代码如下:
libraryieee;
useieee.std_logic_1164.all;
useieee.std_logic_unsigned.all;
entitybijiao2is
port(clk,clk1:
instd_logic;
h0,h1,h2,h3,s0,s1,s2,s3:
instd_logic_vector(3downto0);
y:
outstd_logic);
endbijiao2;
architectureminofbijiao2is
signalc:
std_logic;
begin
process(clk,clk1,h0,h1,h2,h3,s0,s1,s2,s3)
begin
if(clk'eventandclk='1')then
ifh0(0)=s0(0)andh0
(1)=s0
(1)andh0
(2)=s0
(2)andh0(3)=s0(3)andh1(0)=s1(0)andh1
(1)=s1
(1)andh1
(2)=s1
(2)andh1(3)=s1(3)andh2(0)=s2(0)andh2
(1)=s2
(1)andh2
(2)=s2
(2)andh2(3)=s2(3)andh3(0)=s3(0)andh3
(1)=s3
(1)andh3
(2)=s3
(2)andh3(3)=s3(3)then
y<=clk1;
endif;
endif;
endprocess;
endmin;
二.整体电路图如下
数码管显示24h、60min、60s。
在正中间有个时、分、秒的输出。
这些时、分、秒的输出经过“八选一的器件控制数码管的亮或不亮”,输出y[3..0]。
八选一的器件控制数码管的亮或不亮”,输出的y[3..0],经过显示译码器输出给7段数据管显示。
下面的分频器输出时、分、秒控制其清零。
从而实现校准时间时秒清零的功能。
报警元器件如下图所示。
它分别接分的高位输出和低位输出、秒的高位输出和低位输出。
从而实现整点报时的功能。
比较器2,比较当时显示时间与设置的闹钟时间是否相等,如相等,输出信号给蜂鸣器。
从而实现闹钟功能。
- 配套讲稿:
如PPT文件的首页显示word图标,表示该PPT已包含配套word讲稿。双击word图标可打开word文档。
- 特殊限制:
部分文档作品中含有的国旗、国徽等图片,仅作为作品整体效果示例展示,禁止商用。设计者仅对作品中独创性部分享有著作权。
- 关 键 词:
- 万年 历时 钟表