导航: 老古网老古论坛XMOS公共讨论区XMOS开源项目区单片机程序设计嵌入式系统广告区域
→请高手帮我个忙,关与VHDL语言的。[mmaatybz]

 *第38044篇: 请高手帮我个忙,关与VHDL语言的。

  
楼 主:mmaatybz 2006年2月27日21:17
 请高手帮我个忙,关与VHDL语言的。
我是不懂的,帮一个朋友发的
下面是一段交通灯的控制程序,里面要加一个计数器可以从1到50记数,请各位大虾帮忙。谢谢了

library ieee;
use ieee.std_logic_1164.all; 
use ieee.std_logic_arith.all; 
entity light is
port(clk,clr,set_red:in std_logic;
  a_green,a_yellow,a_red:out std_logic;
  b_green,b_yellow,b_red:out std_logic);
end light;
architecture rtl of light is
type state is(agreen,ayellow,bgreen,byellow,alarm);
--begin
signal current_state,next_state:state;
signal timer:integer;
signal light:std_logic_vector(5 downto 0);
signal flag:std_logic;
begin
process(clk,clr,set_red)
 begin
 if(clr='1')then
  current_state   <= agreen;
  --timer   <= 50;
  flag   <='0';
 --elsif(set_red='1')then 
  --current_state  <= alarm;
  --timer  <=timer;
  --flag  <='1';
  --light  <="001001" ;
 elsif(clk'event and clk='1')then
  flag  <='0';
  --timer  <=timer-1;
  --if(timer=timer-1)
  current_state  <= next_state;
 end if;
end process;

process(current_state,set_red)
 begin
 case current_state is
  when agreen=>  
   if(timer=0)then
    next_state  <=ayellow;
    timer  <=5;
   end if;
  when ayellow =>  
   if(timer=0)then
    next_state  <=bgreen;
    timer  <=50;
   end if;
  when bgreen=>  
   if(timer=0)then
    next_state  <=byellow;
    timer  <=5;
   end if;
  when byellow=>  
   if(timer=0)then
    next_state  <=agreen;
    timer  <=50;
   end if;
        when alarm=>  
    if(timer=0)then
                next_state  <=alarm;
   end if;
 end case;
end process;

process(current_state)
 --if(flag='0')then
begin
 case current_state is
  when agreen =>  light  <="100001";
  when ayellow =>  light  <="010001";
  when bgreen =>  light  <="001100";
  when byellow =>  light  <="001010";
  when alarm =>  light  <="001001";
 end case;
 --end if;
 a_green  <=light(5);
 a_yellow  <=light(4);
 a_red  <=light(3);
 b_green  <=light(2);
 b_yellow  <=light(1);
 b_red  <=light(0);
end process;
end rtl;

  
2楼:mmaatybz 2006年3月1日18:48
 基与VHDL语言的交通灯控制系统。
大吓 等着急用啊。

>>>>>>对该主题发表你的看法

本主题贴数2,分页: [第1页]


[上一篇主题]:字段式液晶显示怎样使用

[下一篇主题]:请问各位,谁由KEILC编译器的完整版,能给我一份吗