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

📄 bankorder.vhd

📁 银行排队系统的VHDL程序实现
💻 VHD
字号:
LIBRARY IEEE;
USE IEEE.STD_LOGIC_1164.ALL;
--USE IEEE.STD_LOGIC_UNSIGNED.ALL;

ENTITY bankorder IS
 PORT(CLK,CLR,C1:IN STD_LOGIC;
               S:IN STD_LOGIC_VECTOR(4 DOWNTO 1);
          LEDNUM:OUT integer range 0 to 15;         
          SELBIT:OUT STD_LOGIC_VECTOR(7 DOWNTO 0));
END bankorder;

ARCHITECTURE RTL OF bankorder IS

signal       waitnum0,waitnum1:integer range 0 to 9;    --等待人数
signal               workernum:integer range 0 to 9;   --银行工作柜台编号
signal         curnum0,curnum1:integer range 0 to 9;   --顾客取号编号
signal         sernum0,sernum1:integer range 0 to 9;    --当前接收服务的顾客编号
signal          CLKX:STD_LOGIC :='0';                          --clk经1000分频后占空比为1:1的时钟信号
constant        datazero :integer :=0;
--constant        data10 :integer :=10;
constant        data15 :integer :=15;

BEGIN
P1:PROCESS(clk,clr,C1,S)   --C1控制等待人数及顾客取号编号的变化,clr控制系统的复位
  variable flagc:bit :='0'; --结合C1判断是否为其上升沿
  variable flagf:bit_vector(4 downto 1) :="0000";  --结合银行柜台按钮S判断是否为其上升沿
  variable tmpwait0,tmpwait1:integer range 0 to 9;    --等待人数
  variable         tmpworker:integer range 0 to 9;   --银行工作柜台编号
  variable   tmpcur0,tmpcur1:integer range 0 to 9;   --顾客取号编号
  variable   tmpser0,tmpser1:integer range 0 to 9;    --当前接收服务的顾客编号
begin
  if(clr='1')then
    tmpworker:=0;  
    tmpcur0:=0;    tmpcur1:=0;
    tmpser0:=0;    tmpser1:=0;    
    tmpwait0:=0;   tmpwait1:=0;    
    flagc:='0';    flagf:="0000";
  elsif(clk'event and clk='1')then
    if(C1='1'and flagc='0')then
       if(tmpcur0<9)then
         tmpcur0:=tmpcur0+1;
       else
         tmpcur0:=0; 
         tmpcur1:=tmpcur1+1;               
       end if;
       if(tmpwait0<9)then
         tmpwait0:=tmpwait0+1;
       else
         tmpwait0:=0; 
         tmpwait1:=tmpwait1+1;               
       end if;
       flagc:='1';
    elsif(C1='0')then
       flagc:='0';
    end if;
    if(tmpcur0=9 and tmpcur1=9)then
      tmpcur0:=0;
      tmpcur1:=0;      
    end if;
    if(tmpwait0=9 and tmpwait1=9)then
      tmpwait0:=0;
      tmpwait1:=0;      
    end if;    
    if(S(4)='1'and flagf(4)='0')then
       tmpworker:=4;
       if(tmpser0<9)then
         tmpser0:=tmpser0+1;
       else
         tmpser0:=0;       
         tmpser1:=tmpser1+1;
       end if;       
       if(tmpwait0>0)then
         tmpwait0:=tmpwait0-1;
       elsif(tmpwait0=0 and tmpwait1>0)then
         tmpwait0:=9;         
         tmpwait1:=tmpwait1-1;                  
       else
         tmpwait0:=0;         
         tmpwait1:=0;                  
       end if;          
       flagf(4):='1';
    elsif(S(3)='1'and flagf(3)='0')then
       tmpworker:=3;
       if(tmpser0<9)then
         tmpser0:=tmpser0+1;
       else
         tmpser0:=0;       
         tmpser1:=tmpser1+1;
       end if;       
       if(tmpwait0>0)then
         tmpwait0:=tmpwait0-1;
       elsif(tmpwait0=0 and tmpwait1>0)then
         tmpwait0:=9;         
         tmpwait1:=tmpwait1-1;                  
       else
         tmpwait0:=0;         
         tmpwait1:=0;                  
       end if; 
       flagf(3):='1';
    elsif(S(2)='1'and flagf(2)='0')then
       tmpworker:=2;    
       if(tmpser0<9)then
         tmpser0:=tmpser0+1;
       else
         tmpser0:=0;       
         tmpser1:=tmpser1+1;
       end if;       
       if(tmpwait0>0)then
         tmpwait0:=tmpwait0-1;
       elsif(tmpwait0=0 and tmpwait1>0)then
         tmpwait0:=9;         
         tmpwait1:=tmpwait1-1;                  
       else
         tmpwait0:=0;         
         tmpwait1:=0;                  
       end if; 
       flagf(2):='1';
    elsif(S(1)='1'and flagf(1)='0')then
       tmpworker:=1;    
       if(tmpser0<9)then
         tmpser0:=tmpser0+1;
       else
         tmpser0:=0;       
         tmpser1:=tmpser1+1;
       end if;       
       if(tmpwait0>0)then
         tmpwait0:=tmpwait0-1;
       elsif(tmpwait0=0 and tmpwait1>0)then
         tmpwait0:=9;         
         tmpwait1:=tmpwait1-1;                  
       else
         tmpwait0:=0;         
         tmpwait1:=0;                  
       end if; 
       flagf(1):='1';
    else
       NULL;
    end if;
    if(S(4)='0')THEN
       flagf(4):='0';
    END IF;
    if(S(3)='0')THEN
       flagf(3):='0';
    END IF;
    if(S(2)='0')THEN
       flagf(2):='0';
    END IF;
    if(S(1)='0')THEN
       flagf(1):='0';
    END IF;
    if(tmpser0=9 and tmpser1=9)then
      tmpser0:=0;
      tmpser1:=0;      
    end if;  
    if(tmpwait0=0 and tmpwait1=0)then
      NULL;    
      NULL;      
    end if;        
  end if;
  workernum<=tmpworker;
  waitnum0<=tmpwait0;   waitnum1<=tmpwait1;
  curnum0<=tmpcur0;     curnum1<=tmpcur1;   
  sernum0<=tmpser0;     sernum1<=tmpser1;
end process P1;


--因容量问题,此分频进程不被其他进程调用,只将代码置于此处
P2:PROCESS(clk,clkx)    --将时钟进行1000分频(可调),且占空比为1:1
  variable cnt3:integer range 0 to 20 :=0;
begin
  if(clk'event and clk='1')then
    if(cnt3<19)then
       cnt3:=cnt3+1;
    else
       cnt3:=0;
    end if;
    if(cnt3<10)then
       clkx<='0';
    else
       clkx<='1';
    end if;
  end if;
end process P2;

P3:PROCESS(clk)  --clkx作用下依次循环点亮各数码管,各数码管分别显示定义好的数值
  variable cnt4:integer range 0 to 10 :=0;
begin
  if(clk'event and clk='1')then
    if(cnt4<8)then
       cnt4:=cnt4+1;
    else
       cnt4:=0;
    end if;
    case cnt4 is
      when 1 =>
           selbit<="11111110";
           LEDNUM<=curnum0;  
      when 2 =>
           selbit<="11111101";
           LEDNUM<=curnum1;
      when 3 =>
           selbit<="11111011";
           LEDNUM<=waitnum0;    
      when 4 =>
           selbit<="11110111";
           LEDNUM<=waitnum1;
      when 5 =>
           selbit<="11101111";
           LEDNUM<=sernum0;
      when 6 =>
           selbit<="11011111";
           LEDNUM<=sernum1;
      when 7 =>
           selbit<="10111111";
           LEDNUM<=datazero;
      when 8 =>
           selbit<="01111111";
           LEDNUM<=workernum;
      WHEN OTHERS =>
           selbit<="11111111";
           LEDNUM<=data15;
      END CASE;
  end if;
end process P3;

END RTL;
        

⌨️ 快捷键说明

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