用状态机实现循环彩灯控制器(含清零功能)000→001→010→100→010→001→000→111→000→111→(循环)
2条回答 默认 最新
- zhaoyang_yt 2019-12-11 14:45关注
module led
(
input clk,
input rst_n,output led_000,
output led_001,
output led_010,
output led_100,
output led_111
);parameter LED_000 = 5'b00001,
LED_001 = 5'b00010,
LED_010 = 5'b00100,
LED_100 = 5'b01000,
LED_111 = 5'b00010;reg [4:0] cnt;
reg [4:0] cur_state;
reg [4:0] nxt_state;always @(posedge clk or negedge rst_n)
begin
if(~rst_n)
cur_state <= LED_000;
else
cur_state <= nxt_state;
endalways @(*)
begin
nxt_state = cur_state;
case(cur_state)
LED_000 : if(cnt==5'h1f)
nxt_state = LED_001;
LED_001 : if(cnt==5'h1f)
nxt_state = LED_010;
LED_010 : if(cnt==5'h1f)
nxt_state = LED_100;
LED_100 : if(cnt==5'h1f)
nxt_state = LED_111;
LED_111 : if(cnt==5'h1f)
nxt_state = LED_000;
endcase
endalways @(posedge clk or negedge rst_n)
begin
if(~rst_n)
cnt <= 5'd0;
else
cnt <= cnt + 1'd1;
endassign led_000=cur_state[0];
assign led_001=cur_state[1];
assign led_010=cur_state[2];
assign led_100=cur_state[3];
assign led_111=cur_state[4];endmodule
本回答被题主选为最佳回答 , 对您是否有帮助呢?解决 3无用 1
悬赏问题
- ¥15 metadata提取的PDF元数据,如何转换为一个Excel
- ¥15 关于arduino编程toCharArray()函数的使用
- ¥100 vc++混合CEF采用CLR方式编译报错
- ¥15 coze 的插件输入飞书多维表格 app_token 后一直显示错误,如何解决?
- ¥15 vite+vue3+plyr播放本地public文件夹下视频无法加载
- ¥15 c#逐行读取txt文本,但是每一行里面数据之间空格数量不同
- ¥50 如何openEuler 22.03上安装配置drbd
- ¥20 ING91680C BLE5.3 芯片怎么实现串口收发数据
- ¥15 无线连接树莓派,无法执行update,如何解决?(相关搜索:软件下载)
- ¥15 Windows11, backspace, enter, space键失灵