查看: 2503|回复: 10
收起左侧

[已解决] vhdl 3层楼梯的程序问题

 关闭 [复制链接]
bailey53
发表于 2008-9-28 13:53:32 | 显示全部楼层 |阅读模式
library ieee;
use ieee.std_logic_1164.all;
use ieee.std_logic_unsigned.all;
use ieee.std_logic_arith.all;
entity threelift is
port(buttonclk,liftclk,reset,f1upbutton,
   f2upbutton,f2dnbutton,f3dnbutton,
   stop1button,stop2button,stop3button:in std_logic;
   fuplight,fdnlight,stoplight:buffer std_logic_vector(3 downto 1);
   position: buffer integer range 1 to 3;
   doorlight: out std_logic;
   udsig: buffer std_logic  
   );
end threelift;
architecture art of threelift is
type lift_state is
(stopon1,dooropen,doorclose,doorwait1,doorwait2,doorwait3,doorwait4,up,down,stop);
signal mylift: lift_state;
signal clearup: std_logic;
signal cleardn: std_logic;
begin
ctrlift: process(reset,liftclk)
variable pos: integer range 3 downto 1;
begin
if reset='1' then
    mylift<=stopon1;
    clearup<='0';
    cleardn<='0';
       doorlight<='1'
elsif liftclk'event and liftclk='1' then
case mylift is
   when stopon1=>   doorlight<='1';position<=1;pos:=1;mylift<=doorwait1;
   when doorwait1=> mylift<=doorwait2;
   when doorwait2=> clearup<='0';cleardn<='0';mylift<=doorwait3;
   when doorwait3=> mylift<=doorwait4;
   when doorwait4=> mylift<=doorclose;doorlight<='0';
           if udsig='0' then
           if position=3 then
              if stoplight="000" and fuplight="000" and fdnlight="000" then
                 udsig<='1'; mylift<=doorclose;
              else udsig<='1';mylift<=down;
              end if;
           elsif position=2 then
              if stoplight="000" and fuplight="000" and fdnlight="000" then
                 udsig<='0'; mylift<=doorclose;
              elsif stoplight(3)='1' or (stoplight(3)='0' and fdnlight(3)='1') then
                 udsig<='0'; mylift<=up;
              else udsig<='1'; mylift<=down;
              end if;
           elsif position=1 then
              if stoplight="000" and fuplight="000" and fdnlight="000" then
                 udsig<='0'; mylift<=doorclose;
              else udsig<='0';mylift<=up;
              end if;
              else null;
           end if;
       elsif udsig='1' then
           if position=1 then
              if stoplight="000" and fuplight="000" and fdnlight="000" then
                 udsig<='0'; mylift<=doorclose;
              else udsig<='0';mylift<=up;
              end if;
           elsif position=2 then
              if stoplight="000" and fuplight="000" and fdnlight="000" then
                 udsig<='1'; mylift<=doorclose;
              elsif stoplight(1)='1' or(stoplight(1)='0' and fdnlight(1)='1') then
                 udsig<='1'; mylift<=down;
              else udsig<='0'; mylift<=up;
              end if;
           elsif position=3 then
              if stoplight="000" and fuplight="000" and fdnlight="000"then
                 udsig<='1'; mylift<=doorclose;
              else udsig<='1'; mylift<=down;
              end if;
              else
           end if;
           else
     end if;
   when up=> position<=position+1; pos:=pos+1;
        if pos<3 and (stoplight(pos)='1' or fdnlight(pos)='1') then
              mylift<=stop;
        elsif pos=3 and (stoplight(pos)='1' or fdnlight(pos)='1') then
              mylift<=stop;
        else mylift<=doorclose;
        end if;
   when down=> position<=position-1; pos:=pos-1;
        if pos>1 and(stoplight(pos)='1' or fdnlight(pos)='1')then
              mylift<=stop;
           else mylift<=doorclose;
           end if;
   when stop=> mylift<=dooropen;
   when dooropen=> doorlight<='1';
           if udsig='0' then
           if position<=2 and (stoplight(position)='1' or fdnlight(position)='1') then
            clearup<='1';
           else clearup<='1';cleardn<='1';
           end if;
        elsif udsig='1' then
           if position>=2 and (stoplight(position)='1' or fdnlight(position)='1') then
             cleardn<='1';
           else clearup<='1';cleardn<='1';
           end if;
           else
        end if;
       mylift<=doorwait1;
    when others=> null;
