52电子时钟a.docx

上传人:b****1 文档编号:2800808 上传时间:2023-05-04 格式:DOCX 页数:13 大小:55.12KB
下载 相关 举报
52电子时钟a.docx_第1页
第1页 / 共13页
52电子时钟a.docx_第2页
第2页 / 共13页
52电子时钟a.docx_第3页
第3页 / 共13页
52电子时钟a.docx_第4页
第4页 / 共13页
52电子时钟a.docx_第5页
第5页 / 共13页
52电子时钟a.docx_第6页
第6页 / 共13页
52电子时钟a.docx_第7页
第7页 / 共13页
52电子时钟a.docx_第8页
第8页 / 共13页
52电子时钟a.docx_第9页
第9页 / 共13页
52电子时钟a.docx_第10页
第10页 / 共13页
52电子时钟a.docx_第11页
第11页 / 共13页
52电子时钟a.docx_第12页
第12页 / 共13页
52电子时钟a.docx_第13页
第13页 / 共13页
亲,该文档总共13页,全部预览完了,如果喜欢就下载吧!
下载资源
资源描述

52电子时钟a.docx

《52电子时钟a.docx》由会员分享,可在线阅读,更多相关《52电子时钟a.docx(13页珍藏版)》请在冰点文库上搜索。

52电子时钟a.docx

52电子时钟a

5.2电子时钟程序设计与仿真实验

1实验目的

设计一个含时/分/秒的电子时钟,并且具有可设置、清除的功能。

2实验原理

根据电子时钟设计要求,系统可以分为以下模块:

控制模块,基准时钟模块,计数器可预置模块,锁存器模块,LED译码模块,系统组成方框图如图5.2.1所示。

图5.2.1系统组成方框图

(1)10进制可预置计数器模块

时钟由时、分、秒组成,分、秒都为60进制。

由于需要使用LED显示时间,所以采用的计数器应该是10进制的,从而方便译码模块的通用。

而60进制计数器可以由10进制计数器和6进制计数器组成。

(2)6进制可预置计数器模块

要组成一个可预置的60进制计数器,还需要一个6进制的计数器,使用10进制的进位作为6进制的计数器的时钟信号可以组成一个60进制的计数器。

(3)24进制可预置计数器模块

时钟的小时是24进制的,所以必须设计一个24进制的可预置计数器。

显然,24进制计数器不可以使用6进制计数器和4进制计数器组成,因为这样做的24进制计数器将给译码带来麻烦。

(4)译码显示模块

一共有6个LED需要显示,所以需要6个译码模块。

3实验内容

(1)由CLK引入1Hz的时钟信号。

(2)由RESET引入总清零信号,dins、dinm、dinh分别引入秒、分、钟可预置信号。

(3)设计一个异步清零六(count6)进制计数器,一个异步清零十(count10)进制计数器和一个二十四(count24)进制计数器。

(4)设计一个BCD码到LED的七段译码器(led7s).

(5)设计一个含时/分/妙的电子时钟。

(6)对时钟电路进行下载

4实验预习与思考题

(1)学习用VHDL语言编写十进制,六进制,二十四进制计数器。

(2)怎样编写秒、分、钟可预置信号。

(3)用十进制和六进制组成六十进制计数器的级联方法。

(4)为什么时钟的二十四进制不用一个六进制和一个四进制组成。

5程序设计与仿真

(1)程序设计

①十进制计数器(count10.vhd)。

十进制计数器源程序如下:

libraryIEEE;

useIEEE.STD_LOGIC_1164.ALL;

useIEEE.STD_LOGIC_ARITH.ALL;

useIEEE.STD_LOGIC_UNSIGNED.ALL;

--Uncommentthefollowinglinestousethedeclarationsthatare

--providedforinstantiatingXilinxprimitivecomponents.

--libraryUNISIM;

-useUNISIM.VComponents.all;

entitycount10is

Port(clk:

instd_logic;

reset:

instd_logic;

din:

instd_logic_vector(3downto0);

dout:

outstd_logic_vector(3downto0);

c:

outstd_logic);

endcount10;

architectureBehavioralofcount10is

signalcount:

std_logic_vector(3downto0);

begin

dout<=count;

process(clk,reset,din)

begin

ifreset='0'then

count<=din;

c<='0';

elsifrising_edge(clk)then

ifcount="1001"then

count<="0000";

c<='1';

else

count<=count+1;

c<='0';

endif;

endif;

endprocess;

②六进制计数器(count6.vhd),六进制计数器源程序如下:

libraryIEEE;

useIEEE.STD_LOGIC_1164.ALL;

