📄 cmp.vhd
字号:
library IEEE;
use IEEE.std_logic_1164.all;
use IEEE.std_logic_unsigned.all;
entity cmp is
port(clk_100:in std_logic; --100HZ输入
clk_1:in std_logic; --1HZ输入
reset:in std_logic; --重置
start:in std_logic; --开始
sum1,sum2:in std_logic_vector(4 downto 0); --计数输入
record1,record2:out std_logic_vector(1 downto 0); --比分输出
music_begin:out std_logic; --音乐开始
sw:out std_logic; --状态输出
lights:out std_logic_vector(2 downto 0)); --绳子状态
end cmp;
architecture body_cmp of cmp is
signal tmp_record1:std_logic_vector(1 downto 0); --比分
signal tmp_record2:std_logic_vector(1 downto 0);
signal tmp:std_logic_vector(2 downto 0); --绳子状态
signal tmp_sta:std_logic; --状态
signal s1,s2:std_logic_vector(4 downto 0); --计数
begin
record1<=tmp_record1;
record2<=tmp_record2;
lights<=tmp;
sw<=tmp_sta;
process(clk_100) --判断比赛状态
begin
if(start='1') then
if(clk_100'event and clk_100='1') then
tmp_sta<='1';
end if;
end if;
if(clk_100'event and clk_100='1') then --任意比分到3,比赛结束,开始播放音乐
if(tmp_record1="11" or tmp_record2="11") then
tmp_sta<='0';
music_begin<='1';
end if;
if(tmp="001" or tmp="111") then --绳子到头,进入等待状态
tmp_sta<='0';
end if;
if(reset='1') then --复位,状态归零
tmp_sta<='0';
music_begin<='0';
end if;
end if;
end process;
s1<=sum1;
s2<=sum2;
process(clk_1,reset) --控制绳子移位
begin
if(reset='1') then
tmp<="100"; --绳子初始状态为100
tmp_record1<="00";
tmp_record2<="00";
else
if(clk_1'event and clk_1='1') then
if(tmp_sta='1') then
if(s1>s2) then tmp<=tmp-'1'; --绳子左移
elsif(s1=s2) then tmp<=tmp; --绳子保持原状
else tmp<=tmp+'1'; --绳子右移
end if;
else
if(tmp="001") then --绳子到左尽头,左计分器加1
tmp_record1<=tmp_record1+'1';
tmp<="100";
elsif(tmp="111") then --绳子到右尽头,右记分器加1,
tmp_record2<=tmp_record2+'1';
tmp<="100";
end if;
end if;
end if;
end if;
end process;
end body_cmp;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -