收藏 分销(赏)

基于vhdl时钟的设计与制作(附完整代码).doc

上传人:w****g 文档编号:3930918 上传时间:2024-07-23 格式:DOC 页数:7 大小:37.04KB 下载积分:6 金币
下载 相关
基于vhdl时钟的设计与制作(附完整代码).doc_第1页
第1页 / 共7页
基于vhdl时钟的设计与制作(附完整代码).doc_第2页
第2页 / 共7页


点击查看更多>>
资源描述
机电工程系 《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:所要显示的数值 三、实验程序及部分仿真波形图 library ieee; use ieee.std_logic_1164。all; use ieee.std_logic_unsigned.all; entity colock is port(clk1,clk2,key1,key2: in std_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; signals1,s2,m1,m2,h1,h2,s01,s02,m01,m02,h01,h02,s001,s002,m001,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 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; when others => clk02〈=clk2;cs02〈=cs2;cm02<=cm2; end case ; end process; —-500进制计数器,每500ms对CP进行取反一次,用于闪烁控制 process(clk1) begin if rising_edge(clk1) then if ctrl0<499 then ctrl0〈=ctrl0+1; else ctrl0〈=”000000000”;cp〈=not cp; end if ; end if; end process; ——数码管动态扫描,接138的输入端 process(clk1) begin if rising_edge(clk1) then if ctrl<9 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 s01〈”1001" then s01〈=s01+1;cs1<=’0'; else s01<=”0000”;cs1〈='1’; end if; end if; end process; ——秒十位的计数 process(cs1) begin if rising_edge(cs1) then if s02〈"0101" 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 m01〈"1001” then m01〈=m01+1;cm1〈=’0'; else m01<="0000”;cm1〈='1’; end if; end if; end process; —-分十位的计数 process(cm1) begin if rising_edge(cm1) then if m02<”0101" 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 h02〈"0010” then if h01〈”1001” then h01<=h01+1;ch1〈=’0’; else h01<="0000”;ch1<=’1’; end if ; else if h01<"0011”then h01<=h01+1;ch1<='0'; else h01<=”0000”;ch1〈=’1’; end if; end if; end if; end process; ——小时十位的计数 process(ch1) begin if rising_edge(ch1) then if h02<"0010” 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'; end 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〈=’0’; end if ; end if; end process; ——闪烁程序,当CP=0时送显示数据,当CP=1时送灭灯指令 process(cp,s01,s02,m01,m02,h01,h02) begin case cp is 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”; when others => s001<=”1011";s002<="1011”;s001〈=”1011”;s002<=”1011";m001〈=”1011”;m002〈="1011”;h001〈=”1011”;h002<="1011"; end case; end process; ——当没有进行调整则送正常显示数据,当进行调整时对相应位送闪烁数据进行显示 process(k1,s01,s02,m01,m02,h01,h02,s001,s002,m001,m002,h001,h002) begin case k1 is 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; when others =〉 s1<=s01;s2〈=s02;m1〈=m01;m2<=m02;h1<=h01;h2<=h02; end case ; end process; --横杠闪烁 process(cp) begin case cp is when ’0’=> p1 〈="1010”;p2 〈="1010”; when ’1’=〉 p1 〈="1011”;p2 〈="1011”; when others=〉 p1 〈=”1100”;p2 〈=”1100"; end case; end process; —-动态扫描时每个数码管送相应的显示数据 process(ctrl,s1,s2,p1,m1,p2,m2,h1,h2) begin case ctrl is 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; when others =〉disp〈=”1100”; end case; end process;] —-显示数据对应的段码 process(disp) begin case disp is 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”; when others =〉led7s〈="0000000"; end case ; end process; end architecture one; 1. 第五章 心得体会 7 通过此次课程设计使我更加深刻的认识EDA电子电路设计的各个模块。时钟程序的编写按键调整时间同时让处于调整的位闪烁体会到各个进程之间通过控制信号建立起来的紧密联系,以及通过移位来达到按键的去抖动。进行硬件调试时了解到芯片跟外围设备之间的连接程序功能由简单到复杂,通过课堂提问一步步完善时钟的各个模块,将本学期所学到的内容串到一起,最终完成课程设计
展开阅读全文

开通  VIP会员、SVIP会员  优惠大
下载10份以上建议开通VIP会员
下载20份以上建议开通SVIP会员


开通VIP      成为共赢上传

当前位置:首页 > 学术论文 > 其他

移动网页_全站_页脚广告1

关于我们      便捷服务       自信AI       AI导航        抽奖活动

©2010-2026 宁波自信网络信息技术有限公司  版权所有

客服电话:0574-28810668  投诉电话:18658249818

gongan.png浙公网安备33021202000488号   

icp.png浙ICP备2021020529号-1  |  浙B2-20240490  

关注我们 :微信公众号    抖音    微博    LOFTER 

客服