1、基于vhdl时钟的设计与制作附完整代码 机电工程系EDA实 验 报 告实验题目: 时钟的设计与制作 班 级: 08通信 姓 名: 学 号: 一、实验要求1、实现功能: (1)运用动态扫描对8个数码管进行显示操作; (2)通过两个按键对时钟的时间进行调整,处于被调整状态下的位能闪烁。2、硬件知识要求:(1)掌握数码管的动态扫描;(2)熟悉各个管脚所接的硬件;(3)掌握按键去抖动原理;(4)熟悉程序到实验箱的下载;3、软件知识要求:(1)掌握各种编程语句的使用方法;(2)掌握判断语句的嵌套;二、各个信号所对应功能CLK1:1KHZ -作为动态显示扫描时钟及500ms计数时钟CLK2:1HZ -作为
2、时钟控制信号CS1:自动秒个位进十位控制;CS2:自动秒进分控制位;Cm1:自动分个位进十位控制Cm2:自动分进时控制位 ; Ch1:自动时个位进十位控制位Key1,key2:按键1,按键2Ck1,按键1去抖动后控制位K1:00正常显示,01调秒同时秒位闪烁,10调分同时分位闪烁,11调时同时时位闪烁Ck2:按键二按下产生一个上升沿脉冲从而作为手动调整时钟的脉冲Cp:闪烁控制位,500ms取反一次Clk02:选用按键脉冲或自动自动脉冲的进位寄存器控制秒个位Cs02:选用按键脉冲或自动自动脉冲的进位寄存器控制分个位Cm02:选用按键脉冲或自动自动脉冲的进位寄存器控制时个位s1,s2,m1,m2,
3、h1,h2:送显示的寄存器s01,s02,m01,m02,h01,h02:时钟秒、分、时寄存器s001,s002,m001,m002,h001,h002:闪烁用时钟秒、分、时寄存器(闪烁频率为2hz)。当处于调整状态的时送到相应的显示寄存器。abc:74ls138控制信号,由clk1控制。Led7s:显示Disp:所要显示的数值三、实验程序及部分仿真波形图library ieee;use ieee.std_logic_1164.all;use ieee.std_logic_unsigned.all;entity colock isport(clk1,clk2,key1,key2: in std
4、_logic; abc:out std_logic_vector(2 downto 0); led7s:out std_logic_vector(6 downto 0) );end entity;architecture one of colock is signal ctrl:std_logic_vector(3 downto 0); signal clk02,cs02,cm02,cs1,cs2,cm1,cm2,ch1,cp,k2,ck1,ck2:std_logic;signal s1,s2,m1,m2,h1,h2,s01,s02,m01,m02,h01,h02,s001,s002,m001
5、,m002,h001,h002,p1,p2,disp:std_logic_vector(3 downto 0); signal ctrl0:std_logic_vector(8 downto 0); signal tmp1,tmp2:std_logic_vector(9 downto 0); signal k1:std_logic_vector(1 downto 0);begin-当处于按键调时状态时,根据K1的值来确定所调整的位,被调整的位送按键2产生的脉冲(CK2),其余进位脉冲赋0屏蔽掉process(k1,clk2,clk02,cs2,cm2,ck2)begin case k1 is
6、when 00 = clk02=clk2;cs02=cs2;cm02 clk02=ck2;cs02=0;cm02 clk02=0;cs02=ck2;cm02 clk02=0;cs02=0;cm02 clk02=clk2;cs02=cs2;cm02=cm2; end case ;end process;-500进制计数器,每500ms对CP进行取反一次,用于闪烁控制process(clk1) begin if rising_edge(clk1) then if ctrl0499 then ctrl0=ctrl0+1; else ctrl0=000000000;cp=not cp; end if
7、; end if;end process;-数码管动态扫描,接138的输入端process(clk1)begin if rising_edge(clk1) then if ctrl9 then ctrl=ctrl+1; else ctrl=0000; end if ; end if ;end process;abc=ctrl(2 downto 0);-秒个位的计数process(clk02) begin if rising_edge(clk02) then if s011001 then s01=s01+1;cs1=0; else s01=0000;cs1=1; end if; end if;
8、end process;-秒十位的计数process(cs1) begin if rising_edge(cs1) then if s020101 then s02=s02+1;cs2=0; else s02=0000;cs2=1; end if; end if;end process;-分个位的计数process(cs02) begin if rising_edge(cs02) then if m011001 then m01=m01+1;cm1=0; else m01=0000;cm1=1; end if; end if;end process;-分十位的计数process(cm1) be
9、gin if rising_edge(cm1) then if m020101 then m02=m02+1;cm2=0; else m02=0000;cm2=1; end if; end if;end process;-小时个位的计数process(cm02) begin if rising_edge(cm02) then if h020010 then if h011001 then h01=h01+1;ch1=0; else h01=0000;ch1=1; end if ; else if h010011then h01=h01+1;ch1=0; else h01=0000;ch1=1;
10、 end if; end if; end if;end process;-小时十位的计数process(ch1)begin if rising_edge(ch1) then if h020010 then h02=h2+1; else h02=0000; end if; end if;end process;-按键一去抖动process(clk1) begin if rising_edge(clk1) then tmp1(0)=key1;tmp1(9 downto 1)=tmp1(8 downto 0); if tmp1=1111111111 then ck1=1;else ck1=0; en
11、d if ; end if;end process;-按键一实现功能process(ck1) begin if rising_edge(ck1) then k1=k1+1; end if ;end process;-按键二去抖动,并产生一个时钟上升沿脉冲process(clk1) begin if rising_edge(clk1) then tmp2(0)=key2;tmp2(9 downto 1)=tmp2(8 downto 0); if tmp2=1111111111 then ck2=1;else ck2 s001=s01;s002=s02;m001=m01;m002=m02;h001
12、=h01;h002 s001=1011;s002=1011;m001=1011;m002=1011;h001=1011;h002 s001=1011;s002=1011;s001=1011;s002=1011;m001=1011;m002=1011;h001=1011;h002 s1=s01;s2=s02;m1=m01;m2=m02;h1=h01;h2 s1=s001;s2=s002;m1=m01;m2=m02;h1=h01;h2 s1=s01;s2=s02;m1=m001;m2=m002;h1=h01;h2 s1=s01;s2=s02;m1=m01;m2=m02;h1=h001;h2 s1=
13、s01;s2=s02;m1=m01;m2=m02;h1=h01;h2 p1 =1010;p2 p1 =1011;p2 p1 =1100;p2 dispdispdispdispdispdispdispdispdispled7sled7sled7sled7sled7sled7sled7sled7sled7sled7sled7sled7sled7s=0000000; end case ; end process;end architecture one;1.第五章 心得体会 通过此次课程设计使我更加深刻的认识EDA电子电路设计的各个模块。时钟程序的编写按键调整时间同时让处于调整的位闪烁体会到各个进程之间通过控制信号建立起来的紧密联系,以及通过移位来达到按键的去抖动。进行硬件调试时了解到芯片跟外围设备之间的连接程序功能由简单到复杂,通过课堂提问一步步完善时钟的各个模块,将本学期所学到的内容串到一起,最终完成课程设计