基于BASYS2的VHDL程序——交通灯(状态机版)
请尊重作者版权,转载注明源地址: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程序——交通灯(状态机版)的更多相关文章
- 基于BASYS2的VHDL程序——交通灯
请尊重作者版权,转载请注明原地址: http://www.cnblogs.com/connorzx/p/3676746.html 数电实验交通灯VHDL版,程序写的扩展性很差,待以后有时间进行优化. ...
- 基于BASYS2的VHDL程序——分频和数码管静态显示程序
转载请注明出处:http://www.cnblogs.com/connorzx/p/3633860.html 分频是基于计数器程序.由于FPGA的并行处理能力,根本不需要单片机式的中断指令,用起来很方 ...
- 基于BASYS2的VHDL程序与烧写——按键消抖程序
请尊重作者版权,转载请注明源地址http://www.cnblogs.com/connorzx/p/3548364.html 按键在按下的过程中通常会产生一段时间的抖动,为了消除这种抖动,一般采取两种 ...
- 基于BASYS2的VHDL程序与仿真——50%占空比8分频器
转帖请注明转自http://www.cnblogs.com/connorzx/p/3547673.html 一.新建工程 1.点击File->New Project, 2.点击Next 注:此处 ...
- 基于BASYS2的VHDL程序——数字钟(最终版)
转载请注明原地址:http://www.cnblogs.com/connorzx/p/3674178.html 调时电路正常工作.一切正常.发现做FPGA还是得从数电的思路思考,设置一个预置使能端,预 ...
- 基于BASYS2的VHDL程序——数字钟(改进版)
扩展到时分秒.加了入调时电路,但不知道为什么有两个按键不好使.而且不知道以何种方式假如按键消抖电路,因为加入后会多个时钟控制一个信号,物理不可实现.调试电路待解决.还有,四个数目管中间的那两个圆点怎么 ...
- 基于BASYS2的VHDL程序——数字钟
在编电子表时发现FPGA求余,取模只能针对2的次方.毕竟是数字的嘛! 时钟用到了动态刷新数码管.以一个大于50Hz的速度刷新每一个数码管. 因为数码管只有四个,只写了分针和秒针. 代码如下: libr ...
- EDA课设-交通灯-Verilog版----FPGA--004
分得到析四个状态: S1: 主干道(绿灯亮) ,支干道(亮红灯):--40S S1: 主干道 (黄灯亮) ,支干道(亮红灯):--4S S1: 主干道 (亮红灯),支干道(绿灯亮):--20S S1: ...
- 黑马程序员——【Java高新技术】——案例:交通灯管理系统
---------- android培训.java培训.期待与您交流! ---------- 一.交通灯管理系统的项目需求 Ø 异步随机生成按照各个路线行驶的车辆 例如: 由南向而来去往北向的车辆 - ...
随机推荐
- 会话跟踪技术Cookieless
会话跟踪技术Cookieless 在Web应用中,通常使用Cookie记录用户的状态,如用户名.访问时间等信息.当进行HTTP请求的时候,会自动发送Cookie信息给服务器.服务器接收到,就可以判 ...
- HDU 2460 Network 傻逼Tarjan
Network Time Limit: 10000/5000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Su ...
- 天啦噜!原来Chrome自带的开发者工具还能这么用!
作者:余博伦链接:https://zhuanlan.zhihu.com/p/22665710来源:知乎著作权归作者所有.商业转载请联系作者获得授权,非商业转载请注明出处. Chrome自带开发者工具. ...
- Git 常用场景操作
git init 在本地新建一个repo,进入一个项目目录,执行git init,会初始化一个repo,并在当前文件夹下创建一个.git文件夹. git clone 获取一个u ...
- 赵雅智_Fragment
当我们须要动态的多界面切换的时候,就须要将UI元素和Activity融合成一个模块. 在2.3中我们一般通过各种Activity中进行跳转来实现多界面的跳转和单个界面动态改变.在4.0或以上系统中就能 ...
- MDCC 2014移动开发人员大会參会实录
MDCC 2014移动开发人员大会參会实录 详细讲什么我就不反复了,各大媒体的编辑整理的比我的好! 我就晒晒图!后面有惊喜哦! 会场地点:早上七点多.天色有点暗,主要是阴天的原因. watermark ...
- python(40)- 进程、线程、协程及IO模型
一.操作系统概念 操作系统位于底层硬件与应用软件之间的一层.工作方式:向下管理硬件,向上提供接口. 操作系统进行进程切换:1.出现IO操作:2.固定时间. 固定时间很短,人感受不到.每一个应用层运行起 ...
- python缺省参数
def test(a,b=22): result=a+b print("resuLt=%d"%result) test(33,33) #缺省参数的意思就是,函数在有参数的情况下,调 ...
- svn 命令个
svn 命令行下常用的几个命令 标签: svnpathdelete工作urlfile 2011-11-28 08:16 128627人阅读 评论(1) 收藏 举报 分类: 版本控制(8) 版权声明 ...
- caffe搭建以及初步学习--win7-vs2013-gtx650tiboost-cuda8.0-cifar10训练和测试-2-完整解决方案cifar10_full_solver.prototxt
首先总结前一节的内容. 简单的讲,就是训练并测试了快速解决方案. 转换数据格式: convert_cifar_data.exe data/cifar10 examples/cifar10 lmdb 计 ...