?? 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 + -