黑金开发板状态机实现的可用按键控制的流水灯
2012-07-10 21:15
549 查看
module state(CLOCK,RESET,LED,KEY_UP);
input CLOCK,RESET,KEY_UP;
output reg [3:0] LED;
parameter s1=2'b00,s2=2'b01,s3=2'b10,s4=2'b11;
reg [1:0] current_state,next_state;
reg t;
parameter T1s=23'd2_000_00000;
reg [22:0] cnt;
always @ (posedge CLOCK or negedge RESET)
if(!RESET)
begin
cnt<=0;
t<=0;
end
else if(cnt==T1s)
begin
cnt<=0;
t<=~t;
end
else
cnt<=cnt+1;
//assign t=(cnt==T1s)? 1'b1:1'b0;
always @ (posedge t or negedge RESET)
if(!RESET)
current_state<=s1;
else
current_state<=next_state;
always @ (current_state)
begin
next_state=s1;
case(current_state)
s1: if(KEY_UP) next_state=s2;else next_state=s4;
s2: if(KEY_UP) next_state=s3;else next_state=s1;
s3: if(KEY_UP) next_state=s4;else next_state=s2;
s4: if(KEY_UP) next_state=s1;else next_state=s3;
default: next_state=s1;
endcase
end
always @ (posedge t or negedge RESET)
if(!RESET)
LED<=4'b0000;
else
case(next_state)
s1: LED<=4'b0001;
s2: LED<=4'b0010;
s3: LED<=4'b0100;
s4: LED<=4'b1000;
default: LED<=4'bzzzz;
endcase
endmodule
input CLOCK,RESET,KEY_UP;
output reg [3:0] LED;
parameter s1=2'b00,s2=2'b01,s3=2'b10,s4=2'b11;
reg [1:0] current_state,next_state;
reg t;
parameter T1s=23'd2_000_00000;
reg [22:0] cnt;
always @ (posedge CLOCK or negedge RESET)
if(!RESET)
begin
cnt<=0;
t<=0;
end
else if(cnt==T1s)
begin
cnt<=0;
t<=~t;
end
else
cnt<=cnt+1;
//assign t=(cnt==T1s)? 1'b1:1'b0;
always @ (posedge t or negedge RESET)
if(!RESET)
current_state<=s1;
else
current_state<=next_state;
always @ (current_state)
begin
next_state=s1;
case(current_state)
s1: if(KEY_UP) next_state=s2;else next_state=s4;
s2: if(KEY_UP) next_state=s3;else next_state=s1;
s3: if(KEY_UP) next_state=s4;else next_state=s2;
s4: if(KEY_UP) next_state=s1;else next_state=s3;
default: next_state=s1;
endcase
end
always @ (posedge t or negedge RESET)
if(!RESET)
LED<=4'b0000;
else
case(next_state)
s1: LED<=4'b0001;
s2: LED<=4'b0010;
s3: LED<=4'b0100;
s4: LED<=4'b1000;
default: LED<=4'bzzzz;
endcase
endmodule
相关文章推荐
- P1口外接8个LED,通过按键控制,实现左右移动的流水灯
- Android中通过耳机按键控制音乐播放的实现
- 【连载】【FPGA黑金开发板】Verilog HDL那些事儿--独立按键封装(十五)
- 转载:cocos2d-x下硬件音量按键控制游戏音量的实现
- 在开发板S3C2440中如何用自带的QT去设计一个界面来实现控制摄像头,这个界面的框架图是怎样的
- 基于状态机的单个按键长按,短按实现复用
- Qt实现完全按键控制Ui的简单框架
- 按键状态机—实现连发
- dsp控制DM9000实现802.3数据收发第三篇,调试过程程序第二版;接受部分可用,但是容易掉帧,采用的读取dm9000中断寄存器的方式获取数据
- 按键控制LED实现启动、停止按钮
- cocos2d-x下硬件音量按键控制游戏音量的实现
- 单片机:按键(使用中断)控制数码管的数字加减(c语言实现)
- micro2440利用LEDS与BUTTONS驱动实现按键控制led灯【开发总结】
- STM32F103(按键控制流水灯方向)
- Verilog/CPLD代码之按键控制流水灯
- [嵌入式开发板] iTOP-4412实现web控制led
- STM32F103按键操作的另一种实现——状态机
- linux系统怎么实现按键控制进度条
- 基于状态机的按键扫描的实现
- 按键控制流水灯启动,停止,加速,减速