end case;
else
end if;
end process ctrlift;
ctrlight: process(reset,buttonclk,cleardn,stop1button)
begin
if reset='1' then
    stoplight<="000";fuplight<="000";fdnlight<="000";
elsif buttonclk'event and buttonclk='1' then
    if clearup='1' then
     stoplight(position)<='0';fuplight(position)<='0';
    else
     if f1upbutton='1'then fuplight(1)<='1';
     elsif f2upbutton='1' then fuplight(2)<='1';
        else
            null;
        end if;
    end if;

    if cleardn='1' then   
      stoplight(position)<='0';fuplight(position)<='0';
    else
      if f2dnbutton='1' then fdnlight(2)<='1';
      elsif f3dnbutton='1' then fdnlight(3)<='1';
         else
      end if;
    end if;
    if stop1button='1' then
          stoplight(1)<='1';
    elsif stop2button='1' then
          stoplight(2)<='1';
    elsif stop3button='1' then
          stoplight(3)<='1';
       else
    end if;
   
     end if;
end process ctrlight;
end art;

这是我写的程序 不过不能实现功能 希望大家帮忙改一下啊 谢谢 。。。大侠帮忙啊~~~~~  
PS:要不谁给我个新的程序也行啊 急!急!急! 在线===
skylzf
发表于 2008-9-28 14:11:08 | 显示全部楼层
偶没有接触过VHDL语言,帮楼主顶一下。
期待高手,楼主能否说明白实现什么功能。
PS:(感觉像电梯开关设计)。

[ 本帖最后由 skylzf 于 2008-9-28 14:19 编辑 ]
bailey53
 楼主| 发表于 2008-9-28 14:18:34 | 显示全部楼层
恩  是啊  就是3层电梯的设计啊
施老2005
发表于 2008-9-28 14:26:21 | 显示全部楼层
不太懂,顶起。希望强人解答。
skylzf
发表于 2008-9-28 14:44:33 | 显示全部楼层
给楼主找到一个程序,试试看:

我这里没有相关软件,打不开。楼主看看行不。
要不行的话先跟你说声抱歉了。
还有一个是现编的代码,记事本能够打开。
不知道行不行:

[ 本帖最后由 skylzf 于 2008-9-28 14:53 编辑 ]

本帖子中包含更多资源

您需要 登录 才可以下载或查看,没有帐号?快速注册

x
bailey53
 楼主| 发表于 2008-9-28 18:31:27 | 显示全部楼层
谢谢啦   我看看  再一次感谢啊 ~~~~
伊の星
发表于 2008-9-28 18:32:56 | 显示全部楼层
看来语言还是挺兼容的
在语句功能理解上
bailey53
 楼主| 发表于 2008-9-28 18:35:13 | 显示全部楼层
嘿嘿 其实也没什么啊  主要是这个程序有问题 分类不明确 也就是说有交集啊  希望高人指点吧
arccosx
发表于 2008-9-28 18:40:15 | 显示全部楼层
晕,楼主你怎么不到EDACN上面去问?
arccosx
发表于 2008-9-28 18:42:00 | 显示全部楼层
还有就是你要给别人看你的代码,最好注释一下,不然这个样子的代码,格式又不规范,别人很难理解。
您需要登录后才可以回帖 登录 | 快速注册

本版积分规则

手机版|杀毒软件|软件论坛| 卡饭论坛

Copyright © KaFan  KaFan.cn All Rights Reserved.

Powered by Discuz! X3.4( 沪ICP备2020031077号-2 ) GMT+8, 2026-10-21 18:17 , Processed in 0.091371 second(s), 2 queries , Redis On.

卡饭网所发布的一切软件、样本、工具、文章等仅限用于学习和研究,不得将上述内容用于商业或者其他非法用途,否则产生的一切后果自负,本站信息来自网络,版权争议问题与本站无关,您必须在下载后的24小时之内从您的电脑中彻底删除上述信息,如有问题请通过邮件与我们联系。

快速回复 客服 返回顶部 返回列表