?? ok.vhd
字號:
library ieee;
use ieee.std_logic_1164.all;
use ieee.std_logic_unsigned.all;
entity ok is
port(
m:in std_logic;
clk:in std_logic;
reset:in std_logic;
a:in std_logic_vector(3 downto 0);
b1:out std_logic_vector(3 downto 0);
b2:out std_logic_vector(3 downto 0);
b:out std_logic_vector(6 downto 0);
disp:out std_logic_vector(5 downto 0);
level:in std_logic_vector(3 downto 0)
);
end ok;
architecture vhdl of ok is
component kongzhi is --kongzhi 控制器
port(
clk:in std_logic;
reset:in std_logic;
a:out std_logic_vector(2 downto 0);
b:out std_logic_vector(5 downto 0)
);
end component kongzhi;
component display is --display 顯示器
port(
n:in std_logic_vector(1 downto 0);
b1_temp:in std_logic_vector(3 downto 0);
a:in std_logic_vector(2 downto 0);
b:out std_logic_vector(6 downto 0);
u:in std_logic_vector(6 downto 0);
v:in std_logic_vector(6 downto 0)
);
end component display;
signal temp1:std_logic_vector(2 downto 0);
signal b1_temp:std_logic_vector(3 downto 0);
signal b2_temp:std_logic_vector(3 downto 0);
signal b_temp:std_logic_vector(6 downto 0);
signal n:std_logic_vector(1 downto 0);
signal k:std_logic;
signal u:std_logic_vector(6 downto 0);
signal v:std_logic_vector(6 downto 0);
signal count2_temp:std_logic_vector(3 downto 0);
begin
process(m,reset,b1_temp,b2_temp,k,level)
variable p:std_logic_vector(3 downto 0);
variable q:std_logic_vector(3 downto 0);
variable c:std_logic_vector(3 downto 0);
variable d:std_logic_vector(3 downto 0);
variable r:std_logic_vector(3 downto 0);
variable count1:std_logic_vector(3 downto 0);
variable count2:std_logic_vector(3 downto 0);
begin
if(reset='1')then --復(fù)位
b1_temp<="0000";
b2_temp<="1111";
n<="00";
count1:="0000";
count2:="0000";
else
if(m'event and m='0')then
r:=a xor b1_temp; --河右岸動物的情況,人在對岸則結(jié)果為1
p:=(not a) and "1100"; --判斷河的左岸 貓和狗
q:=(not a) and "0110"; --判斷河的左岸 貓和鼠
c:=a and "1100"; --判斷河的右岸 貓和狗
d:=a and "0110"; --判斷河的右岸 貓和鼠
if(r="0001" or r="1001" or r="0101" or r="0011")then--走法正確
if(a(0)='1')then --判斷人是否在河右岸
if(p="1100" or q="0110")then --判斷左岸
n<="01";
else --選擇正確
n<="10";
b1_temp<=a;
b2_temp<=not a;
count1:=count1+1; --計數(shù)器加1
end if;
else --人在左岸
if(c="1100" or d="0110")then --判斷右岸
n<="01";
else --選擇正確
n<="10";
b1_temp<=a;
b2_temp<=not a;
count1:=count1+1; --計數(shù)器加1
end if;
end if;
if(count1="1010")then
count1:="0000"; --進位
count2:=count2+1;
if(count2="1010")then --當計數(shù)超過99時,顯示'fail'
n<="01";
end if;
end if;
else --走法錯誤
n<="01"; --狀態(tài)為失敗
count1:=count1; --計數(shù)器不變
count2:=count2;
end if;
end if;
end if;
case count1 is --十位數(shù)字
when"0000"=>u<="1111110";
when"0001"=>u<="0110000";
when"0010"=>u<="1101101";
when"0011"=>u<="1111001";
when"0100"=>u<="0110011";
when"0101"=>u<="1011011";
when"0110"=>u<="1011111";
when"0111"=>u<="1110000";
when"1000"=>u<="1111111";
when"1001"=>u<="1111011";
when others=>u<="0000000";
end case;
case count2 is --個位數(shù)字
when"0000"=>v<="1111110";
when"0001"=>v<="0110000";
when"0010"=>v<="1101101";
when"0011"=>v<="1111001";
when"0100"=>v<="0110011";
when"0101"=>v<="1011011";
when"0110"=>v<="1011111";
when"0111"=>v<="1110000";
when"1000"=>v<="1111111";
when"1001"=>v<="1111011";
when others=>v<="0000000";
end case;
end process;
b1<=b1_temp;
b2<=b2_temp;
a1:kongzhi port map(clk,reset,temp1,disp); --調(diào)用kongzhi
a2:display port map(n,b1_temp,temp1,b,u,v); --調(diào)用display
end;
?? 快捷鍵說明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -