基于vhdl时钟的设计与制作附完整代码.docx
- 文档编号:29993784
- 上传时间:2023-08-04
- 格式:DOCX
- 页数:10
- 大小:82.38KB
基于vhdl时钟的设计与制作附完整代码.docx
《基于vhdl时钟的设计与制作附完整代码.docx》由会员分享,可在线阅读,更多相关《基于vhdl时钟的设计与制作附完整代码.docx(10页珍藏版)》请在冰豆网上搜索。
基于vhdl时钟的设计与制作附完整代码
机电工程系
《EDA》
实验报告
实验题目:
时钟的设计与制作
班级:
08通信
姓名:
学号:
一、实验要求
1、实现功能:
(1)运用动态扫描对8个数码管进行显示操作;
(2)通过两个按键对时钟的时间进行调整,处于被调整状态下的位能闪烁。
2、硬件知识要求:
(1)掌握数码管的动态扫描;
(2)熟悉各个管脚所接的硬件;
(3)掌握按键去抖动原理;
(4)熟悉程序到实验箱的下载;
3、软件知识要求:
(1)掌握各种编程语句的使用方法;
(2)掌握判断语句的嵌套;
二、各个信号所对应功能
CLK1:
1KHZ--作为动态显示扫描时钟及500ms计数时钟
CLK2:
1HZ--作为时钟控制信号
CS1:
自动秒个位进十位控制;CS2:
自动秒进分控制位;Cm1:
自动分个位进十位控制
Cm2:
自动分进时控制位;Ch1:
自动时个位进十位控制位
Key1,key2:
按键1,按键2
Ck1,按键1去抖动后控制位
K1:
00正常显示,01调秒同时秒位闪烁,10调分同时分位闪烁,
11调时同时时位闪烁
Ck2:
按键二按下产生一个上升沿脉冲从而作为手动调整时钟的脉冲
Cp:
闪烁控制位,500ms取反一次
Clk02:
选用按键脉冲或自动自动脉冲的进位寄存器控制秒个位
Cs02:
选用按键脉冲或自动自动脉冲的进位寄存器控制分个位
Cm02:
选用按键脉冲或自动自动脉冲的进位寄存器控制时个位
s1,s2,m1,m2,h1,h2:
送显示的寄存器
s01,s02,m01,m02,h01,h02:
时钟秒、分、时寄存器
s001,s002,m001,m002,h001,h002:
闪烁用时钟秒、分、时寄存器(闪烁频率为2hz)。
当处于调整状态的时送到相应的显示寄存器。
abc:
74ls138控制信号,由clk1控制。
Led7s:
显示
Disp:
所要显示的数值
三、实验程序及部分仿真波形图
libraryieee;
useieee.std_logic_1164.all;
useieee.std_logic_unsigned.all;
entitycolockis
port(clk1,clk2,key1,key2:
instd_logic;
abc:
outstd_logic_vector(2downto0);
led7s:
outstd_logic_vector(6downto0));
endentity;
architectureoneofcolockis
signalctrl:
std_logic_vector(3downto0);
signalclk02,cs02,cm02,cs1,cs2,cm1,cm2,ch1,cp,k2,ck1,ck2:
std_logic;
signals1,s2,m1,m2,h1,h2,s01,s02,m01,m02,h01,h02,s001,s002,m001,m002,h001,
h002,p1,p2,disp:
std_logic_vector(3downto0);
signalctrl0:
std_logic_vector(8downto0);
signaltmp1,tmp2:
std_logic_vector(9downto0);
signalk1:
std_logic_vector(1downto0);
begin
--当处于按键调时状态时,根据K1的值来确定所调整的位,被调整的位送按键2产生的脉冲(CK2),其余进位脉冲赋0屏蔽掉
process(k1,clk2,clk02,cs2,cm2,ck2)
begin
casek1is
when"00"=>clk02<=clk2;cs02<=cs2;cm02<=cm2;
when"01"=>clk02<=ck2;cs02<='0';cm02<='0';
when"10"=>clk02<='0';cs02<=ck2;cm02<='0';
when"11"=>clk02<='0';cs02<='0';cm02<=ck2;
whenothers=>clk02<=clk2;cs02<=cs2;cm02<=cm2;
endcase;
endprocess;
--500进制计数器,每500ms对CP进行取反一次,用于闪烁控制
process(clk1)
begin
ifrising_edge(clk1)then
ifctrl0<499thenctrl0<=ctrl0+1;
elsectrl0<="000000000";cp<=notcp;
endif;
endif;
endprocess;
--数码管动态扫描,接138的输入端
process(clk1)
begin
ifrising_edge(clk1)then
ifctrl<9thenctrl<=ctrl+1;
elsectrl<="0000";
endif;
endif;
endprocess;
abc<=ctrl(2downto0);
--秒个位的计数
process(clk02)
begin
ifrising_edge(clk02)then
ifs01<"1001"thens01<=s01+1;cs1<='0';
elses01<="0000";cs1<='1';
endif;
endif;
endprocess;
--秒十位的计数
process(cs1)
begin
ifrising_edge(cs1)then
ifs02<"0101"thens02<=s02+1;cs2<='0';
elses02<="0000";cs2<='1';
endif;
endif;
endprocess;
--分个位的计数
process(cs02)
begin
ifrising_edge(cs02)then
ifm01<"1001"thenm01<=m01+1;cm1<='0';
elsem01<="0000";cm1<='1';
endif;
endif;
endprocess;
--分十位的计数
process(cm1)
begin
ifrising_edge(cm1)then
ifm02<"0101"thenm02<=m02+1;cm2<='0';
elsem02<="0000";cm2<='1';
endif;
endif;
endprocess;
--小时个位的计数
process(cm02)
begin
ifrising_edge(cm02)then
ifh02<"0010"then
ifh01<"1001"thenh01<=h01+1;ch1<='0';
elseh01<="0000";ch1<='1';
endif;
else
ifh01<"0011"thenh01<=h01+1;ch1<='0';
elseh01<="0000";ch1<='1';
endif;
endif;
endif;
endprocess;
--小时十位的计数
process(ch1)
begin
ifrising_edge(ch1)then
ifh02<"0010"thenh02<=h2+1;
elseh02<="0000";
endif;
endif;
endprocess;
--按键一去抖动
process(clk1)
begin
ifrising_edge(clk1)then
tmp1(0)<=key1;tmp1(9downto1)<=tmp1(8downto0);
iftmp1="1111111111"thenck1<='1';elseck1<='0';
endif;
endif;
endprocess;
--按键一实现功能
process(ck1)
begin
ifrising_edge(ck1)thenk1<=k1+1;
endif;
endprocess;
--按键二去抖动,并产生一个时钟上升沿脉冲
process(clk1)
begin
ifrising_edge(clk1)then
tmp2(0)<=key2;tmp2(9downto1)<=tmp2(8downto0);
iftmp2="1111111111"thenck2<='1';elseck2<='0';
endif;
endif;
endprocess;
--闪烁程序,当CP=0时送显示数据,当CP=1时送灭灯指令
process(cp,s01,s02,m01,m02,h01,h02)
begin
casecpis
when'0'=>s001<=s01;s002<=s02;m001<=m01;m002<=m02;h001<=h01;h002<=h02;
when'1'=>s001<="1011";s002<="1011";m001<="1011";m002<="1011";h001<="1011";h002<="1011";
whenothers=>s001<="1011";s002<="1011";s001<="1011";s002<="1011";m001<="1011";m002<="1011";h001<="1011";h002<="1011";
endcase;
endprocess;
--当没有进行调整则送正常显示数据,当进行调整时对相应位送闪烁数据进行显示
process(k1,s01,s02,m01,m02,h01,h02,s001,s002,m001,m002,h001,h002)
begin
casek1is
when"00"=>s1<=s01;s2<=s02;m1<=m01;m2<=m02;h1<=h01;h2<=h02;
when"01"=>s1<=s001;s2<=s002;m1<=m01;m2<=m02;h1<=h01;h2<=h02;
when"10"=>s1<=s01;s2<=s02;m1<=m001;m2<=m002;h1<=h01;h2<=h02;
when"11"=>s1<=s01;s2<=s02;m1<=m01;m2<=m02;h1<=h001;h2<=h002;
whenothers=>s1<=s01;s2<=s02;m1<=m01;m2<=m02;h1<=h01;h2<=h02;
endcase;
endprocess;
--横杠闪烁
process(cp)
begin
casecpis
when'0'=>p1<="1010";p2<="1010";
when'1'=>p1<="1011";p2<="1011";
whenothers=>p1<="1100";p2<="1100";
endcase;
endprocess;
--动态扫描时每个数码管送相应的显示数据
process(ctrl,s1,s2,p1,m1,p2,m2,h1,h2)
begin
casectrlis
when"0000"=>disp<=s1;
when"0001"=>disp<=s2;
when"0010"=>disp<=p1;
when"0011"=>disp<=m1;
when"0100"=>disp<=m2;
when"0101"=>disp<=p2;
when"0110"=>disp<=h1;
when"0111"=>disp<=h2;
whenothers=>disp<="1100";
endcase;
endprocess;]
--显示数据对应的段码
process(disp)
begin
casedispis
when"0000"=>led7s<="0111111";
when"0001"=>led7s<="0000110";
when"0010"=>led7s<="1011011";
when"0011"=>led7s<="1001111";
when"0100"=>led7s<="1100110";
when"0101"=>led7s<="1101101";
when"0110"=>led7s<="1111101";
when"0111"=>led7s<="0000111";
when"1000"=>led7s<="1111111";
when"1001"=>led7s<="1101111";
when"1010"=>led7s<="1000000";
when"1011"=>led7s<="0000000";
whenothers=>led7s<="0000000";
endcase;
endprocess;
endarchitectureone;
1.第五章心得体会
通过此次课程设计使我更加深刻的认识EDA电子电路设计的各个模块。
时钟程序的编写按键调整时间同时让处于调整的位闪烁体会到各个进程之间通过控制信号建立起来的紧密联系,以及通过移位来达到按键的去抖动。
进行硬件调试时了解到芯片跟外围设备之间的连接程序功能由简单到复杂,通过课堂提问一步步完善时钟的各个模块,将本学期所学到的内容串到一起,最终完成课程设计
- 配套讲稿:
如PPT文件的首页显示word图标,表示该PPT已包含配套word讲稿。双击word图标可打开word文档。
- 特殊限制:
部分文档作品中含有的国旗、国徽等图片,仅作为作品整体效果示例展示,禁止商用。设计者仅对作品中独创性部分享有著作权。
- 关 键 词:
- 基于 vhdl 时钟 设计 制作 完整 代码