zoukankan      html  css  js  c++  java
  • 基于BASYS2的VHDL程序——数字钟(改进版)

    扩展到时分秒。加了入调时电路,但不知道为什么有两个按键不好使。而且不知道以何种方式假如按键消抖电路,因为加入后会多个时钟控制一个信号,物理不可实现。调试电路待解决。还有,四个数目管中间的那两个圆点怎么点亮啊,没有地址啊,求破。待我清明之后解决这个问题。

    下面是代码。

      1 library IEEE;
      2 use IEEE.STD_LOGIC_1164.ALL;
      3 use IEEE.STD_LOGIC_ARITH.ALL;
      4 use IEEE.STD_LOGIC_UNSIGNED.ALL;
      5 
      6 entity clock is
      7     Port ( clk : in  STD_LOGIC;
      8               sw0:  in STD_LOGIC;
      9               btn : in  STD_LOGIC_VECTOR (3 downto 0);
     10               led0:  out STD_LOGIC;
     11            seg : out  STD_LOGIC_VECTOR (6 downto 0);
     12               seg7:out STD_LOGIC;
     13            an : out  STD_LOGIC_VECTOR (3 downto 0));
     14 end clock;
     15 
     16 architecture Behavioral of clock is
     17 signal num:STD_LOGIC_VECTOR (3 downto 0);
     18 signal hour_h:STD_LOGIC_VECTOR (3 downto 0);
     19 signal hour_l:STD_LOGIC_VECTOR (3 downto 0);
     20 signal min_h:STD_LOGIC_VECTOR (3 downto 0);
     21 signal min_l:STD_LOGIC_VECTOR (3 downto 0);
     22 signal second_h:STD_LOGIC_VECTOR (3 downto 0);
     23 signal second_l:STD_LOGIC_VECTOR (3 downto 0);
     24 signal an_sel:STD_LOGIC_VECTOR (1 downto 0);
     25 signal cnt:   INTEGER;
     26 signal cnt2:  INTEGER;
     27 signal sclk: STD_LOGIC;
     28 signal aclk: STD_LOGIC;
     29 signal shine:STD_LOGIC;
     30 begin
     31 led0<=shine;
     32 process(clk)
     33 begin
     34 if(clk'event and clk='1') then
     35     if(cnt=25000000) then
     36         cnt<=0;
     37         sclk<=not sclk;
     38     else
     39         cnt<=cnt+1;
     40     end if;
     41 end if;
     42 end process;
     43 
     44 process(clk)
     45 begin
     46 if(clk'event and clk='1') then
     47     if(cnt2=50000) then
     48         cnt2<=0;
     49         if(an_sel="11") then
     50             an_sel<="00";
     51         else
     52             an_sel<=an_sel+'1';
     53         end if;
     54     else
     55         cnt2<=cnt2+1;
     56     end if;
     57 end if;
     58 end process;
     59 
     60 process(sclk,sw0,btn)
     61 begin
     62 if(sw0='1')    then
     63     if(btn(0)='1') then
     64             second_l<=second_l+'1';
     65     end if;
     66     if(btn(1)='1') then
     67             second_h<=second_h+'1';
     68     end if;
     69     if(btn(2)='1') then
     70             hour_l<=hour_l+'1';
     71     end if;
     72     if(btn(3)='1') then
     73             hour_h<=hour_h+'1';
     74     end if;
     75 else
     76     if(sclk'event and sclk='1') then
     77         shine<=second_l(0);
     78         if(second_h="0101" and second_l="1001") then
     79             second_h<="0000";
     80             second_l<="0000";
     81             min_l<=min_l+'1';
     82             if(min_h="0101" and min_l="1001") then
     83                 min_h<="0000";
     84                 min_l<="0000";
     85                 hour_l<=hour_l+'1';
     86                 if(hour_h="0010" and min_l="0011") then
     87                     hour_h<="0000";
     88                     hour_l<="0000";
     89                 elsif(hour_l="1001")then
     90                     hour_h<=hour_h+'1';
     91                     hour_l<="0000";
     92                 end if;
     93             elsif(min_l="1001") then
     94                 min_h<=min_h+'1';
     95                 min_l<="0000";
     96             end if;
     97         elsif(second_l="1001") then
     98             second_h<=second_h+'1';
     99             second_l<="0000";
    100         else
    101             second_l<=second_l+'1';
    102         end if;
    103     end if;
    104 end if;
    105 end process;
    106 
    107 process(an_sel,second_l,second_h,min_l,min_h,hour_l,hour_h)
    108 begin
    109 case an_sel is
    110 when "00"=>an<="0111";num<=min_l;seg7<='1';
    111 when "01"=>an<="1011";num<=min_h;seg7<='1';
    112 when "10"=>an<="1101";num<=hour_l;seg7<='0';
    113 when "11"=>an<="1110";num<=hour_h;seg7<='1';
    114 when others=>null;
    115 end case;
    116 case num  is
    117         when x"0"=>seg<=b"0000001";
    118         when x"1"=>seg<=b"1001111";
    119         when x"2"=>seg<=b"0010010";
    120         when x"3"=>seg<=b"0000110";
    121         when x"4"=>seg<=b"1001100";
    122         when x"5"=>seg<=b"0100100";
    123         when x"6"=>seg<=b"0100000";
    124         when x"7"=>seg<=b"0001111";
    125         when x"8"=>seg<=b"0000000";
    126         when x"9"=>seg<=b"0000100";
    127         when others=>null;
    128 end case;
    129 end process;
    130 end Behavioral;

    约束文件

     1 NET "clk" LOC = "B8";
     2 NET "led0" LOC ="M5";
     3 NET "an<0>" LOC="K14";
     4 NET "an<1>" LOC="M13";
     5 NET "an<2>" LOC="J12";
     6 NET "an<3>" LOC="F12";
     7 NET "seg7" LOC="N13";
     8 NET "seg<6>" LOC="L14";
     9 NET "seg<5>" LOC="H12";
    10 NET "seg<4>" LOC="N14";
    11 NET "seg<3>" LOC="N11";
    12 NET "seg<2>" LOC="P12";
    13 NET "seg<1>" LOC="L13";
    14 NET "seg<0>" LOC="M12";  
    15 NET "btn<0>" LOC = "G12";
    16 NET "btn<1>" LOC = "C11";
    17 NET "btn<2>" LOC = "M4";
    18 NET "btn<3>" LOC = "A7";
    19 NET "sw0"    LOC="P11";
  • 相关阅读:
    Swift相比OC语言有哪些优点
    Swift实战技巧
    Swift 并行编程现状和展望
    Swift设置只读(readOnly)属性
    Swift零基础教程2019最新版(一)搭建开发环境
    中文版 Apple 官方 Swift 教程《The Swift Programming Language》
    一个中文的苹果开发站
    simulink创建简单模型
    Simulink 产品说明
    matlab中的实时音频
  • 原文地址:https://www.cnblogs.com/connorzx/p/3637077.html
Copyright © 2011-2022 走看看