排队电路设计代码(EDA)

排队电路设计(EDA)
内容及要求
单窗口排队机电路,给每个新来者编号,并计算队伍长度。
(1)进队、离队两个信号作为输入,当前服务号码队长各由4个数码管显示;
(2)初始时队长0,进队号码由1顺序递增,输出编号;
(3)有人入队,长度加,有人离队长度减;
(4)工作时钟适当即可;
(5)完成全部流程:设计规范文档、模块设计、代码输入、功能仿真、约束与综合、布局布线、时序仿真、下载验证等。代码如下:
library ieee;
  use ieee.std_logic_1164.all;
  use ieee.std_logic_arith.all;
  use ieee.std_logic_unsigned.all;
  entity count is
    port(rst,clk:in std_logic;
        selbit:out std_logic_vector(7 downto 0);  --位选数码管
        signal sel:std_logic_vector(2 downto 0);
        jin,chu:in std_logic;  --jin为进队信号,chu为出队信号
        lednum:out std_logic_vector(6 downto 0));  ---输出显示
  end count;
  architecture behav of count is
  signal num_ll,num_lh,num_hl,num_hh:std_logic_vector(3 downto 0);                            -----定义新来者编号
  signal cus_ll,cus_lh,cus_hl,cus_hh:std_logic_vector(3 downto 0);
                                    ----定义当前服务号码
  signal length_ll,length_lh,length_hl,length_hh:std_logic_vector(3 downto 0);                              ---定义队伍长度
  signal tmpbcdnum:std_logic_vector(3 downto 0);
  signal cnt4:integer range 0 to 10 ;       
  signal sel:std_logic_vector(2 downto 0);
  signal cnt10:std_logic_vector(11 downto 0);
  signal tmpclk:std_logic;
  begin
  p1:process(clk,rst,jin)      (输入代码)
  begin
    I f rst='1' then
    num_ll<="0000";num_lh<="0000";num_hl<="0000";num_hh<="0000";                              ------复位信号则全部清零
    elsif clk'event and clk='1' then  ---时钟上升沿到来且有进队
                if jin='1' then
                    num_ll<=num_ll+1;
                if num_ll<"1001" then  num_ll<=num_ll+1; 10
              elsif num_lh<"1001" then    num_lh<=num_lh+1;num_ll<="0000";
              elsif num_hl<"1001" then      num_hl<=num_hl+1;num_lh<="0000";
              elsif num_hh<"1001" then num_hh<=num_hh+1;num_hl<="0000";
              elsif (num_ll<="1001" and num_lh<="1001" and num_hl<="1001" and num_hh<="1001") then
                          num_ll<="0000";num_lh<="0000";num_hl<="0000";num_hh<="0000";  ----计数,从0000计到9999,再从0000循环;
                end if;
              end if;
    end if;
end process p1;
p2:process(rst,clk,dout)
  begin
    if rst='1' then cus_ll<="0000";cus_lh<="0000";cus_hl<="0000";cus_hh<="0000";
    elsif clk'event and clk='1' then
              if chu='1'  then
                      cus_ll<=cus_ll+1;
                    if cus_ll<"1001" then cus_ll<=cus_ll+1;
                    elsif cus_lh<"1001" then cus_lh<=cus_lh+1;cus_ll<="0000";
                    elsif cus_hl<"1001" then cus_hl<=cus_hl+1;cus_lh<="0000";
                    elsif cus_hh<"1001" then cus_hh<=cus_hh+1;cus_hl<="0000";
                    elsif (cus_ll<="1001" and cus_lh<="1001" and cus_hl<="1001" and cus_hh<="1001") then
                          cus_ll<="0000";cus_lh<="0000";cus_hl<="0000";cus_hh<="0000";
            end if; ----当前服务号码的变化类似于新来者编号
            end if;
        end if;
end process p2;
p3:process(rst,tmpclk)
  begin
      if rst='1' then cnt4<=0;
      elsif tmpclk'event and tmpclk='1' then
            if cnt4<8 then cnt4<=cnt4+1;   
            else cnt4<=0;
            end if;        -----计数,为后边扫描信号做准备
      end if;
end process p3;
free_counter:block
    signal q:std_logic_vector(24 downto 0);
  begin
    p4:process(clk,rst)
      begin
      if rst='0' then q<=(OTHERS=>'0');
      elsif clk'event and clk='1' then
        q<=q+1;
      end if;
    end process p4;
    selout<=sel;       
      sel<="000" when cnt4=0 else
      "001" when cnt4=1 else
      "010" when cnt4=2 else
      "011" when cnt4=3 else
      "100" when cnt4=4 else
      "101" when cnt4=5 else
      "110" when cnt4=6 else
      "111" when cnt4=7 else
      "000";                    -----实现位选数码管
end block free_counter;
P5:process(rst,clk)
begin
  if rst='0' then cnt10<=0;
    elsif clk'event and clk='1' then
          cnt10<=cnt10+1; ----cnt10用来计数实现时钟分频
        else cnt10<=0;
        end if;    -----时钟分频
  end if;
end process p5;
tmpclk<=cnt10(10);
p5:process(rst,clk,chu)
  begin
  if rst='1' then length_ll<="0000";length_lh<="0000";length_hl<="0000";length_hh<="0000";
  elsif clk'event and clk='1' then
        if chu<='1' then
              length_ll<=num_ll-cus_ll;    -----减法得到队长
              length_lh<=num_lh-cus_lh; ---并将值附给相应位
              length_hl<=num_hl-cus_hl;

本文发布于:2024-09-20 21:36:48,感谢您对本站的认可!

本文链接:https://www.17tex.com/tex/2/91921.html

版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。

标签:信号   号码   编号   输入   队长   服务   新来者   时钟
留言与评论(共有 0 条评论)
   
验证码:
Copyright ©2019-2024 Comsenz Inc.Powered by © 易纺专利技术学习网 豫ICP备2022007602号 豫公网安备41160202000603 站长QQ:729038198 关于我们 投诉建议