📄 tingche.vhd
字号:
--此模块实现车的任意位置停放或离开,并显示剩余车位数量
library ieee;
use ieee.std_logic_1164.all;
use ieee.std_logic_unsigned.all;
use ieee.std_logic_arith.all;
entity tingche is
port(
clk : in std_logic;
hello : in std_logic;
data : in std_logic_vector(2 downto 0); --停车位的行/列值选择
hang : in std_logic;
lie : in std_logic;
jin : in std_logic;
chu : in std_logic;
sel : in std_logic_vector(2 downto 0);
q : out std_logic_vector(7 downto 0);
chewei: out std_logic_vector(6 downto 0); --停车位数目
empty : out std_logic --停车场是否为空
);
end tingche;
architecture park of tingche is
type stop is array(0 to 7) of std_logic_vector(7 downto 0); --8X8数组作为停车位
begin
process(clk)
variable tmp:stop;
variable h,l:std_logic_vector(2 downto 0);
variable h_num,l_num:integer range 0 to 7;
variable i,j:integer range 0 to 7;
variable carnum:integer range 0 to 64;
variable x:std_logic;
begin
carnum:=0;
if clk'event and clk='1' then
if x='0' then --初始化为停车场为空
tmp(0):="00000000";
tmp(1):="00000000";
tmp(2):="00000000";
tmp(3):="00000000";
tmp(4):="00000000";
tmp(5):="00000000";
tmp(6):="00000000";
tmp(7):="00000000";
x:='1';
else
if hang = '1' then
h:=data;
h_num:=conv_integer(h);
elsif lie='1' then
l:=data;
l_num:=conv_integer(l);
elsif jin='1' then --在相应位置停进一部车,点亮相应灯
tmp(l_num)(h_num):='1';
elsif chu='1' then
tmp(l_num)(h_num):='0';
end if;
case sel is --根据列选信号,输出相应列值值
when "000"=>q<=tmp(0);
when "001"=>q<=tmp(1);
when "010"=>q<=tmp(2);
when "011"=>q<=tmp(3);
when "100"=>q<=tmp(4);
when "101"=>q<=tmp(5);
when "110"=>q<=tmp(6);
when "111"=>q<=tmp(7);
when others =>null;
end case;
end if;
end if;
if hello ='1' then
tmp(0):="00000000";
tmp(1):="00000000";
tmp(2):="00000000";
tmp(3):="00000000";
tmp(4):="00000000";
tmp(5):="00000000";
tmp(6):="00000000";
tmp(7):="00000000";
h:="000";
l:="000";
h_num:=0;
l_num:=0;
end if;
L1:for i in 0 to 7 loop --记录车数
L2:for j in 0 to 7 loop
if(tmp(i)(j)='1')then
carnum:=carnum+1;
end if;
end loop L2;
end loop L1;
if(carnum = 0)then
empty<='1';
else
empty<='0';
end if;
chewei<=64-conv_std_logic_vector(carnum,7);--输出车位个数
end process;
end park;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -