问答文章1 问答文章501 问答文章1001 问答文章1501 问答文章2001 问答文章2501 问答文章3001 问答文章3501 问答文章4001 问答文章4501 问答文章5001 问答文章5501 问答文章6001 问答文章6501 问答文章7001 问答文章7501 问答文章8001 问答文章8501 问答文章9001 问答文章9501

高分求 基于VHDL语言设计的数字时钟

发布网友 发布时间:2022-05-14 07:19

我来回答

1个回答

热心网友 时间:2023-10-09 16:45

-------------------程序(.vhd文件)如下---------------------------
library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
use IEEE.STD_LOGIC_ARITH.ALL;
use IEEE.STD_LOGIC_UNSIGNED.ALL;

---- Uncomment the following library declaration if instantiating
---- any Xilinx primitives in this code.
--library UNISIM;
--use UNISIM.VComponents.all;

entity clock is
port(
clk : in std_logic;
rst : in std_logic;
inc_min : in std_logic;
sub_min : in std_logic;
inc_hour : in std_logic;
sub_hour : in std_logic;
sel : out std_logic_vector(3 downto 0);
q : out std_logic_vector(7 downto 0));
end clock;

architecture Behavioral of clock is
signal sec_counter1:std_logic_vector(3 downto 0);
signal sec_counter2:std_logic_vector(3 downto 0);
signal min_counter1:std_logic_vector(3 downto 0);
signal min_counter2:std_logic_vector(3 downto 0);
signal hour_counter1:std_logic_vector(3 downto 0);
signal hour_counter2:std_logic_vector(3 downto 0);
signal divcounter : std_logic_vector(27 downto 0);
signal div_clk : std_logic;
signal scancounter : std_logic_vector(10 downto 0);
signal scan_clk : std_logic;
signal scan_out : std_logic_vector(2 downto 0);
signal secseg1,secseg2,minseg1,minseg2,hourseg1,hourseg2:std_logic_vector(7downto 0);
begin

--计数时钟,对外部输入时钟分频,此处只适用于仿真,实际进行时间计数时,分频后时钟应该满足1HZ。

process(rst,clk)
begin
if(rst='0')then
divcounter <= (others=>'0');
div_clk<='0';
elsif(rising_edge(clk))then
if(divcounter=X"17D7840") then
divcounter <= (others=>'0');
div_clk<=not div_clk;
else
divcounter<=divcounter+'1';
end if;
end if;
end process;

--仿真时数码管扫描??钟,实??中?韪菥咛迩榭鼋械鹘馐敝悠德?process(rst,clk)
begin
if(rst='0')then
scancounter<=(others=>'0');
scan_clk<='0';
elsif(rising_edge(clk))then
if(scancounter="00011111111") then
scancounter<=(others=>'0');
scan_clk<=not scan_clk;
else
scancounter<=scancounter+'1';
end if;
end if;
end process;

--时钟计数部分主进程
--时钟复位
clock:process(div_clk,rst)
begin
if(rst='0')then
sec_counter1<=X"0";
sec_counter2<=X"0";
min_counter1<=X"0";
min_counter2<=X"0";
hour_counter1<=X"0";
hour_counter2<=X"0";

--手动调分,递增
elsif(rising_edge(div_clk))then
if(inc_min='0') then
if(min_counter1=X"9") then
min_counter1<=X"0";
if(min_counter2>=X"5") then
min_counter2<=X"0";
else
min_counter2<=min_counter2+1;
end if;
else
min_counter1<=min_counter1+1;
end if;

--手动调分,递减
elsif(sub_min='0') then
if(min_counter1=X"0") then
min_counter1<=X"9";
if(min_counter2=X"0")then
min_counter2<=X"5";
else
min_counter2<=min_counter2-1;
end if;
else
min_counter1<=min_counter1-1;
end if;
--手动调时,增时
elsif(inc_hour='0') then
if(hour_counter2=X"2")then
if(hour_counter1=X"3")then
hour_counter1<=X"0";
hour_counter2<=X"0";
else
hour_counter1<=hour_counter1+1;
end if;
else
if(hour_counter1=X"9") then
hour_counter1<=X"0";
hour_counter2<=hour_counter2+1;
else
hour_counter1<=hour_counter1+1;
end if;
end if;
--手动调时,减时
elsif(sub_hour='0') then
if(hour_counter1=X"0")then
if(hour_counter2=X"0")then
hour_counter1<=X"3"; hour_counter2<=X"2";
else
hour_counter2<=hour_counter2-1;
hour_counter1<=X"9";
end if;
else
hour_counter1<=hour_counter1-1;
end if;
--时分秒正常计数
else
if(sec_counter1>=X"9") then
sec_counter1<=X"0";
if(sec_counter2>=X"5") then
sec_counter2<=X"0";
if(min_counter1>=X"9") then
min_counter1<=X"0";
if(min_counter2>=X"5") then
min_counter2<=X"0";
if(hour_counter2=X"2") then
if(hour_counter1=X"3") then
hour_counter1<=X"0";
hour_counter2<=X"0";
else
hour_counter1<=hour_counter1+1;
end if;
else
if(hour_counter1=X"9") then
hour_counter1<=X"0";
hour_counter2<=hour_counter2+1;
else
hour_counter1<=hour_counter1+1;
end if;
end if;
else
min_counter2<=min_counter2+1;
end if;
else
min_counter1<=min_counter1+1;
end if;
else
sec_counter2<=sec_counter2+1;
end if;
else
sec_counter1<=sec_counter1+1;
end if;
end if;
end if;

end process clock;
--生成扫描时钟
process(rst,scan_clk)
begin
if (rst='0') then
scan_out<="000";
elsif(rising_edge(scan_clk)) then
if(scan_out="011")then
scan_out<="000";
else
scan_out<=scan_out+1;
end if;
end if;
end process;
--扫描输出进程
process(scan_out)
begin
case scan_out is
when "000" => q<=secseg1; sel<="0001";
when "001" => q<=secseg2; sel<="0010";
when "010" => q<=minseg1; sel<="0100";
when "011" => q<=minseg2; sel<="1000";
--when "100" => q<=hourseg1; --sel<="100";
--when "101"=> q<=hourseg2; --sel<="101";
when others => q<="00000000";sel<="0000";
end case;
end process;
--秒低位显示
second_counter1:process(sec_counter1)
begin
case sec_counter1 is
when "0000" => secseg1<="10111111";
when "0001" => secseg1<="10000110";
when "0010" => secseg1<="11011011";
when "0011" => secseg1<="11001111";
when "0100" => secseg1<="11100110";
when "0101" => secseg1<="11101101";
when "0110" => secseg1<="11111101";
when "0111" => secseg1<="10000111";
when "1000" => secseg1<="11111111";
when "1001" => secseg1<="11101111";
when others => secseg1<="11111111";
end case;
end process second_counter1;
--秒高位显示
second_counter2:process(sec_counter2)
begin
case sec_counter2 is
when "0000" => secseg2<="00111111";
when "0001" => secseg2<="00000110";
when "0010" => secseg2<="01011011";
when "0011" => secseg2<="01001111";
when "0100" => secseg2<="01100110";
when "0101" => secseg2<="01101101";
when others => secseg2<="01111111";
end case;
end process second_counter2;
--分低位显示
minute_counter1:process(min_counter1)
begin
case min_counter1 is
when "0000" => minseg1<="10111111";
when "0001" => minseg1<="10000110";
when "0010" => minseg1<="11011011";
when "0011" => minseg1<="11001111";
when "0100" => minseg1<="11100110";
when "0101" => minseg1<="11101101";
when "0110" => minseg1<="11111101";
when "0111" => minseg1<="10000111";
when "1000" => minseg1<="11111111";
when "1001" => minseg1<="11101111";
when others => minseg1<="11111111";
end case;
end process minute_counter1;
--分高位显示
minute_counter2:process(min_counter2)
begin
case min_counter2 is
when "0000" => minseg2<="00111111";
when "0001" => minseg2<="00000110";
when "0010" => minseg2<="01011011";
when "0011" => minseg2<="01001111";
when "0100" => minseg2<="01100110";
when "0101" => minseg2<="01101101";
when others => minseg2<="01111111";
end case;
end process minute_counter2;
--小时低位显示
hor_counter1:process(hour_counter1)
begin
case hour_counter1 is
when "0000" => hourseg1<="10111111";
when "0001" => hourseg1<="10000110";
when "0010" => hourseg1<="11011011";
when "0011" => hourseg1<="11001111";
when "0100" => hourseg1<="11100110";
when "0101" => hourseg1<="11101101";
when "0110" => hourseg1<="11111101";
when "0111" => hourseg1<="10000111";
when "1000" => hourseg1<="11111111";
when "1001" => hourseg1<="11101111";
when others => hourseg1<="11111111";
end case;
end process;
--小时高位显示

hor_counter2:process(hour_counter2)
begin
case hour_counter2 is
when "0000" => hourseg2<="00111111";
when "0001" => hourseg2<="00000110";
when "0010" => hourseg2<="01011011";
when others => hourseg2<="01111111";
end case;
end process;
end Behavioral;
------------------引脚(.ucf文件)如下-------------------
#clk : in std_logic;
#rst : in std_logic;
#inc_min : in std_logic;
#sub_min : in std_logic;
#inc_hour : in std_logic;
#sub_hour : in std_logic;
#sel : out std_logic_vector(2 downto 0);
#q : out std_logic_vector(7 downto 0));

#PACE: Start of Constraints generated by PACE

#PACE: Start of PACE I/O Pin Assignments
NET "clk" LOC = "p80" ;
NET "inc_hour" LOC = "p20" | PULLUP ; #SW3
NET "inc_min" LOC = "p32" ; #SW1
NET "q<0>" LOC = "p47" ; # Bank = 1, Pin name = IO_L10P_1, Type = I/O, Sch name = JD4 (a)
NET "q<1>" LOC = "p50" ; # Bank = 1, Pin name = IO_L19P_1, Type = I/O, Sch name = JD5 (b)
NET "q<2>" LOC = "p48" ; # Bank = 1, Pin name = IO_L23P_1/HDC, Type = DUAL, Sch name = JD6(c)
NET "q<3>" LOC = "p41" ; # Bank = 1, Pin name = IO_L23N_1/LDC0, Type = DUAL, Sch name = JD7(d)
NET "q<4>" LOC = "p45" ; # Bank = 1, Pin name = IO_L20P_1, Type = I/O, Sch name = JD8(e)
NET "q<5>" LOC = "p42" ; # Bank = 1, Pin name = IO_L13P_1/A6/RHCLK4/IRDY1, Type = RHCLK/DUAL, Sch name = JD3(f)
NET "q<6>" LOC = "p49" ; # Bank = 1, Pin name = IO_L17P_1, Type = I/O, Sch name = JD1(g)

NET "q<7>" LOC = "p40" ;
NET "rst" LOC = "p43" ; #SW0

NET "sel<0>" LOC = "p34" ; # Bank = 1, Pin name = IO_L19N_1, Type = I/O, Sch name = SEG_SELIN1
NET "sel<1>" LOC = "p35" ; # Bank = 1, Pin name = IO_L16N_1/A0, Type = DUAL, Sch name = SEG_SELIN2
NET "sel<2>" LOC = "p36" ; # Bank = 1, Pin name = IO_L24P_1/LDC1, Type = DUAL, Sch name = SEG_SELIN3
NET "sel<3>" LOC = "p39" ; # Bank = 1, Pin name = IO_L21P_1, Type = I/O, Sch name = SEG_SELIN4

NET "sub_hour" LOC = "p14" | PULLUP ; #SW4

NET "sub_min" LOC = "p26" ; #SW2

#PACE: Start of PACE Area Constraints

#PACE: Start of PACE Prohibit Constraints

#PACE: End of Constraints generated by PACE
声明声明:本网页内容为用户发布,旨在传播知识,不代表本网认同其观点,若有侵权等问题请及时与本网联系,我们将在第一时间删除处理。E-MAIL:11247931@qq.com
...的话有啥影响,怎么听说对六年后换证有影响? ...重新刷学时吗,科一科二科三科四可以转校吗? 考完科一科二科三科四要多久 ...但是科目三的学时没有打满对以后有没有影响? 我的学时卡没有打过,一点都没有,不过我科一科二科三科四都全部考完了... 五行穿搭2021年10月8日五行属什么怎么穿衣 十月八日上到十月几日 ipadmini和iphone6是充电器不一样、还是数据线不一样呢?可以互相使用充 ... iphone6的插头可以通用ipad mini 吗 iphone6和ipad mini的充电器可以通用吗 吉他音孔拾音器的原理是什么 韩国喷码机有哪些知名品牌 兰州会议活动去哪家公司好啊? 求最新的火箭队目前球员名单 B型GT-A1音孔拾音器是什么品牌 国外的小字符喷码机与国内的喷码机要怎么选? 生物化学翻译 哪个牌子的喷码机好用 为什么ucf101有3个text文件 国内外有那些喷码机品牌? 谁知道国内外大字符喷码机的品牌有哪些 世界知名的喷码机有哪些品牌?国产的呢? 苗族三月三怎么过 《贤妻攻略》txt下载在线阅读全文,求百度网盘云资源 为什么人生气的时候容易变傻? 求名侦探柯南被狙击的名侦探的谜题和答案 女皇陛下怎么获得酒神? 一个正常人能变成傻子么? 一个正常人突然变傻了是一种怎样的体验? 福尔摩斯银耳环攻略 有哪些做年会活动比较好玩的策划公司? 急求一个计算机专业,关于JavaEE方向的论文翻译。 跪求 约瑟夫 凯赛尔《狮王》读后感 《狮王》txt全集下载 普通话语言中的声母、韵母、声调有哪些? 狮王进行曲的作者是谁? 《狮王争霸》为何是最佳《黄飞鸿》作品? 普通话声母和韵母都有多少个? 狮王联盟传奇一共几部 凌岚的狮王传奇读后感 黄飞鸿舞着狮子去祭拜,舞得特别生动传神,狮子也像哭一样的。出自哪一部电影除了赵文卓的那一部《狮王争 37.7度发烧了吗 成年人37.7度算发烧吗? 人体温度37.7度算低烧吗? 37.7度属于发烧吗 该如何处理 人体温度37.7度算不算正常? 体温37.7度正常吗? 37.7度算发烧吗手术 我有点感冒体温37.7度。体温正常吗? 腋下温度37.7度,需要去医院吗?