useIEEE.STD_LOGIC_ARITH.ALL;

useIEEE.STD_LOGIC_UNSIGNED.ALL;

--Uncommentthefollowinglinestousethedeclarationsthatare

--providedforinstantiatingXilinxprimitivecomponents.

--libraryUNISIM;

--useUNISIM.VComponents.all;

entitycount6is

Port(clk:

instd_logic;

reset:

instd_logic;

din:

instd_logic_vector(2downto0);

dout:

outstd_logic_vector(2downto0);

c:

outstd_logic);

endcount6;

architectureBehavioralofcount6is

signalcount:

std_logic_vector(2downto0);

begin

dout<=count;

process(clk,reset,din)

begin

ifreset='0'then

count<=din;

c<='0';

elsifrising_edge(clk)then

ifcount="101"then

count<="000";

c<='1';

else

count<=count+1;

c<='0';

endif;

endif;

endprocess;

③二十四进制计数器(count24.vhd),二十四进制计数器源程序如下:

libraryIEEE;

useIEEE.STD_LOGIC_1164.ALL;

useIEEE.STD_LOGIC_ARITH.ALL;

useIEEE.STD_LOGIC_UNSIGNED.ALL;

--Uncommentthefollowinglinestousethedeclarationsthatare

--providedforinstantiatingXilinxprimitivecomponents.

--libraryUNISIM;

--useUNISIM.VComponents.all;

entitycount24is

Port(clk:

instd_logic;

reset:

instd_logic;

din:

instd_logic_vector(5downto0);

dout:

outstd_logic_vector(5downto0));

endcount24;

architectureBehavioralofcount24is

signalcount:

std_logic_vector(5downto0);

begin

dout<=count;

process(clk,reset,din)

begin

ifreset='0'then

count<=din;

elsifrising_edge(clk)then

ifcount(3downto0)="1001"then

count(3downto0)<="0000";

count(5downto4)<=count(5downto4)+1;

else

count(3downto0)<=count(3downto0)+1;

endif;

ifcount="100011"then

count<="000000";

endif;

endif;

endprocess;

④译码器源程序(led7s.vhd),译码器源程序如下,

libraryIEEE;

useIEEE.STD_LOGIC_1164.ALL;

useIEEE.STD_LOGIC_ARITH.ALL;

useIEEE.STD_LOGIC_UNSIGNED.ALL;

--Uncommentthefollowinglinestousethedeclarationsthatare

--providedforinstantiatingXilinxprimitivecomponents.

--libraryUNISIM;

--useUNISIM.VComponents.all;

entityled7sis

Port(din:

instd_logic_vector(3downto0);

dout:

outstd_logic_vector(6downto0));

endled7s;

architectureBehavioralofled7sis

begin

process(din)

begin

casedinis

when"0000"=>dout<=not"0111111";--0

when"0001"=>dout<=not"0000110";--1

when"0010"=>dout<=not"1011011";--2

when"0011"=>dout<=not"1001111";--3

when"0100"=>dout<=not"1100110";--4

when"0101"=>dout<=not"1101101";--5

when"0110"=>dout<=not"1111101";--6

when"0111"=>dout<=not"0000111";--7

when"1000"=>dout<=not"111111";--8

when"1001"=>dout<=not"1101111";--9

whenothers=>dout<="0000000";

endcase;

endprocess;

endBehavioral;

