基于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培训.期待与您交流! ---------- 一.交通灯管理系统的项目需求 Ø 异步随机生成按照各个路线行驶的车辆 例如: 由南向而来去往北向的车辆 - ...
随机推荐
- laravel svn从win上传linux需要注意事项
一首页设置目录权限: /storage /bootstrap/cache 设置可写权限 二执行命令: php artisan key:generate
- uitableview中文排序问题
1,uitableview中涉及到排序的问题,查找资料后发现使用UILocalizedIndexedCollation可以很好处理中文和英文系统下中文的排序.而且如果第一个汉字首字母一样那么就会按照第 ...
- iOS -- SKEmitterNode类
SKEmitterNode类 继承自 SKNode:UIResponder:NSObject 符合 NSCoding(SKNode)NSCopying(SKNode)NSObject(NSObje ...
- Go -- LFU类(缓存淘汰算法)(转)
1. LFU类 1.1. LFU 1.1.1. 原理 LFU(Least Frequently Used)算法根据数据的历史访问频率来淘汰数据,其核心思想是“如果数据过去被访问多次,那么将来被访问的频 ...
- SilverLight:基础控件使用(4)-日期显示和选择类控件
ylbtech-SilverLight-Basic-Control:基础控件使用(4)-日期显示和选择类控件 Calendar,DatePicker 1.A,返回顶部 Calendar控件(日期控件) ...
- Exchange 2013 Database Move to New Partition
建议不要删除默认数据库,可以通过修改默认数据库名称.路径等实现您的需求. 客戶:The HK Anti-Cancer Society. 要求:遷移數據庫(01)到新分區,實際是遷移成為數據庫(05) ...
- Vue.js 使用cordova camera插件调取相机
本文给出在vue.js里如何使用cordova的插件完成调取相机及图库,并完成图片上传的操作.具体的操作步骤如下 第一步:在cordova项目下安装cordova-plugin-camera插件 co ...
- windows 平台 ffmeg h264 硬编码
本文讲述windows 平台下ffmpeg如何利用intel media SDK 进行 h264硬编码(测试版本为3.2.2). ffmeg硬编编码的流程与软件编码流程相同,唯一不同的地方在初始化en ...
- javacript中apply和call的区别
apply:方法能劫持另外一个对象的方法,继承另外一个对象的属性. 接受的参数是一个字符串. call:和apply的意思一样,只不过是参数列表不一样. 接收的参数是一个数组. 例如: <s ...
- MOS简介
功率半导体器件机能 MOS管(击穿原因),它采用“超级结”(Super-Junction)结构,故又称超结功率MOSFET.全数字控制是发展趋势,已经在很多功率变换设备中得到应用.既管理了对电网的谐波 ...