龙芯

龙芯

0个粉丝

18

问答

0

专栏

1

资料

龙芯  发布于  2008-10-02 20:52:33
采纳率 0%
18个问答
5410

自动售货机VHDL程序与仿真

 
货物信息存储,进程控制,硬币处理,余额计算,显示等功能。
library ieee;
use ieee.std_logic_arith.all;
use ieee.std_logic_1164.all;
use ieee.std_logic_unsigned.all;
entity PL_auto1 is
port ( clk:in std_logic;                              --系统时钟
set,get,sel,finish: in std_logic;                   --设定、买、选择、完成信号
coin0,coin1: in std_logic;                      --5角硬币、1元硬币
price,quantity  :in std_logic_vector(3 downto 0);   --价格、数量数据
item0 , act:out std_logic_vector(3 downto 0);       --显示、开关信号
y0,y1 :out std_logic_vector(6 downto 0);          --钱数、商品数量显示数据
act10,act5   :out std_logic);                   --1元硬币、5角硬币
end PL_auto1;
architecture behav of PL_auto1 is
type  ram_type is array(3 downto 0)of std_logic_vector(7 downto 0);
signal ram :ram_type;                                      --定义RAM
signal item: std_logic_vector(1 downto 0);                      --商品种类
signal coin: std_logic_vector(3 downto 0);                      --币数计数器
signal pri,qua:std_logic_vector(3 downto 0);                    --商品单价、数量
signal clk1: std_logic;                                      --控制系统的时钟信号
begin
com:process(set,clk1)
variable quan:std_logic_vector(3 downto 0);
begin
  if set='1' then ram(conv_integer(item))<=price & quantity;act<="0000";
--把商品的单价、数量置入到RAM
  elsif clk1'event and clk1='1' then  act5<='0'; act10<='0';
      if coin0='1' then     
             if coin<"1001"then coin<=coin+1;            --投入5角硬币,coin自加1
                 else coin<="0000";
                 end if;
      elsif coin1='1' then
                 if coin<"1001"then coin<=coin+2;            --投入1元硬币,coin自加2
                 else coin<="0000";
                 end if;
      elsif sel='1' then item<=item+1;                  --对商品进行循环选择
elsif get='1' then                              --对商品进行购买
if qua>"0000" and coin>=pri then coin<=coin-pri;quan:=quan-1;
ram(conv_integer(item))<=pri & quan;
            if   item="00" then act<="1000";  --购买时,自动售货机对4种商品的操作
                        elsif item="01" then act<="0100";
                    elsif item="10" then act<="0010";
                    elsif item="11" then act<="0001";
                        end if;
                end if;
      elsif  finish='1' then                            --结束交易,退币(找币)
         if coin>"0001" then act10<='1';coin<=coin-2;     --此IF语句完成找币操作
         elsif coin>"0000" then act5<='1'; coin<=coin-1;
         else act5<='0'; act10<='0';
         end if;
      elsif get='0' then act<="0000";                  
         for i in 4 to 7 loop                    
         pri(i-4)<=ram (conv_integer(item))(i);           --商品单价的读取
         end loop;
         for i in 0 to 3 loop
         quan(i):=ram(conv_integer(item))(i);            --商品数量的读取
         end loop;
      end if;
  end if;
qua<=quan;
end process com;

m32:process(clk)                            --此进程完成对32Mhz的脉冲分频
variable q: std_logic_vector( 24 downto 0);
begin
   if clk'event and clk='1' then q:=q+1;
   end if;
   if q="111111111111111111111111" then clk1<='1';
   else clk1<='0';
   end if;
end process m32;

code0:process(item)                          --商品指示灯译码
begin
case item is
when "00"=>item0<="0111";
when "01"=>item0<="1011";
when "10"=>item0<="1101";
when others=>item0<="1110";
end case;
end process;

code1: process (coin)                       --钱数的BCD到七段码的译码
begin
  case coin is
      when "0000"=>y0<="0000001";
      when "0001"=>y0<="1001111";
      when "0010"=>y0<="0010010";
      when "0011"=>y0<="0000110";
      when "0100"=>y0<="1001100";
      when "0101"=>y0<="0100100";
      when "0110"=>y0<="0100000";
      when "0111"=>y0<="0001111";
      when "1000"=>y0<="0000000";
      when "1001"=>y0<="0000100";
      when others=>y0<="1111111";
  end case;
end process;

code2: process (qua)                       --单价的BCD到七段码的译码
begin
  case qua is
      when "0000"=>y1<="0000001";
      when "0001"=>y1<="1001111";
      when "0010"=>y1<="0010010";
      when "0011"=>y1<="0000110";
      when "0100"=>y1<="1001100";
      when "0101"=>y1<="0100100";
      when "0110"=>y1<="0100000";
      when "0111"=>y1<="0001111";
      when "1000"=>y1<="0000000";
      when "1001"=>y1<="0000100";
      when others=>y1<="1111111";
  end case;
end process;
end behav;
(2)程序仿真

注:仿真图里没有对clk信号进行分频处理。
图 8.21.2 系统仿真全图

图 8.21.3 系统仿真图-预置部分
图 21.4 系统仿真图-商品种类选择部分
2图 8.21.5 系统仿真图-投币部分

图 8.21.6 系统仿真图-购买、找币结束交易部分
我来回答
回答2个
时间排序
认可量排序

hrx2018

0个粉丝

8

问答

0

专栏

0

资料

hrx2018 2013-11-24 22:07:20
认可0
抢2楼,首先要网速快,宽带4兆起步。
您要是手机党,谢了您呐,您歇会儿,这儿没您什么事儿。
其次是耐力,手不离F5,在贴吧高峰时期,平均每3秒一下,您键盘要是塑料的您也别出来,两天就得按坏了。
还有就是要眼明手快,看到0回复马上点开,粘贴、发表、顶要一气呵成,这就像玩街机,要各个方向键配合,才能发出大招。
最后要有坚强的抗压能力,总会有某个比你还闲的蛋疼的家伙和你抢,这时候要跟丫死磕看谁更闲的蛋疼。就是这么快!最后站起来整理一下衣角,笑而不语。在哥的面前一切都是浮云,哥的足迹将踏遍二楼!留给你们一个潇洒蛋疼的背影!

david

9个粉丝

36

问答

24

专栏

58

资料

david 2013-07-01 14:13:31
认可0
:):):):):):):):):)
或将文件直接拖到这里
悬赏:
E币
网盘
* 网盘链接:
* 提取码:
悬赏:
E币

Markdown 语法

  • 加粗**内容**
  • 斜体*内容*
  • 删除线~~内容~~
  • 引用> 引用内容
  • 代码`代码`
  • 代码块```编程语言↵代码```
  • 链接[链接标题](url)
  • 无序列表- 内容
  • 有序列表1. 内容
  • 缩进内容
  • 图片![alt](url)
+ 添加网盘链接/附件

Markdown 语法

  • 加粗**内容**
  • 斜体*内容*
  • 删除线~~内容~~
  • 引用> 引用内容
  • 代码`代码`
  • 代码块```编程语言↵代码```
  • 链接[链接标题](url)
  • 无序列表- 内容
  • 有序列表1. 内容
  • 缩进内容
  • 图片![alt](url)
举报反馈

举报类型

  • 内容涉黄/赌/毒
  • 内容侵权/抄袭
  • 政治相关
  • 涉嫌广告
  • 侮辱谩骂
  • 其他

详细说明

易百纳技术社区