基于DE2的VHDL六层电梯控制程序设计

该篇博客分享了一位学生基于DE2开发板使用VHDL语言编写的六层电梯控制程序。作者指出网络上类似源码重复,希望通过分享自己的实践代码提供新的参考。博客包含电梯控制流程图及详细源码。
摘要由CSDN通过智能技术生成

这学期的课程实践自己写的,看到网上的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
评论 4
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值