⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 speed.vhd

📁 FPGA VHDL 语言的的士计费系统!与现有的的士计费系统功能一样。
💻 VHD
字号:
library ieee;
use ieee.std_logic_1164.all;
use ieee.std_logic_unsigned.all;

entity speed is  --计费表实体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                              --结构体a
signal kilo: std_logic;  --满一公理的标致
signal mint: std_logic;  --满一分钟的标致
signal stance_1 : integer range 999 downto 0; --路程1(km)
signal time: integer range 999 downto 0;  --等待时间
signal aq:integer range 999 downto 0;
begin

process(clk_sp,start)   --路程计数                           --进程1
variable q1: integer range 999 downto 0; 
begin
    --计数开始
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)  --监视kilo变化  算出路程stance_1           -进程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)  --等待计时                         --进程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)   --监视mint变化 算出等待时间time          --进程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)   --最终结果                             --进程5
begin

if clk_1s'event and clk_1s='1' then

   if push='0' and time=0 then    --不停车时的算法
             if stance_1<3 then
                money<= 5;
             else money<=(stance_1-2)*2+5;
             end if;
   else                  --等待时的算法
             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;

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -