请尊重作者版权,转载注明源地址:http://www.cnblogs.com/connorzx/p/3694618.html

使用了状态机,增加了可读性和用户体验。

 library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
use IEEE.STD_LOGIC_ARITH.ALL;
use IEEE.STD_LOGIC_UNSIGNED.ALL;
entity main is
Port ( clk : in STD_LOGIC;
rst : in STD_LOGIC;
led : out STD_LOGIC_VECTOR ( downto );
an : out STD_LOGIC_VECTOR ( downto );
seg : out STD_LOGIC_VECTOR ( downto ));
end main; architecture Behavioral of main is
signal sclk: std_logic;
signal now_state,next_state: std_logic_vector( downto );
signal ledt: std_logic_vector( downto );
signal led_state: std_logic_vector( downto );
signal cnt0:integer:=;
signal cnt1:integer:=;
signal cnt2:integer:=;
signal disp_main:integer:=;
signal disp_branch:integer:=;
signal display:integer;
signal time_main:integer;
signal time_main_l:integer;
signal time_main_h:integer;
signal time_branch:integer;
signal time_branch_l:integer;
signal time_branch_h:integer;
signal time_long:integer:=;
constant red_time:integer:=;
constant green_time:integer:=;
constant yellow_time:integer:=;
signal an_sel: integer;
begin
led()<=led_state();
led()<=led_state();
led()<=led_state();
led()<=led_state();
led()<=led_state();
led()<=led_state();
process(clk)
begin
if(clk'event and clk='') then
if(cnt0=)then
cnt0<=;
sclk<=not sclk;
else
cnt0<=cnt0+;
end if;
end if;
end process; process(clk)
begin
if(clk'event and clk='') then
if(cnt2=) then
cnt2<=;
if(an_sel=)then
an_sel<=;
else
an_sel<=an_sel+;
end if;
else
cnt2<=cnt2+;
end if;
end if;
end process; process(now_state)
begin
case now_state is
when ""=>time_long<=green_time;ledt<="";next_state<="";
when ""=>time_long<=yellow_time;ledt<="";next_state<="";
when ""=>time_long<=green_time;ledt<="";next_state<="";
when ""=>time_long<=yellow_time;ledt<="";next_state<="";
when others=>time_long<=green_time;ledt<="";next_state<="";
end case;
end process; process(rst,sclk)
begin
if(rst='') then
now_state<="";
led_state<="";
elsif(sclk'event and sclk='') then
led_state()<=ledt();
led_state()<=ledt();
led_state()<=ledt();
led_state()<=ledt();
led_state()<=ledt();
led_state()<=ledt();
if(cnt1=time_long) then
now_state<=next_state;
cnt1<=;
else
cnt1<=cnt1+;
end if;
end if;
end process; process(sclk,led_state,rst,cnt1)
begin
if (rst='')then
disp_main<=red_time;
disp_branch<=green_time;
elsif(sclk'event and sclk='') then
if(disp_main=)then
if(led_state()='')then
disp_main<=green_time;
elsif(led_state()='')then
disp_main<=yellow_time;
elsif(led_state()='')then
disp_main<=red_time;
end if;
else
disp_main<=disp_main - ;
end if;
if(disp_branch=)then
if(led_state()='')then
disp_branch<=green_time;
elsif(led_state()='')then
disp_branch<=yellow_time;
elsif(led_state()='')then
disp_branch<=red_time;
end if;
else
disp_branch<=disp_branch - ;
end if;
end if;
end process; process(an_sel,disp_main,disp_branch)
begin
time_main<=disp_main;
if(time_main>=)then
time_main_h<=;
time_main_l<=time_main-;
else
time_main_h<=;
time_main_l<=time_main;
end if;
time_branch<=disp_branch;
if(time_branch>=)then
time_branch_h<=;
time_branch_l<=time_branch-;
else
time_branch_h<=;
time_branch_l<=time_branch;
end if;
case an_sel is
when =>an<="";display<=time_main_l;
when =>an<="";display<=time_main_h;
when =>an<="";display<=time_branch_l;
when =>an<="";display<=time_branch_h;
when others=>null;
end case;
case display is
when =>seg<=b"";
when =>seg<=b"";
when =>seg<=b"";
when =>seg<=b"";
when =>seg<=b"";
when =>seg<=b"";
when =>seg<=b"";
when =>seg<=b"";
when =>seg<=b"";
when =>seg<=b"";
when others=>null;
end case;
end process;
end Behavioral;

基于BASYS2的VHDL程序——交通灯(状态机版)的更多相关文章

  1. 基于BASYS2的VHDL程序——交通灯

    请尊重作者版权,转载请注明原地址: http://www.cnblogs.com/connorzx/p/3676746.html 数电实验交通灯VHDL版,程序写的扩展性很差,待以后有时间进行优化. ...

  2. 基于BASYS2的VHDL程序——分频和数码管静态显示程序

    转载请注明出处:http://www.cnblogs.com/connorzx/p/3633860.html 分频是基于计数器程序.由于FPGA的并行处理能力,根本不需要单片机式的中断指令,用起来很方 ...

  3. 基于BASYS2的VHDL程序与烧写——按键消抖程序

    请尊重作者版权,转载请注明源地址http://www.cnblogs.com/connorzx/p/3548364.html 按键在按下的过程中通常会产生一段时间的抖动,为了消除这种抖动,一般采取两种 ...

  4. 基于BASYS2的VHDL程序与仿真——50%占空比8分频器

    转帖请注明转自http://www.cnblogs.com/connorzx/p/3547673.html 一.新建工程 1.点击File->New Project, 2.点击Next 注:此处 ...

  5. 基于BASYS2的VHDL程序——数字钟(最终版)

    转载请注明原地址:http://www.cnblogs.com/connorzx/p/3674178.html 调时电路正常工作.一切正常.发现做FPGA还是得从数电的思路思考,设置一个预置使能端,预 ...

  6. 基于BASYS2的VHDL程序——数字钟(改进版)

    扩展到时分秒.加了入调时电路,但不知道为什么有两个按键不好使.而且不知道以何种方式假如按键消抖电路,因为加入后会多个时钟控制一个信号,物理不可实现.调试电路待解决.还有,四个数目管中间的那两个圆点怎么 ...

  7. 基于BASYS2的VHDL程序——数字钟

    在编电子表时发现FPGA求余,取模只能针对2的次方.毕竟是数字的嘛! 时钟用到了动态刷新数码管.以一个大于50Hz的速度刷新每一个数码管. 因为数码管只有四个,只写了分针和秒针. 代码如下: libr ...

  8. EDA课设-交通灯-Verilog版----FPGA--004

    分得到析四个状态: S1: 主干道(绿灯亮) ,支干道(亮红灯):--40S S1: 主干道 (黄灯亮) ,支干道(亮红灯):--4S S1: 主干道 (亮红灯),支干道(绿灯亮):--20S S1: ...

  9. 黑马程序员——【Java高新技术】——案例:交通灯管理系统

    ---------- android培训.java培训.期待与您交流! ---------- 一.交通灯管理系统的项目需求 Ø 异步随机生成按照各个路线行驶的车辆 例如: 由南向而来去往北向的车辆 - ...

随机推荐

  1. Arduino可穿戴教程保存源文件与打开已经存在的源文件

    Arduino可穿戴教程保存源文件与打开已经存在的源文件 Arduino IDE保存源文件 保存源文件可以通过“文件”菜单的“保存”或者快捷键Ctrl+S完成,如图2.28所示.   图2.28  保 ...

  2. 空扫描Idle Scanning

    空扫描Idle Scanning   空扫描Idle Scanning是一种借助第三方实施的端口扫描技术,可以很好的隐蔽扫描主机本身.它的实现基于以下两个TCP工作机制.   (1)在TCP三次握手阶 ...

  3. highcharts中放aqi及6要素,再加上气象5要素的图

    var chart = Highcharts.chart('container', { chart: { zoomType: 'xy' }, title: { text: '东京月平均天气数据' }, ...

  4. 几点iOS开发技巧

    转自I'm Allen的博客   原文:iOS Programming Architecture and Design Guidelines   原文来自破船的分享   原文作者是开发界中知晓度相当高 ...

  5. 全方位绕过软WAF攻略

    0×00 前言 现在软waf较为多,就在今年夏天苦逼挖洞的日子里经常遇到360主机卫士,安全狗,云锁之类的软waf进行拦截,经常碰到如下拦截提示: 看到以上三个拦截提示就让人头疼不已,欲罢不能. so ...

  6. 【Todo】Java并发学习 & 示例练习及代码

    接上一篇:http://www.cnblogs.com/charlesblc/p/6097111.html <Java并发学习 & Executor学习 & 异常逃逸 & ...

  7. python3 查看已安装的模块

    一.命令行下使用pydoc命令 在命令行下运行$ pydoc modules即可查看 二.在python交互解释器中使用help()查看 在交互式解释器中输入>>> help(&qu ...

  8. C++11 并发指南系列(转)

    本系列文章主要介绍 C++11 并发编程,计划分为 9 章介绍 C++11 的并发和多线程编程,分别如下: C++11 并发指南一(C++11 多线程初探)(本章计划 1-2 篇,已完成 1 篇) C ...

  9. linux c 网络编程:用域名获取IP地址或者用IP获取域名 网络地址转换成整型 主机字符顺序与网络字节顺序的转换

    用域名获取IP地址或者用IP获取域名 #include<stdio.h> #include<sys/socket.h> #include<netdb.h> int ...

  10. php把时间存入数据库为年月日时分秒类型

    时间用now() $sql1 = "insert into registerip (name,logintime,ip,url) values ('1211121',now(),'127.0 ...