⑤顶层设计文件(clock_top.vhd,设计的电子时钟可以显示时,分,秒,还可以进行时间的设置和调节。

顶层文件VHDL源程序如下:

useIEEE.STD_LOGIC_1164.ALL;

useIEEE.STD_LOGIC_ARITH.ALL;

useIEEE.STD_LOGIC_UNSIGNED.ALL;

--Uncommentthefollowinglinestousethedeclarationsthatare

--providedforinstantiatingXilinxprimitivecomponents.

--libraryUNISIM;

--useUNISIM.VComponents.all;

entityclock_topis

Port(clk:

instd_logic;--1Hz

reset:

instd_logic;--复位信号

dins:

instd_logic_vector(6downto0);--秒钟预置

dinm:

instd_logic_vector(6downto0);--分钟预置

dinh:

instd_logic_vector(5downto0);--时钟预置

secondl:

outstd_logic_vector(6downto0);--秒钟低位输出

secondh:

outstd_logic_vector(6downto0);--秒钟高位输出

minutel:

outstd_logic_vector(6downto0);--分钟低位输出

minuteh:

outstd_logic_vector(6downto0);--分钟高位输出

hourl:

outstd_logic_vector(6downto0);---小时低位输出

hourh:

outstd_logic_vector(6downto0));--小时高位输出

endclock_top;

architectureBehavioralofclock_topis

componentcount10is

Port(clk:

instd_logic;

reset:

instd_logic;

din:

instd_logic_vector(3downto0);

dout:

outstd_logic_vector(3downto0);

c:

outstd_logic);

endcomponent;

componentcount6is

Port(clk:

instd_logic;

reset:

instd_logic;

din:

instd_logic_vector(2downto0);

dout:

outstd_logic_vector(2downto0);

c:

outstd_logic);

endcomponent;

componentcount24is

Port(clk:

instd_logic;

reset:

instd_logic;

din:

instd_logic_vector(5downto0);

dout:

outstd_logic_vector(5downto0));

endcomponent;

componentled7sis

Port(din:

instd_logic_vector(3downto0);

dout:

outstd_logic_vector(6downto0));

endcomponent;

SIGNALN:

STD_LOGIC_VECTOR(24DOWNTO0);

SIGNALM:

STD_LOGIC;

signalc1,c2,c3,c4:

std_logic;

signaldoutsl,doutml:

std_logic_vector(3downto0);

signaldoutsh,doutmh:

std_logic_vector(2downto0);

signaldouth:

std_logic_vector(5downto0);

signalrdoutsh,rdoutmh:

std_logic_vector(3downto0);

signalrdouth:

std_logic_vector(7downto0);

begin

PROCESS(CLK,RESET)

BEGIN

IFRESET='0'THENN<=(OTHERS=>'0');

ELSIF(CLK'EVENTANDCLK='1')THEN

N<=N+1;

ENDIF;

ENDPROCESS;

M<=N(24);

rdoutsh<='0'&doutsh;--将秒钟高位数据变为4位,再进行译码

rdoutmh<='0'&doutmh;--将分钟高位数据变为4位,再进行译码

rdouth<="00"&douth;--将时钟高位数据变为4位,再进行译码

u1:

count10portmap(clk=>M,reset=>reset,

din=>dins(3downto0),

dout=>doutsl,

c=>c1);

u2:

count6portmap(clk=>c1,reset=>reset,

din=>dins(6downto4),

dout=>doutsh,

c=>c2);

u3:

count10portmap(clk=>c2,reset=>reset,

din=>dinm(3downto0),

dout=>doutml,

c=>c3);

u4:

count6portmap(clk=>c3,reset=>reset,

din=>dinm(6downto4),

dout=>doutmh,

c=>c4);

u5:

count24portmap(clk=>c4,reset=>reset,

din=>dinh,dout=>douth);

u6:

led7sportmap(din=>doutsl,dout=>secondl);--秒的低位

u7:

led7sportmap(din=>rdoutsh,dout=>secondh);--秒的高位

u8:

led7sportmap(din=>doutml,dout=>minutel);--分的低位

u9:

led7sportmap(din=>rdoutmh,dout=>minuteh);--分的高位

u10:

led7sportmap(din=>rdouth(3downto0),dout=>hourh);--时的低位

u11:

led7sportmap(din=>rdouth(7downto4),dout=>hourl);--时的高位

endBehavioral;

(2)仿真

①二十四进制计数器仿真结果如图5.2.2所示。

由图知当reset为低电平时清零,为高电平时开始计数,并且计到24。

图中dout的输出选择的是无符号整数显示方式,

图5.2..2二十四进制计数器仿真结果

②顶层仿真结果如图5.2.3所示,图5.2.3(a)仿真结果可以看到秒的个位和秒的十位之间的进位,图5.2.3(b)的仿真结果可以清楚看到秒的十位向分的个位之间的进位。

(a)电子时钟秒的个位和秒的十位之间的进位

 

(b)电子时钟秒的十位向分的个位之间的进位

(c)电子时钟仿真局部放大图

图5.2.3电子时钟仿真结果

(6)下载

引脚设置和下载请参照第2章的2.2节方法。

6实验报告

(1)用VHDL语言编写电子时钟的源程序。

(2)分别将电子时钟中的十进制计数器、六进制计数器及二十四进制计数器进行仿真并分析仿真结果。

(3)对电子时钟系统的功能进行仿真并分析仿真结果。

(4)写出实验体会。

7.实验练习题

修改本次实验中的程序,使设计的电子时钟为12小时制。

展开阅读全文
相关资源
猜你喜欢
相关搜索
资源标签

当前位置:首页 > PPT模板 > 商务科技

copyright@ 2008-2023 冰点文库 网站版权所有

经营许可证编号:鄂ICP备19020893号-2