电梯控制器VHDL

  • 格式:doc
  • 大小:32.00 KB
  • 文档页数:3

数字逻辑与数字系统课程设计
设计题目:高层电梯自动控制系统
年级专业:
学生姓名:
学号:
合作组员:
附:
源代码:
library ieee;
use ieee.std_logic_1164.all;
use ieee.std_logic_unsigned.all;
use ieee.std_logic_arith.all;
entity dianti is
port(
clk:in std_logic; --时钟脉冲信号
clr:in std_logic; --清零复位信号
ck:in std_logic_vector(8 downto 0); --接各楼层开关
light:out std_logic; --指示灯
number:out std_logic_vector(3 downto 0) --数字显示信号);
end dianti;
architecture behavioral of dianti is
signal fn:integer range 0 to 8; --当前楼层
signal cm:integer range 0 to 8; --计数器
signal cb:integer range 0 to 1000; --分频计数器变量
begin
process(clk, clr, ck)
begin
if(clr = '0') then --初始化
fn <= 0;
cb <= 0;
number <= "0000";
cm <= 0;
elsif ( clk = '1' and clk' event) then
if(cb = 499) then
cb <= 0;
light <= '0';
if(ck(0) = '1') then
cm <= 0;
elsif(ck(1) = '1') then
cm <= 1;
elsif(ck(2) = '1') then
cm <= 2;
elsif(ck(3) = '1') then
cm <= 3;
elsif(ck(4) = '1') then
cm <= 4;
elsif(ck(5) = '1') then
cm <= 5;
elsif(ck(6) = '1') then
cm <= 6;
elsif(ck(7) = '1') then
cm <= 7;
elsif(ck(8) = '1') then
cm <= 8;
end if;
if(cm > fn) then
fn <= fn + 1;
elsif(cm < fn) then
fn <= fn - 1;
elsif(cm = fn) then
light <= '1';
end if;
if(fn = 0) then
number <= "0001";
elsif(fn = 1) then
number <= "0010";
elsif(fn = 2) then
number <= "0011";
elsif(fn = 3) then
number <= "0100";
elsif(fn = 4) then
number <= "0101";
elsif(fn = 5) then
number <= "0110";
elsif(fn = 6) then
number <= "0111";
elsif(fn = 7) then
number <= "1000";
elsif(fn = 8) then
number <= "1001";
end if;
else
cb <= cb + 1;
end if;
end if;
end process;
end behavioral;。