这学期的课程实践自己写的,看到网上的VHDL电梯控制程序版本的源码都差不多,大家都是抄来抄去,有些人甚至还抄来发论文当毕业设计(搞笑)。
所以我把自己写的也发上来,供大家参考参考。嗯,就是这样。
首先是电梯控制的流程图:
接下来源码:
LIBRARY ieee;
USE ieee.std_logic_1164.all;
USE IEEE.STD_LOGIC_UNSIGNED.ALL;
ENTITY myLIFT IS
PORT(out_up1,out_up2,out_up3,out_up4,out_up5: IN STD_LOGIC;--represent outside up button
out_down2,out_down3,out_down4,out_down5,out_down6: IN STD_LOGIC;--represent outside down button
in_request: IN STD_LOGIC_VECTOR(5 DOWNTO 0);--represent inside button
open_door: IN STD_LOGIC; --open door button
close_door: IN STD_LOGIC; --close door button
reset: IN STD_LOGIC; --reset button
clk: IN STD_LOGIC; --1hz
floor_num: OUT STD_LOGIC_VECTOR(0 TO 6);--show where the elevator is
floor_dirstatus: OUT STD_LOGIC_VECTOR(0 TO 6);--0 represent stop, 1 rep down, 2 rep up
out_up_light: OUT STD_LOGIC_VECTOR(4 DOWNTO 0);--show the elevator direction
out_down_light: OUT STD_LOGIC_VECTOR(4 DOWNTO 0);--show the elevator direction
in_req_light: OUT STD_LOGIC_VECTOR(5 DOWNTO 0);--show which floor is requesting
testkey: OUT STD_LOGIC_VECTOR(3 DOWNTO 0) --ignore it ,just for test
);
END myLIFT;
ARCHITECTURE bev OF myLIFT IS
TYPE floor_state IS (f1, f2, f3, f4, f5, f6);
SIGNAL floor: floor_state;
SIGNAL elevator_dir: INTEGER RANGE 0 TO 2;
SIGNAL req_floor: STD_LOGIC_VECTOR(5 DOWNTO 0);
SIGNAL out_up: STD_LOGIC_VECTOR(5 DOWNTO 0);
SIGNAL out_down: STD_LOGIC_VECTOR(5 DOWNTO 0);
SIGNAL counter: STD_LOGIC_VECTOR(1 DOWNTO 0);
SIGNAL door_state: STD_LOGIC;
BEGIN
testkey(0) <= open_door;
testkey(1) <= close_door;
testkey(3) <= reset;
--door <= door_state;
PROCESS(clk,reset,open_door,close_door,in_request,out_up1,out_up2,out_up3,out_up4,out_up5,out_down2,out_down3,out_down4,out_down5,out_down6)
VARIABLE last_out_up: STD_LOGIC_VECTOR(5 DOWNTO 0):="000000";
VARIABLE last_out_down: STD_LOGIC_VECTOR(5 DOWNTO 0):="000000";
VARIABLE last_req_floor: STD_LOGIC_VECTOR(5 DOWNTO 0):="000000";
VARIABLE buttonpress: STD_LOGIC_VECTOR(5 DOWNTO 0):=in_request OR ('0' & out_up5 & out_up4 & out_up3 & out_up2 & out_up1) OR (out_down6 & out_down5 & out_down4 & out_down3 & out_down2 & '0');
BEGIN
IF (reset='1') THEN
floor<=f1;
floor_num <= "1001111";
elevator_dir<=0;
out_up <= "000000";
out_down <= "000000";
req_floor <= "000000";
counter <= "00";
door_state <= '0';
ELSIF (buttonpress>"000000") THEN
last_out_up := out_up;
last_out_down := out_down;
last_req_floor := req_floor;
out_up <= last_out_up OR ('0' & out_up5 & out_up4 & out_up3 & out_up2 & out_up1);
out_down <= last_out_down OR (out_down6 & out_down5 & out_down4 & out_down3 & out_down2 & '0');
req_floor <= last_req_floor OR in_request;
ELSIF (open_door = '1') THEN
counter <= "00"; --door open time is recounted from 0
ELSIF (close_door = '1') THEN
counter <= "11";
--door_state <= '0';
ELSIF (CLK'EVENT AND CLK='1') THEN
IF (door_state='1') THEN --open time: 5s
counter <= cou