实验五数字时钟的设计课案.docx
《实验五数字时钟的设计课案.docx》由会员分享,可在线阅读,更多相关《实验五数字时钟的设计课案.docx(16页珍藏版)》请在冰豆网上搜索。
实验五数字时钟的设计课案
实验五数字时钟的设计
实验性质:
综合性实验级别:
开课单位:
信息与通信工程学院通信工程系学时:
4学时
一、实验目的:
1、学习用VHDL语言实现比较大型的电路的方法。
2、继续巩固cpld技术层次化设计方法。
二、实验器材:
计算机、QuartusII软件
三、实验内容:
设计一数字时钟,要求具有时、分、秒、计数显示功能,以24小时循环计时;具有清零,调节小时,分钟功能;具有整点报时功能。
四、实验步骤:
1、根据电路特点,用层次设计的概念,将此任务分成若干模块,规定每一模块的功能和各模块之间的接口。
让几个学生分作和调试其中之一,然后再将各模块合起来联试。
以培养学生之间的合作精神,同时加深层次化设计概念。
2、了解软件的元件管理深层含义,以及模块元件之间的连接概念,对于不同目录下的同一设计,如何融合。
3、模块说明:
各种进制的计数及时钟控制模块(10进制、6进制、24进制)
扫描分时显示,译码模块
各模块都用VHDL语言编写
五、实验模块:
秒模块
LIBRARYieee;
useieee.std_logic_1164.all;
useieee.std_logic_unsigned.all;
ENTITYsecondIS
PORT(
clk,reset,setmin:
INSTD_LOGIC;
enmin:
OUTSTD_LOGIC;
da0out:
outstd_logic_vector(6downto0));
ENDentitysecond;
ARCHITECTUREfunOFsecondIS
SIGNALcount:
STD_LOGIC_VECTOR(6downto0);
BEGIN
da0out<=count;
process(clk,reset,setmin)
begin
--enmin<=k;
if(reset='0')then
count<="0000000";
elsif(setmin='0')then
enmin<=clk;
elsif(clk'eventandclk='1')then
if(count(3downto0)="1001")then
if(count<16#60#)then
if(count="1011001")then
enmin<='1';
count<="0000000";
ELSE
count<=count+7;
endif;
else
count<="0000000";
endif;
elsif(count<16#60#)then
count<=count+1;
enmin<='0'after100ns;
else
count<="0000000";
endif;
endif;
endprocess;
ENDfun;
分析:
脉冲从0计数至59,向前进1,enmin由低电平变至高电平。
分模块
LIBRARYieee;
useieee.std_logic_1164.all;
useieee.std_logic_unsigned.all;
ENTITYminuteIS
PORT(
clk,reset,sethour:
INSTD_LOGIC;
enhour:
OUTSTD_LOGIC;
da1out:
outstd_logic_vector(6downto0));
ENDentityminute;
ARCHITECTUREfunOFminuteIS
SIGNALcount:
STD_LOGIC_VECTOR(6downto0);
BEGIN
da1out<=count;
process(clk,reset,sethour)
begin
--enmin<=k;
if(reset='0')then
count<="0000000";
elsif(sethour='0')then
enhour<=clk;
elsif(clk'eventandclk='1')then
if(count(3downto0)="1001")then
if(count<16#60#)then
if(count="1011001")then
enhour<='1';
count<="0000000";
ELSE
count<=count+7;
endif;
else
count<="0000000";
endif;
elsif(count<16#60#)then
count<=count+1;
enhour<='0'after100ns;
else
count<="0000000";
endif;
endif;
endprocess;
ENDfun;
分析:
脉冲从0计数至59,向前进1,enhour由低电平变至高电平。
时模块
LIBRARYieee;
useieee.std_logic_1164.all;
useieee.std_logic_unsigned.all;
ENTITYhourIS
PORT(
clk,reset,setweek:
INSTD_LOGIC;
enweek:
OUTSTD_LOGIC;
da2out:
outstd_logic_vector(6downto0));
ENDentityhour;
ARCHITECTUREfunOFhourIS
SIGNALcount:
STD_LOGIC_VECTOR(6downto0);
BEGIN
da2out<=count;
process(clk,reset,setweek)
begin
--enmin<=k;
if(reset='0')then
count<="0000000";
elsif(setweek='0')then
enweek<=clk;
elsif(clk'eventandclk='1')then
if(count(3downto0)="1001")then
if(count<16#23#)then
if(count="00100011")then
enweek<='1';
count<="0000000";
ELSE
count<=count+7;
endif;
else
count<="0000000";
endif;
elsif(count<16#23#)then
count<=count+1;
enweek<='0'after100ns;
else
count<="0000000";
endif;
endif;
endprocess;
ENDfun;
分析:
脉冲从0计数至23,复位从0重新开始。
显示模块
低位显示数码管
LIBRARYIEEE;
USEIEEE.STD_LOGIC_1164.ALL;
ENTITYshumaguanIS
PORT(a:
instd_logic_vector(6downto0);
y:
outstd_logic_vector(6downto0));
endshumaguan;
ARCHITECTUREbehOFshumaguanIS
BEGIN
process(a)
begin
casea(3downto0)is
when"0000"=>y<="1111110";
when"0001"=>y<="0110000";
when"0010"=>y<="1101101";
when"0011"=>y<="1111001";
when"0100"=>y<="0110011";
when"0101"=>y<="1011011";
when"0110"=>y<="1011111";
when"0111"=>y<="1110000";
when"1000"=>y<="1111111";
when"1001"=>y<="1111011";
whenothers=>y<="0000000";
endcase;
endprocess;
endbeh;
高位显示数码管
LIBRARYIEEE;
USEIEEE.STD_LOGIC_1164.ALL;
ENTITYshumaguanhighIS
PORT(a:
instd_logic_vector(6downto0);
y:
outstd_logic_vector(6downto0));
endshumaguanhigh;
ARCHITECTUREbehOFshumaguanhighIS
BEGIN
process(a)
begin
casea(6downto4)is
when"000"=>y<="1111110";
when"001"=>y<="0110000";
when"010"=>y<="1101101";
when"011"=>y<="1111001";
when"100"=>y<="0110011";
when"101"=>y<="1011011";
whenothers=>y<="0000000";
endcase;
endprocess;
endbeh;
小时高位显示数码管
LIBRARYIEEE;
USEIEEE.STD_LOGIC_1164.ALL;
ENTITYshumaguanhourIS
PORT(a:
instd_logic_vector(6downto0);
y:
outstd_logic_vector(6downto0));
endshumaguanhour;
ARCHITECTUREbehOFshumaguanhourIS
BEGIN
process(a)
begin
casea(6downto4)is
when"000"=>y<="1111110";
when"001"=>y<="0110000";
when"010"=>y<="1101101";
whenothers=>y<="0000000";
endcase;
endprocess;
endbeh;
分析:
将8421BCD码转化成7段码。
整点报时
libraryieee;
useieee.std_logic_1164.all;
useieee.std_logic_unsigned.all;
entityspeakeris
port(clk:
instd_logic;
speaksec:
instd_logic_vector(6downto0);
speakmin:
instd_logic_vector(6downto0);
speak:
outstd_logic);
endentityspeaker;
architecturefunofspeakeris
begin
process(clk,speakmin)
begin
if(clk'eventandclk='1')then
if(speakmin="0000000"andspeaksec="0000000")thenspeak<='1';elsespeak<='0';endif;
endif;
endprocess;
endfun;
分析:
当时钟计数到整点,即秒和分都等于0时蜂鸣器报警,以实现整点报时功能。
输入:
clk计数时钟信号,speaksec秒输出信号,speakmin分输出信号
输出:
报警信号
输出转换模块
1.六转一
libraryIEEE;
useIEEE.STD_LOGIC_1164.ALL;
useIEEE.STD_LOGIC_ARITH.ALL;
useIEEE.STD_LOGIC_UNSIGNED.ALL;
--Uncommentthefollowinglinestousethedeclarationsthatare
--providedforinstantiatingXilinxprimitivecomponents.
--libraryUNISIM;
--useUNISIM.VComponents.all;
entitysixtozerois
Port(d:
instd_logic_vector(6downto0);
out6:
outstd_logic;
out5:
outstd_logic;
out4:
outstd_logic;
out3:
outstd_logic;
out2:
outstd_logic;
out1:
outstd_logic;
out0:
outstd_logic);
endsixtozero;
architectureBehavioralofsixtozerois
begin
process(d)
Begin
out6<=d(6);
out5<=d(5);
out4<=d(4);
out3<=d(3);
out2<=d
(2);
out1<=d
(1);
out0<=d(0);
endprocess;
endBehavioral;
2.二转一
3.libraryIEEE;
useIEEE.STD_LOGIC_1164.ALL;
useIEEE.STD_LOGIC_ARITH.ALL;
useIEEE.STD_LOGIC_UNSIGNED.ALL;
--Uncommentthefollowinglinestousethedeclarationsthatare
--providedforinstantiatingXilinxprimitivecomponents.
--libraryUNISIM;
--useUNISIM.VComponents.all;
entitytwotozerois
Port(d:
instd_logic_vector(2downto0);
out2:
outstd_logic;
out1:
outstd_logic;
out0:
outstd_logic);
endtwotozero;
architectureBehavioraloftwotozerois
begin
process(d)
begin
out2<=d
(2);
out1<=d
(1);
out0<=d(0);
endprocess;
endBehavioral;
3.三转一
libraryIEEE;
useIEEE.STD_LOGIC_1164.ALL;
useIEEE.STD_LOGIC_ARITH.ALL;
useIEEE.STD_LOGIC_UNSIGNED.ALL;
--Uncommentthefollowinglinestousethedeclarationsthatare
--providedforinstantiatingXilinxprimitivecomponents.
--libraryUNISIM;
--useUNISIM.VComponents.all;
entitytretozerois
Port(d:
instd_logic_vector(6downto0);
out3:
outstd_logic;
out2:
outstd_logic;
out1:
outstd_logic;
out0:
outstd_logic);
endtretozero;
architectureBehavioraloftretozerois
begin
process(d)
begin
out3<=d(3);
out2<=d
(2);
out0<=d(0);
out0<=d(0);
endprocess;
endBehavioral;
整体工程图:
整体波形图
分析:
秒从0计数至59,向前进位,分加一;分从0计数至59,向前进位,时加一;此时整点报时模块工作,speak由低电平变为高电平。
刘德文:
各个模块的联调,组合
王梦丹:
显示模块
刘鹏媛:
秒和整点报时模块
王飞:
分和时模块
实验五
数
字
时
钟
的
设
计
组长:
刘德文
组员:
王梦丹
王飞
刘鹏媛