?? speed.vhd
字號:
library ieee;
use ieee.std_logic_1164.all;
use ieee.std_logic_unsigned.all;
entity speed is --計(jì)費(fèi)表實(shí)體speed
port (start: in std_logic; --開始/停止 按扭
push: in std_logic; --等待按扭
clk_1s: in std_logic; --秒信號
clk_sp:in std_logic; --速度脈沖
stance : out integer range 999 downto 0; --路程
money : out integer range 999 downto 0 --金額
);
end;
architecture a of speed is --結(jié)構(gòu)體a
signal kilo: std_logic; --滿一公理的標(biāo)致
signal mint: std_logic; --滿一分鐘的標(biāo)致
signal stance_1 : integer range 999 downto 0; --路程1(km)
signal time: integer range 999 downto 0; --等待時(shí)間
signal aq:integer range 999 downto 0;
begin
process(clk_sp,start) --路程計(jì)數(shù) --進(jìn)程1
variable q1: integer range 999 downto 0;
begin
--計(jì)數(shù)開始
if start='0' then
q1:=0;
elsif clk_sp'event and clk_sp='1' then
if push='0' then
if q1<999 then
q1:=q1+1;
kilo<='0';
else q1:=0; kilo<='1';
end if;
end if;
end if;
end process;
process(kilo,clk_1s,start) --監(jiān)視kilo變化 算出路程stance_1 -進(jìn)程2
variable q3: integer range 999 downto 0;
begin
if start='0' then
q3:=0;
elsif kilo'event and kilo='1' then
if push='0' then
if q3<999 then
q3:=q3+1;
else q3:=0;
end if;
end if;
end if;
stance_1<=q3;
end process;
process(clk_1s,push,start) --等待計(jì)時(shí) --進(jìn)程3
variable q2: integer range 59 downto 0;
begin
if start='0' then
q2:=0;
elsif clk_1s'event and clk_1s='1' and push='1' then
if q2<59 then
q2:=q2+1; mint<='0';
else q2:=0; mint<='1';
end if;
end if;
end process;
process(mint,clk_1s,start) --監(jiān)視mint變化 算出等待時(shí)間time --進(jìn)程4
begin
if start='0' then
time<=0;
elsif mint'event and mint='1' then
if time<999 then
time<=time+1;
else time<=0;
end if;
end if;
end process;
process(clk_1s) --最終結(jié)果 --進(jìn)程5
begin
if clk_1s'event and clk_1s='1' then
if push='0' and time=0 then --不停車時(shí)的算法
if stance_1<3 then
money<= 5;
else money<=(stance_1-2)*2+5;
end if;
else --等待時(shí)的算法
if stance_1<3 then
money<= 5+time+1;
else money<=(stance_1-2)*2+time+1+5;
end if;
end if;
stance<=stance_1+1;
end if;
end process;
end a;
?? 快捷鍵說明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -