?? state_graph.vhd
字號:
library ieee;
use ieee.std_logic_1164.all;
entity state_graph is
port(
st:in std_logic;
--連接到外部輸入信號,st=‘1’表示命令開始運算
clk:in std_logic;
--連接時鐘輸入信號
overflow:out std_logic;
--連接到外部輸出信號,overflow=‘1’表示溢出
load:out std_logic;
--輸出信號,控制mux18_9
c:in std_logic;
--輸入信號,由diag_c模塊產(chǎn)生。只在狀態(tài)1時使用,從而決定這個除法是否溢出。
diag,su_en, sh_en:out std_logic;
--這四個輸出信號是在外部時鐘的上升沿時產(chǎn)生的,且是順序產(chǎn)生的。它們的作用是使判斷、相減和移位按順序執(zhí)行。
isover:out std_logic);
--通知外部,整個除法運算進行完,取出商和余數(shù)
end state_graph;
architecture behavioral of state_graph is
signal state :integer range 0 to 5;
--表示狀態(tài),狀態(tài)0,1,2 ,3,4,5
signal input:std_logic;
--內(nèi)部信號送到移位寄存器srg,作用:輸入為1時新的狀態(tài)開始
signal update:std_logic;
--表示一個狀態(tài)的結(jié)束,在時鐘上升沿的到來進入下個狀態(tài)
component srg4
--移位寄存器srg的聲明。
port(clk:in std_logic;
input:in std_logic;
diag,su_en,sh_en,update:out std_logic);
end component;
begin
state_m:process(clk,state,st,c,update)
begin
if clk'event and clk='1' then
--時鐘上升沿執(zhí)行狀態(tài)的轉(zhuǎn)換
case state is
when 0=>
if(st='1') then load<='1';state<=1;input<='1';
else state<=0;input<='0';
end if;
--狀態(tài)0,st=‘1’時開始進入下個狀態(tài)
when 1=>isover<='0';load<='0';
if(c='1')then state<=0;overflow<='1';
end if;
if(c='0') then
if update='1' then state<=2;input<='1';else state<=1;input<='0'; end if;
end if;
--狀態(tài)1,只有在update=‘1’才進入狀態(tài)2。
when 2|3|4=>isover<='0';load<='0';
if update='1' then state<=state+1;input<='1';else input<='0';end if;
--狀態(tài)2,3,4,
when 5=>load<='0';
if update='1' then input<='0';isover<='1';state<=0;else input<='0';isover<='0';end if;
--狀態(tài)5
when others =>null;
end case;
end if;
end process state_m;
u1:srg4 port map(clk,input,diag,su_en,sh_en,update);
--口映射srg, 它的作用是規(guī)定比較、相減和移位的時間順序,還有狀態(tài)的改變不能相減的前面。
end behavioral;
?? 快捷鍵說明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -