time.vhd

来自「一个用VHDL编程基于CPLD的EDA实验板开发可以实现顺计时和倒计时的秒表。要」· VHDL 代码 · 共 45 行

VHD
45
字号
library ieee;
use ieee.std_logic_1164.all;
use ieee.std_logic_unsigned.all;
entity time is
port(clk:in std_logic;							--时钟500Hz
    reset:in std_logic;        					--复位信号
	start:in std_logic;                         --启动信号
	stop:in std_logic;							--暂停信号
	clkout:out std_logic;					--软件分频得到时钟信号频率为10Hz
	bcd1:out std_logic_vector(11 downto 0));    --时间输出信号
end time;
architecture behav of time is
	signal clk1: std_logic;					--软件分频得到时钟信号频率为10Hz
begin
	--divclk进程,产生clkout脉冲(频率为10Hz)
	divclk:process(clk)
		variable cnt:integer range 0 to 50:=0;
	begin	
		if clk'event and clk='1' then
			if cnt=50 then cnt:=0;clk1<='1';
			else cnt:=cnt+1;clk1<='0';
			end if;
		end if;
	end process divclk;
	--timecount进程,实现顺计时
	timecount:process(clk1,reset)
		variable time_reg: std_logic_vector(11 downto 0);
	begin
		if reset='1' then time_reg:="000000000000";
		elsif clk1'event and clk1='1' then
			if (start='1' and stop='0')then
				if time_reg(3 downto 0)="1001" then
					time_reg:=time_reg+"0111";
				else 
					time_reg(3 downto 0):=time_reg(3 downto 0)+"0001";
				end if;
				if time_reg(7 downto 4)="1010" then 
					time_reg:=time_reg+"01100000";
				end if;
			end if;
		end if;
		bcd1<=time_reg;
	end process timecount;
	clkout<=clk1;
end behav;

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?