找回密码
 立即注册

QQ登录

只需一步,快速开始

搜索
查看: 4456|回复: 3
收起左侧

基于VHDL语言的电子时钟设计-ISE开发的EDA源码 晶振25Mhz

[复制链接]
ID:191542 发表于 2019-1-9 21:42 | 显示全部楼层 |阅读模式
本人的课程设计,和大家分享分享,多谢大家的指导和建议!
所有功能全部实现  使用的是赛灵斯的开发板 晶振是25Mhz  开发软件是ISE
包含路径不允许有中文....
后附完整的工程和实习报告  有需要的可以拿走
程序设计要求
(1)根据系统的功能和技术指标,寻找出合适的算法,并用 VHDL 语言对算法进行描述;
(2)在设计输入后,在 EDA 软件上对系统进行仿真和调试;
(3)在调试完毕后,将所设计的算法下载到目标板上查看结果;
(4)运用 VHDL 语言描述电子时钟的时、分、秒;
(5)将时、分、秒连接成电子时钟,秒/分/时的依次显示并正确计数;
(6)秒/分/时各段个位满 10 正确进位,秒/分能做到满 60 向前进位;
(7)可以控制电子时钟的启停;
(8)通过键盘控制电子时钟可以 12 时或 24 时计时;
(9)当认为时钟不准确时,通过键盘可以分别对分/时钟进行调整;
(10)电子时钟具有时钟和秒表功能,秒表和时钟功能可以相互切换;
(11)电子时钟具有定时功能,当定时与时钟时间相同时,蜂鸣器发生。
0.png

目录

一、              工程框架及顶层原理图
二、各模块原理图及程序
1、分频器
1.1、分频器原理图
1.2、分频器程序
2、12/24进制时钟
2.1、时钟顶层、底层原理图
2.2时钟顶层文件
2.3、时钟底层文件
2.3.1、四选一芯片
2.3.2、秒——60进制芯片
2.3.3、分——60进制芯片
2.3.4、时——12/24进制芯片
3、秒表
3.1、秒表顶层、底层原理图
3.2秒表顶层文件
3.3秒表底层文件
3.3.1、十进制计时器(4个计数器级联)
4、定时闹钟
4.1、闹钟顶层原理图
4.2、闹钟顶层程序
4.3、闹钟底层文件
4.3.1、调整位选择
4.3.2、时间设定
4.3.3、闹铃
5、按键消抖
5.1、按键消抖原理图
5.2、按键消抖底层程序
6、按键处理部分
6.1按键处理原理图
6.2按键处理底层程序
7、选中数码管闪烁
7.1、原理图
7.2、底层程序
8、数码管显示控制
8.1、原理图
8.2底层程序
9、数码管译码器
9.1、原理图
9.2、底层程序
10、FPGA芯片引脚锁定UCF文件
三、仿真波形
1、秒——60进制计数
2、时钟暂停及运行

一、        工程框架及顶层原理图


二、各模块原理图及程序1、分频器
1.1、分频器原理图

1.2、分频器程序


library ieee;
use ieee.std_logic_1164.all;
use ieee.std_logic_unsigned.all;
entity fenpin is
              port(
                            clk:in std_logic;
                            c0:buffer std_logic;
                            c1:buffer std_logic;
                            c2:buffer std_logic;
                            c3:buffer std_logic;
                            );
end fenpin;
architecture behav of fenpin is
              signal counter0:integer range 0 to 12500000;
              signal counter1:integer range 0 to 125;
              signal counter2:integer range 0 to 6250000;
              signal counter3:integer range 0 to 125000;
              begin

              ctr0:--1hz
              process(clk)
                            begin

                            if(clk='1' and clk'event)then
                                          if(counter0=12500000)then
                                                        counter0<=0;c0<=not c0;
                                          else
                                                        counter0<=counter0+1;
                                          end if;
                            end if;
              end process;

              ctr1:--100khz
              process(clk)
                            begin

                            if(clk='1' and clk'event)then
                                          if(counter1=125)then
                                                        counter1<=1;c1<=not c1;
                                          else
                                                        counter1<=counter1+1;
                                          end if;
                            end if;
              end process;

              ctr2:--2Hz
              process(clk)
                            begin

                            if(clk='1' and clk'event)then
                                          if(counter2=6250000)then
                                                        counter2<=0;c2<=not c2;
                                          else
                                                        counter2<=counter2+1;
                                          end if;
                            end if;
              end process;

              ctr3:--100hz
              process(clk)
                            begin

                            if(clk='1' and clk'event)then
                                          if(counter3=125000)then
                                                        counter3<=0;c3<=not c3;
                                          else
                                                        counter3<=counter3+1;
                                          end if;
                            end if;
              end process;
end behav;




2、12/24进制时钟2.1、时钟顶层、底层原理图


2.2时钟顶层文件
library ieee;
use ieee.std_logic_1164.all;
use ieee.std_logic_unsigned.all;

entity clock is
              port(
                            clk1:in std_logic;
                            clk:in std_logic;
                            flag1:in std_logic_vector(2 downto 0);
                            step_up:in std_logic;
                            d_0,d_1:out std_logic_vector(3 downto 0);
                            d_2,d_3:out std_logic_vector(3 downto 0);
                            d_4,d_5:out std_logic_vector(3 downto 0);
                            hour_12_24:in std_logic;
                            clock_stop:in std_logic
                            );
end clock;

architecture struct of clock is

              component xuanze4_1 is
                            port(
                                          clk:in std_logic;
                                          in2,in3,in4,in5:in std_logic;
                                          step_up:in std_logic;
                                          flag1:in std_logic_vector(2 downto 0);
                                          co2,co3,co4,co5:out std_logic
                                          );
              end component;

              component hour is
                            port (
                                          clk_l:in std_logic;
                                          clk_h:in std_logic;                           
                                          d_4,d_5:out std_logic_vector(3 downto 0);
                                          cout_4,cout_5:out std_logic;
                                          hour_12_24:in std_logic
                                          );
              end component;

              component fen60 is
                            port (
                                          clk_l:in std_logic;
                                          clk_h:in std_logic;            
                                          d_2,d_3:out std_logic_vector(3 downto 0);
                                          cout_2,cout_3:out std_logic
                                          );
              end component;

              component sn60 is
                            port (
                                          clk:in std_logic;
                                          d_0,d_1:out std_logic_vector(3 downto 0);
                                          cout:out std_logic;
                                          clock_stop:in std_logic
                                          );
              end component;

              signal in2,in3,in4,in5,co2,co3,co4,co5,cout_5:std_logic;

              begin

              u20:xuanze4_1 port map (clk1,in2,in3,in4,in5,step_up,flag1,co2,co3,co4,co5);
              u21:sn60 port map(clk,d_0,d_1,in2,clock_stop);
              u22:fen60 port map(co2,co3,d_2,d_3,in3,in4);
              u23:hour port map(co4,co5,d_4,d_5,in5,cout_5,hour_12_24);

end struct;
2.3、时钟底层文件2.3.1、四选一芯片



library ieee;
use ieee.std_logic_1164.all;
use ieee.std_logic_unsigned.all;

entity xuanze4_1 is
              port(
                            clk:in std_logic;
                            in2,in3,in4,in5:in std_logic;
                            step_up:in std_logic;
                            flag1:in std_logic_vector(2 downto 0);
                            co2,co3,co4,co5:out std_logic
                            );
end xuanze4_1;

architecture behav of xuanze4_1 is
begin
              process(clk,in2,in3,in4,in5,step_up,flag1)
              begin
                            case flag1 is
                            when "000" =>              co2<=in2;
                                                                                                  co3<=in3;
                                                                                                  co4<=in4;
                                                                                                  co5<=in5;                                                                                   
                            when "001" =>              co2<=step_up;
                                                                                                  co3<=in3;
                                                                                                  co4<=in4;
                                                                                                  co5<=in5;

                            when "010" =>              co3<=step_up;
                                                                                                  co2<=in2;
                                                                                                  co4<=in4;
                                                                                                  co5<=in5;                                                                                   
                            when "011" =>              co4<=step_up;
                                                                                                  co2<=in2;
                                                                                                  co3<=in3;
                                                                                                  co5<=in5;

                            when "100" =>              co2<=in2;
                                                                                                  co3<=in3;
                                                                                                  co4<=in4;
                                                                                                  co5<=step_up;

                            when others => co2<=in2;
                                                                                                  co3<=in3;
                                                                                                  co4<=in4;
                                                                                                  co5<=in5;
                            end case;
              end process;
end behav;



2.3.2、秒——60进制芯片
library ieee;
use ieee.std_logic_1164.all;
use ieee.std_logic_unsigned.all;
entity sn60 is
port(
              clk:in std_logic;
              d_0,d_1:out std_logic_vector(3 downto 0);
              cout:out std_logic;
              clock_stop:in std_logic
);
end sn60;

architecture behav of sn60 is
signal temp1,temp2:std_logic_vector(3 downto 0):="0000";
signal co:std_logic:='0';
begin

process(clk,clock_stop)
begin
              if(clk'event and clk='1')then
                            if(clock_stop='0')then
                                          if(temp1="1001")then--个位满10进一 并且清零
                                                        temp1<="0000";
                                                        co<='1';
                                          else
                                                        temp1<=temp1+1;
                                                        co<='0';
                                          end if;                                         
                            end if;
              end if;
              d_0<=temp1;
end process;

process(co,clock_stop)
begin
              if(co'event and co='1')then
                            if(clock_stop='0')then
                                          if(temp2="0101")then--十位满6进一
                                                        temp2<="0000";
                                                        cout<='1';
                                          else
                                                        temp2<=temp2+1;
                                                        cout<='0';
                                          end if;
                            end if;
              end if;
              d_1<=temp2;
end process;
end behav;
2.3.3、分——60进制芯片
library ieee;
use ieee.std_logic_1164.all;
use ieee.std_logic_unsigned.all;

entity fen60 is
              port (
                            clk_l:in std_logic;
                            clk_h:in std_logic;            
                            d_2,d_3:out std_logic_vector(3 downto 0);
                            cout_2,cout_3:out std_logic
                            );
end fen60;

architecture behav of fen60 is
signal temp1,temp2:std_logic_vector(3 downto 0);
begin

              process(clk_l)
              begin

                            if(clk_l'event and clk_l='1')then
                                          if(temp1="1001")then
                                                                      temp1<="0000";cout_2<='1';
                                          else
                                                        temp1<=temp1+1;cout_2<='0';
                                          end if;
                            end if;
              d_2<=temp1;
              end process;

              process(clk_h)
              begin

                            if(clk_h'event and clk_h='1')then
                                          if(temp2="0101")then
                                                                      temp2<="0000";cout_3<='1';
                                          else
                                                        temp2<=temp2+1;cout_3<='0';
                                          end if;
                            end if;
              d_3<=temp2;
              end process;

end behav;

2.3.4、时——12/24进制芯片


library ieee;
use ieee.std_logic_1164.all;
use ieee.std_logic_unsigned.all;
entity hour is
              port (
                            clk_l:in std_logic;
                            clk_h:in std_logic;                           
                            d_4,d_5:out std_logic_vector(3 downto 0);
                            cout_4,cout_5:out std_logic;
                            hour_12_24:in std_logic
                            );
end hour;
architecture behav of hour is
signal temp1,temp2:std_logic_vector(3 downto 0);
begin

process(clk_l,hour_12_24)
begin
              if(hour_12_24='1')then----------24小时制
                            if(clk_l'event and clk_l='1')then
                                          if(temp2="0010")then
                                                        if(temp1>="0011")then
                                                        temp1<="0000";cout_4<='1';
                                                        else
                                                        temp1<=temp1+1;cout_4<='0';
                                                        end if;
                                          elsif(temp1="1001")then
                                                        temp1<="0000";cout_4<='1';
                                          else
                                                        temp1<=temp1+1;cout_4<='0';
                                          end if;
                            end if;
                            d_4<=temp1;
              else---------------------------12小时制
                            if(clk_l'event and clk_l='1')then
                                                        if(temp2="0001")then
                                                                      if(temp1>="0010")then
                                                                                    temp1<="0001";
                                                                                    cout_4<='1';
                                                                      else
                                                                                    temp1<=temp1+1;
                                                                                    cout_4<='0';
                                                                      end if;
                                                        elsif(temp1="1001")then
                                                                                    temp1<="0000";
                                                                                    cout_4<='1';
                                                        else
                                                                      temp1<=temp1+1;


                                                                      cout_4<='0';
                                                        end if;
                                          end if;
                                          d_4<=temp1;
              end if;
end process;

process(clk_h,hour_12_24)
begin
              if(hour_12_24='1')then
                            if(clk_h'event and clk_h='1')then
                                          if(temp2="0010")then
                                                        temp2<="0000";cout_5<='1';
                                          else
                                                        temp2<=temp2+1;cout_5<='0';
                                          end if;
                            end if;
                            d_5<=temp2;
              else
                            if(clk_h'event and clk_h='1')then
                                          if(temp2="0001")then
                                                                      temp2<="0000";
                                                                      cout_5<='1';
                                          else
                                                        temp2<=temp2+1;
                                                        cout_5<='0';
                                          end if;
                            end if;
                            d_5<=temp2;
              end if;
end process;

end behav;
3、秒表


3.1、秒表顶层、底层原理图


3.2秒表顶层文件


library ieee;
use ieee.std_logic_1164.all;
use ieee.std_logic_unsigned.all;

entity stopwatch is
              port(
                            mode:in std_logic_vector(1 downto 0);
                            clk:in std_logic;-----------100hz 精确度位0.01s
                            start:in std_logic;--step_up
                            clr:in std_logic;
                            d_6,d_7,d_8,d_9:out std_logic_vector(3 downto 0)
                            );
end stopwatch;
architecture struct of stopwatch is

              component count_10_d_0 is

                            port(            
                                                        mode:in std_logic_vector(1 downto 0);
                                                        clk1,clear,start:in std_logic;
                                                        bcd_out:out std_logic_vector(3 downto 0);
                                                        cout:buffer std_logic);
              end component;

              component count_10_d_1 is
                            port(              clk2,clear:in std_logic;
                                                        bcd_out:out std_logic_vector(3 downto 0);
                                                        cout:buffer std_logic);            
              end component;

              component count_10_d_2 is
                            port(              clk3,clear:in std_logic;
                                                        bcd_out:out std_logic_vector(3 downto 0);
                                                        cout:buffer std_logic);            
              end component;

              component count_10_d_3 is
                            port(              clk4,clear:in std_logic;
                                                        bcd_out:out std_logic_vector(3 downto 0);
                                                        cout:buffer std_logic);            
              end component;

              signal clk1,clk2,clk3,cout:std_logic;

              begin

              u31:count_10_d_0 port map(mode,clk,clr,start,d_6,clk1);
              u32:count_10_d_1 port map(clk1,clr,d_7,clk2);
              u33:count_10_d_2 port map(clk2,clr,d_8,clk3);
              u34:count_10_d_3 port map(clk3,clr,d_9,cout);

end architecture struct;

3.3秒表底层文件3.3.1、十进制计时器(4个计数器级联)
library ieee;
use ieee.std_logic_1164.all;
use ieee.std_logic_unsigned.all;
entity count_10_d_0 is
              port(            
                            mode:in std_logic_vector(1 downto 0);
                            clk1,clear,start:in std_logic;
                            bcd_out:out std_logic_vector(3 downto 0);
                            cout:buffer std_logic
);
end entity count_10_d_0;

architecture behavioral of count_10_d_0 is
              signal temp:std_logic_vector(3 downto 0);
              signal start_state:std_logic:='1';
              begin

              process(start)
              begin
                            if(start'event and start='1')then
                                          if(mode="10")then
                                                        start_state<=not start_state;
                                          else
                                                        start_state<='1';
                                          end if;
                            else start_state<=start_state;
                            end if;                                         
              end process;

              process(clk1,clear)is
              begin
                            if(clear='1')then
                                          temp<="0000";cout<='0';
                            elsif(clk1'event and clk1='1')then
                                          if(start_state='0')then
                                                        if(temp="1001")then
                                                                      temp<="0000";cout<='1';
                                                        else
                                                                      temp<=temp+1;cout<='0';
                                                        end if;
                                          else
                                                        temp<=temp;
                                          end if;
                            end if;
                            bcd_out<=temp;
              end process;
end architecture behavioral;
4、定时闹钟4.1、闹钟顶层原理图


4.2、闹钟顶层程序
library ieee;
use ieee.std_logic_1164.all;
use ieee.std_logic_unsigned.all;
entity timer is
              port(
                            clk:in std_logic;
                            mode:in std_logic_vector(1 downto 0);
                            clk_1hz:in std_logic;
                            clk_2hz:in std_logic;
                            flag2:in std_logic_vector(2 downto 0);
                            step_up:in std_logic;
                            clr:in std_logic;
                            d_10,d_11,d_12,d_13:out std_logic_vector(3 downto 0);
                            led:out std_logic;
                            alarm_on:in std_logic;
                            t_now5,t_now4,t_now3,t_now2:in std_logic_vector(3 downto 0)
                            );
end entity;

architecture struct of timer is
              component xuanze_mode_4_1 is
                            port(
                                          clk:in std_logic;
                                          in2,in3,in4,in5:in std_logic;
                                          step_up:in std_logic;
                                          flag2:in std_logic_vector(2 downto 0);
                                          co2,co3,co4,co5:out std_logic
                                          );
              end component;

              component time_set is
                            port (
                                          clk:in std_logic;
                                          mode:in std_logic_vector(1 downto 0);
                                          flag2:in std_logic_vector(2 downto 0);
                                          clk1,clk2,clk3,clk4:in std_logic;
                                          clear:in std_logic;
                                          step_up:in std_logic;
                                          d_10,d_11,d_12,d_13:out std_logic_vector(3 downto 0);
                                          cout4:buffer std_logic;
                                          alarm_on:in std_logic;
                                          t_now5,t_now4,t_now3,t_now2:in std_logic_vector(3 downto 0)
                                          );
              end component;

              component alarm is
                            port(
                                          clk:in std_logic;
                                          c_in:in std_logic;
                                          c_out:out std_logic
                                          );
              end component;

              signal cout1,cout2,cout3,cout4,clk1,clk2,clk3,clk4:std_logic;

begin

              u40:xuanze_mode_4_1 port map(clk,clk_1hz,cout1,cout2,cout3,step_up,flag2,clk1,clk2,clk3,clk4);
              u41:time_set port map(clk,mode,flag2,clk1,clk2,clk3,clk4,clr,step_up,d_10,d_11,d_12,d_13,cout4,alarm_on,t_now5,t_now4,t_now3,t_now2);
              u42:alarm port map(clk_2hz,cout4,led);

end struct;

4.3、闹钟底层文件4.3.1、调整位选择
library ieee;
use ieee.std_logic_1164.all;
use ieee.std_logic_unsigned.all;

entity xuanze_mode_4_1 is
              port(
                            clk:in std_logic;
                            in2,in3,in4,in5:in std_logic;
                            step_up:in std_logic;
                            flag2:in std_logic_vector(2 downto 0);
                            co2,co3,co4,co5:out std_logic
                            );
end xuanze_mode_4_1;

architecture behav of xuanze_mode_4_1 is
begin
              process(clk,flag2,in2,in3,in4,in5,step_up)
              begin
                            case flag2 is
                            when "000" =>              co2<=in2;
                                                                                                  co3<=in3;
                                                                                                  co4<=in4;
                                                                                                  co5<=in5;

                            when "001" =>              co2<=step_up;
                                                                                                  co3<=in3;
                                                                                                  co4<=in4;
                                                                                                  co5<=in5;

                            when "010" =>              co3<=step_up;                                                                                                
                            when "011" =>              co4<=step_up;                                                                                                
                            when "100" =>              co5<=step_up;                                                                                                
                            when others =>              null;
                            end case;
              end process;
end behav;

4.3.2、时间设定
library ieee;
use ieee.std_logic_1164.all;
use ieee.std_logic_unsigned.all;
entity time_set is
              port(
                            clk:in std_logic;
                            mode:in std_logic_vector(1 downto 0);
                            flag2:in std_logic_vector(2 downto 0);
                            clk1,clk2,clk3,clk4:in std_logic;
                            clear:in std_logic;
                            step_up:in std_logic;
                            d_10,d_11,d_12,d_13:out std_logic_vector(3 downto 0);
                            cout4:buffer std_logic;
                            alarm_on:in std_logic;
                            t_now5,t_now4,t_now3,t_now2:in std_logic_vector(3 downto 0)
                            );
end time_set;

architecture behav of time_set is
signal temp1,temp2,temp3,temp4:std_logic_vector(3 downto 0);

signal start_state:std_logic:='1';
begin

process(clk,cout4)
begin                           
              if(clk'event and clk='1')then
                            if(alarm_on='0')then
                                          ----目前时间和设定的时间对比
                                          if(t_now5=temp4 and t_now4=temp3 and t_now3=temp2 and t_now2=temp1)then
                                                        cout4<='1';
                                          else
                                                        cout4<='0';
                                          end if;
                            else
                                          cout4<='0';
                            end if;
              end if;                           
end process;

process(clk1,clear)is
begin                           
              if(clear='1')then
                            temp1<="0000";
              elsif(clk1'event and clk1='1')then--有脉冲信号 进行数字调整 +1
                            if(flag2/="000")then
                                          if(temp1="1001")then
                                                        temp1<="0000";
                                          else
                                                        temp1<=temp1+1;
                                          end if;
                            end if;
              end if;
              d_10<=temp1;
end process;

process(clk2,clear)is
begin
              if(clear='1')then
                            temp2<="0000";
              elsif(clk2'event and clk2='1')then
                            if(flag2/="000")then
                                          if(temp2="1001")then
                                                        temp2<="0000";
                                          else
                                                        temp2<=temp2+1;
                                          end if;
                            end if;
              end if;
              d_11<=temp2;
end process;

process(clk3,clear)is
begin
              if(clear='1')then
                            temp3<="0000";
              elsif(clk3'event and clk3='1')then
                            if(flag2/="000")then
                                          if(temp3="1001")then
                                                        temp3<="0000";
                                          else
                                                        temp3<=temp3+1;
                                          end if;
                            end if;
              end if;
              d_12<=temp3;
end process;

process(clk4,clear)is
begin
              if(clear='1')then
                            temp4<="0000";
              elsif(clk4'event and clk4='1')then
                            if(flag2/="000")then
                                          if(temp4="1001")then
                                                        temp4<="0000";
                                          else
                                                        temp4<=temp4+1;
                                          end if;
                            end if;
              end if;
              d_13<=temp4;
end process;
end behav;
4.3.3、闹铃
library ieee;
use ieee.std_logic_1164.all;
use ieee.std_logic_unsigned.all;

entity alarm is
              port(
                            clk:in std_logic;
                            c_in:in std_logic;
                            c_out:out std_logic--led
                            );
end entity;

architecture behav of alarm is
signal alarm_state:std_logic:='0';
begin

              process(c_in,clk)
              begin
                            if(c_in='1')then
                                          if(clk='1')then
                                                        c_out<='1';
                                          else
                                                        c_out<='0';
                                          end if;
                            else
                                          c_out<='0';
                            end if;
              end process;                                         

end behav;
5、按键消抖5.1、按键消抖原理图

5.2、按键消抖底层程序
library ieee;
use ieee.std_logic_1164.all;
use ieee.std_logic_unsigned.all;

entity key is
              port(
                            clk:in std_logic;
                            mode,set,step_up,ok,clr:in std_logic;
                            mode_out,set_out,step_up_out,ok_out,clr_out:out std_logic
                            );
end key;

architecture behav of key is
begin

              process(clk,mode,set,step_up,ok,clr)
              variable count1,count2,count3,count4,count5:integer range 0 to 1000000; --20ms延时消抖
              begin

                            if rising_edge(clk) then
                                          if mode='0' then
                                                        if count1<1000000 then
                                                                      count1:=count1+1;
                                                        else
                                                                      count1:=count1;
                                                        end if;
                                                        if count1<=999999 then
                                                                      mode_out<='1';
                                                        else
                                                                      mode_out<='0';
                                                        end if;
                                          else count1:=0;
                                          end if;

                                          if set='0' then              
                                                        if count2<1000000 then
                                                                      count2:=count2+1;
                                                        else
                                                                      count2:=count2;
                                                        end if;

                                                        if count2<=999999 then
                                                                      set_out<='1';
                                                        else
                                                                      set_out<='0';
                                                        end if;
                                          else count2:=0;
                                          end if;

                                          if step_up='0' then                                          
                                                        if count3<1000000 then
                                                                      count3:=count3+1;
                                                        else
                                                                      count3:=count3;
                                                        end if;

                                                        if count3<=999999 then
                                                                      step_up_out<='1';
                                                        else
                                                                      step_up_out<='0';
                                                        end if;                                                        
                                          else count3:=0;
                                          end if;

                                          if ok='0' then
                                                        if count4<1000000 then
                                                                      count4:=count4+1;
                                                        else
                                                                      count4:=count4;
                                                        end if;

                                                        if count4<=999999 then
                                                                      ok_out<='1';
                                                        else
                                                                      ok_out<='0';
                                                        end if;
                                          else count4:=0;
                                          end if;

                                          if clr='0' then                           
                                                        if count5<1000000 then
                                                                      count5:=count5+1;
                                                        else
                                                                      count5:=count5;
                                                        end if;

                                                        if count5<=999999 then
                                                                      clr_out<='1';
                                                        else
                                                                      clr_out<='0';
                                                        end if;
                                          else count5:=0;
                                          end if;
                            end if;
              end process ;
end behav;
6、按键处理部分6.1按键处理原理图
6.2按键处理底层程序
1 / 2

library ieee;
use ieee.std_logic_1164.all;
use ieee.std_logic_unsigned.all;

entity controller is
              port(
                            clk:in std_logic;
                            mode:in std_logic;
                            set:in std_logic;
                            ok:in std_logic;            
                            mode_out:buffer std_logic_vector(1 downto 0);
                            flag1,flag2:buffer std_logic_vector(2 downto 0)
                            );
end controller;

architecture behav of controller is
signal set_ok1,set_ok2: std_logic_vector(2 downto 0):="000";
signal mode_state:std_logic_vector(1 downto 0):="00";
begin

              process(mode,set,ok,clk)
              begin

                                          if(mode='1'and mode'event)then
                                                        if(mode_state="11")then
                                                                      mode_state<="00";
                                                        else
                                                                      mode_state<=mode_state+1;                                         
                                                        end if;
                                          else mode_state<=mode_state;
                                          end if;

                                          if(mode_state="00" or mode_state="01")then

                                                        if(set='1'and set'event)then
                                                                      if(set_ok1="100")then
                                                                                    set_ok1<="000";
                                                                      else
                                                                                    set_ok1<=set_ok1+1;
                                                                      end if;
                                                        end if;
                                          end if;

                                          if(mode_state="11")then
                                                        if(set='1'and set'event)then
                                                                      if(set_ok2="100")then
                                                                                    set_ok2<="000";
                                                                      else
                                                                                    set_ok2<=set_ok2+1;
                                                                      end if;
                                                        end if;
                                          end if;
                            mode_out<=mode_state;
                            flag1<=set_ok1;
                            flag2<=set_ok2;

              end process;

end behav;

7、选中数码管闪烁7.1、原理图

7.2、底层程序
library ieee;
use ieee.std_logic_1164.all;
use ieee.std_logic_unsigned.all;

entity shining is
              port(
                            mode:in std_logic_vector(1 downto 0);
                            clk1:in std_logic;
                            clk:in std_logic;
                            flag1,flag2:in std_logic_vector(2 downto 0);
                            d_2_in,d_3_in,d_4_in,d_5_in:in std_logic_vector(3 downto 0);
                            d_10_in,d_11_in,d_12_in,d_13_in:in std_logic_vector(3 downto 0);
                            d_2,d_3,d_4,d_5,d_10,d_11,d_12,d_13:out std_logic_vector(3 downto 0)                           
                            );
end shining;

architecture behav of shining is
begin

              process(clk1,mode,flag1,flag2,clk,d_2_in,d_3_in,d_4_in,d_5_in,d_10_in,d_11_in,d_12_in,d_13_in)
              begin
              if(clk1'event and clk1='1')then
                            case mode is
                            when "00" =>

                                          case flag1 is
                                          when "000" =>               d_2<=d_2_in;
                                                                                                                d_3<=d_3_in;
                                                                                                                d_4<=d_4_in;
                                                                                                                d_5<=d_5_in;

                                          when "001" =>              if(clk='1')then
                                                                                                                d_2<="1010";
                                                                                                  else
                                                                                                                d_2<=d_2_in;
                                                                                                  end if;
                                                                                                                d_3<=d_3_in;
                                                                                                                d_4<=d_4_in;
                                                                                                                d_5<=d_5_in;

                                          when "010" =>              if(clk='1')then
                                                                                                                d_3<="1010";
                                                                                                  else
                                                                                                                d_3<=d_3_in;
                                                                                                  end if;
                                                                                                                d_2<=d_2_in;
                                                                                                                d_4<=d_4_in;
                                                                                                                d_5<=d_5_in;

                                          when "011" =>              if(clk='1')then
                                                                                                                d_4<="1010";
                                                                                                  else
                                                                                                                d_4<=d_4_in;
                                                                                                  end if;
                                                                                                                d_2<=d_2_in;
                                                                                                                d_3<=d_3_in;
                                                                                                                d_5<=d_5_in;

                                          when "100" =>              if(clk='1')then
                                                                                                                d_5<="1010";
                                                                                                  else
                                                                                                                d_5<=d_5_in;
                                                                                                  end if;
                                                                                                                d_2<=d_2_in;
                                                                                                                d_3<=d_3_in;
                                                                                                                d_4<=d_4_in;

                                          when others =>              d_2<=d_2_in;
                                                                                                                d_3<=d_3_in;
                                                                                                                d_4<=d_4_in;
                                                                                                                d_5<=d_5_in;
                                          end case;

                            when "01" =>              d_2<=d_2_in;
                                                                                                  d_3<=d_3_in;
                                                                                                  d_4<=d_4_in;
                                                                                                  d_5<=d_5_in;
                                                                                                  d_10<=d_10_in;
                                                                                                  d_11<=d_11_in;
                                                                                                  d_12<=d_12_in;
                                                                                                  d_13<=d_13_in;            

                            when "10" =>              d_2<=d_2_in;
                                                                                                  d_3<=d_3_in;
                                                                                                  d_4<=d_4_in;
                                                                                                  d_5<=d_5_in;
                                                                                                  d_10<=d_10_in;
                                                                                                  d_11<=d_11_in;
                                                                                                  d_12<=d_12_in;
                                                                                                  d_13<=d_13_in;

                            when "11" =>            

                                          case flag2 is
                                          when "000" =>               d_10<=d_10_in;
                                                                                                                d_11<=d_11_in;
                                                                                                                d_12<=d_12_in;
                                                                                                                d_13<=d_13_in;

                                          when "001" =>              if(clk='1')then
                                                                                                                              d_10<="1010";
                                                                                                                else
                                                                                                                              d_10<=d_10_in;
                                                                                                                end if;
                                                                                                                d_11<=d_11_in;
                                                                                                                d_12<=d_12_in;
                                                                                                                d_13<=d_13_in;                                                                                                               

                                          when "010" =>              if(clk='1')then
                                                                                                                              d_11<="1010";
                                                                                                                else
                                                                                                                              d_11<=d_11_in;
                                                                                                                end if;
                                                                                                                d_10<=d_10_in;
                                                                                                                d_12<=d_12_in;
                                                                                                                d_13<=d_13_in;

                                          when "011" =>              if(clk='1')then
                                                                                                                              d_12<="1010";
                                                                                                                else
                                                                                                                              d_12<=d_12_in;
                                                                                                                end if;
                                                                                                                d_10<=d_10_in;
                                                                                                                d_11<=d_11_in;
                                                                                                                d_13<=d_13_in;            

                                          when "100" =>              if(clk='1')then
                                                                                                                              d_13<="1010";
                                                                                                                else
                                                                                                                              d_13<=d_13_in;
                                                                                                                end if;
                                                                                                                d_10<=d_10_in;
                                                                                                                d_11<=d_11_in;
                                                                                                                d_12<=d_12_in;

                                          when others =>              d_10<=d_10_in;
                                                                                                                d_11<=d_11_in;
                                                                                                                d_12<=d_12_in;
                                                                                                                d_13<=d_13_in;
                                          end case;
                            when others => null;
                            end case;
              end if;
              end process;            
end behav;
8、数码管显示控制8.1、原理图

8.2底层程序
library ieee;
use ieee.std_logic_1164.all;
use ieee.std_logic_arith.all;
use ieee.std_logic_unsigned.all;
entity selection is
              port(
                            clk:in std_logic;
                            mode:in std_logic_vector(1 downto 0);
                            d_0,d_1,d_2,d_3,d_4,d_5:in std_logic_vector(3 downto 0);
                            d_6,d_7,d_8,d_9:in std_logic_vector(3 downto 0);
                            d_10,d_11,d_12,d_13:in std_logic_vector(3 downto 0);
                            d_0_out,d_1_out,d_2_out,d_3_out:out std_logic_vector(3 downto 0)
                            );
end entity;

architecture behav of selection is
begin
              process(clk,mode,d_0,d_1,d_2,d_3,d_4,d_5,d_6,d_7,d_8,d_9,d_10,d_11,d_12,d_13)
              begin
              if(clk'event and clk='1')then
                            case mode is
                            when "00" =>              d_0_out<=d_2;
                                                                                                  d_1_out<=d_3;
                                                                                                  d_2_out<=d_4;
                                                                                                  d_3_out<=d_5;            
                            when "01" =>              d_0_out<=d_0;
                                                                                                  d_1_out<=d_1;
                                                                                                  d_2_out<=d_2;
                                                                                                  d_3_out<=d_3;
                            when "10" =>              d_0_out<=d_6;
                                                                                                  d_1_out<=d_7;
                                                                                                  d_2_out<=d_8;
                                                                                                  d_3_out<=d_9;
                            when "11" =>              d_0_out<=d_10;
                                                                                                  d_1_out<=d_11;
                                                                                                  d_2_out<=d_12;
                                                                                                  d_3_out<=d_13;            
                            when others => null;
                            end case;
              end if;
              end process;
end behav;
9、数码管译码器9.1、原理图
9.2、底层程序
library ieee;
use ieee.std_logic_1164.all;
use ieee.std_logic_unsigned.all;            

entity seg7led is
              port(
                            mode:in std_logic_vector(1 downto 0);
                            clk4,clear:in std_logic;
                            d_0,d_1,d_2,d_3: in std_logic_vector(3 downto 0);
                            dis:out std_logic_vector(7 downto 0);
                            cs:out std_logic_vector(3 downto 0)
                            );
end seg7led;

architecture behav of seg7led is
signal dakey:std_logic_vector(3 downto 0);
signal ca:integer range 0 to 3;
begin

              n0:process(clk4,clear)
              variable cal:integer range 0 to 3;
              begin

                            if(clear='1')then
                                          cal:=0;
                            elsif rising_edge(clk4)then
                                          if(cal=3)then
                                                        cal:=0;
                                          else
                                                        cal:=cal+1;
                                          end if;
                            end if;                           
                            ca<=cal;
              end process n0;            

              n1:process(ca)
              variable ss:std_logic_vector(3 downto 0);
              begin
                            case ca is
                                          when 0 =>ss:=d_0(3 downto 0);cs<="0111";dis(7)<='0';
                                          when 1 =>ss:=d_1(3 downto 0);cs<="1011";dis(7)<='0';
                                          when 2 =>ss:=d_2(3 downto 0);cs<="1101";if(mode/="11")then
dis(7)<='1';else dis(7)<='0';
end if;
                                          when 3 =>ss:=d_3(3 downto 0);cs<="1110";dis(7)<='0';
                                          when others => ss:="ZZZZ";cs<="1111";
                            end case;
                            dakey<=ss;
              end process n1;
              n2:process(dakey)
              begin
                            case dakey is
                                          when "0000" => dis(6 downto 0) <= "0111111"; -- 0
                                          when "0001" => dis(6 downto 0) <= "0000110"; -- 1
                                          when "0010" => dis(6 downto 0) <= "1011011"; -- 2
                                          when "0011" => dis(6 downto 0) <= "1001111"; -- 3
                                          when "0100" => dis(6 downto 0) <= "1100110"; -- 4
                                          when "0101" => dis(6 downto 0) <= "1101101"; -- 5
                                          when "0110" => dis(6 downto 0) <= "1111101"; -- 6                                         
                                          when "0111" => dis(6 downto 0) <= "0000111"; -- 7
                                          when "1000" => dis(6 downto 0) <= "1111111"; -- 8
                                          when "1001" => dis(6 downto 0) <= "1101111"; -- 9
                                          when others => dis(6 downto 0) <= "0000000";
                            end case;
              end process;
end behav;
10、FPGA芯片引脚锁定UCF文件
NET "clk" LOC= P23;//系统时钟25MHz

NET "mode" LOC= P41;
NET "set" LOC= P44;
NET "step_up" LOC= P47;
NET "ok" LOC= P43;
NET "clr" LOC= P40;
NET "hour_12_24" LOC= P29;
NET "alarm_on" LOC= P32;
NET "clock_stop" LOC= P33;
NET "led" LOC= P27;
//位选
NET "CS<0>" LOC= P2;
NET "CS<1>" LOC= P142;
NET "CS<2>" LOC= P141;
NET "CS<3>" LOC= P132;
//段选
NET "DIS<0>" LOC= P1;
NET "DIS<1>" LOC= P140;
NET "DIS<2>" LOC= P134;
NET "DIS<3>" LOC= P138;
NET "DIS<4>" LOC= P137;
NET "DIS<5>" LOC= P143;
NET "DIS<6>" LOC= P133;
NET "DIS<7>" LOC= P139;

三、仿真波形1、秒——60进制计数

时钟的秒位是60进制计数器,当计数到60后cout产生溢出脉冲信号

2、时钟暂停及运行
时钟的运行及暂停受clock_stop控制 clock_stop=’1’ 时钟暂停;clock_stop=’0’ 时钟运行

全部资料51hei下载地址:
EDA课程设计.rar (2.49 MB, 下载次数: 68)

评分

参与人数 1黑币 +50 收起 理由
admin + 50 共享资料的黑币奖励!

查看全部评分

回复

使用道具 举报

ID:191542 发表于 2019-3-15 14:58 | 显示全部楼层
这个帖子在上传的时候由于格式问题,浏览的时候有些乱,实在是不好意思。但是呢,功能全部实现。

评分

参与人数 1黑币 +20 收起 理由
admin + 20 回帖助人的奖励!

查看全部评分

回复

使用道具 举报

ID:502774 发表于 2019-5-23 21:51 来自手机 | 显示全部楼层
谢谢分享
回复

使用道具 举报

ID:1056772 发表于 2022-12-11 01:48 来自手机 | 显示全部楼层
总是离人泪 发表于 2019-3-15 14:58
这个帖子在上传的时候由于格式问题,浏览的时候有些乱,实在是不好意思。但是呢,功能全部实现。

工程原理部分看不懂呀
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

手机版|小黑屋|51黑电子论坛 |51黑电子论坛6群 QQ 管理员QQ:125739409;技术交流QQ群281945664

Powered by 单片机教程网

快速回复 返回顶部 返回列表