当前位置:网站首页>FPGA: Basic Getting Started Button Controlling LED Lights
FPGA: Basic Getting Started Button Controlling LED Lights
2022-08-05 10:17:00 【first good morning...】
题目概述:
使用按键控制LED灯亮灭.
无按键按下——LED全灭
按下KEYO——Flowing water light effect from right to left
按下KEY1——Flowing water light effect from left to right
按下KEY2——LED闪烁
按下KEY3——LED全亮
编程:
`timescale 1ns / 1ps
module key_led(
input sys_clk,
input sys_rst_n,
input [3:0] key,
output reg [3:0] led
);
//定义0.2s计数器 0.2s/20ns=10^7
reg [23:0] cnt;
[email protected](posedge sys_clk or negedge sys_rst_n)
begin
if(!sys_rst_n)
cnt<=0;
else if(cnt<24'd999_9999)
cnt<=cnt+1'b1;
else
cnt<=0;
end
reg [1:0] led_control;//4个LED 00 01 10 11
//State transition and state assignment
[email protected](posedge sys_clk or negedge sys_rst_n)
begin
if(!sys_rst_n)
led_control<=4'b0;
else if(cnt==24'd999_9999)
led_control<=led_control+1'b1;
else
led_control<=led_control;
end
[email protected](posedge sys_clk or negedge sys_rst_n)
begin
if(!sys_rst_n)
led<=4'b0000;
else if(key[0]==0)
case(led_control)
2'b00:led<=4'b1000;
2'b01:led<=4'b0100;
2'b10:led<=4'b0010;
2'b11:led<=4'b0001;
endcase
else if(key[1]==0)
case(led_control)
2'b00:led<=4'b0001;
2'b01:led<=4'b0010;
2'b10:led<=4'b0100;
2'b11:led<=4'b1000;
endcase
else if(key[2]==0)
case(led_control)
2'b00:led<=4'b0000;
2'b01:led<=4'b1111;
2'b10:led<=4'b0000;
2'b11:led<=4'b1111;
endcase
else if(key[3]==0)
led<=4'b1111;
else
led<=4'b0000;
end
endmodule
上机实践:
QQ视频20220804160212
边栏推荐
- Imitation SBUS fixed with serial data conversion
- 2022杭电多校 第6场 1008.Shinobu Loves Segment Tree 规律题
- 静态链接和动态链接
- The founder of the DFINITY Foundation talks about the ups and downs of the bear market, and where should DeFi projects go?
- Brief Analysis of WSGI Protocol
- 上位机开发C#语言:模拟STC串口助手接收单片机发送数据
- three.js调试工具dat.gui使用
- Oracle临时表空间作用
- 入门 Polkadot 平行链开发,看这一篇就够了
- static linking and dynamic linking
猜你喜欢
随机推荐
Analysis and practice of antjian webshell dynamic encrypted connection
自定义过滤器和拦截器实现ThreadLocal线程封闭
NowCoderTOP35-40——持续更新ing
[Strong Net Cup 2022] WP-UM
Keil升级到AC6后,到底有哪些变化?
Custom filters and interceptors implement ThreadLocal thread closure
【Unity】【UGUI】【在屏幕上显示文本】
第五章:activiti流程分流判断,判断走不同的任务节点
深入理解 Istio 流量管理的超时时间设置
IDEA performs the Test operation, resulting in duplicate data when data is inserted
入门 Polkadot 平行链开发,看这一篇就够了
Oracle 19.3 restart 环境
Confessing in the era of digital transformation: Mai Cong Software allows enterprises to use data in the easiest way
JS introduction to reverse the recycling business network of learning, simple encryption mobile phone number
Oracle临时表空间作用
What is the function of the regular expression replaceFirst() method?
MySQL transactions
[Office] Collection of Microsoft Office download addresses (offline installation and download of Microsoft's official original version)
dotnet OpenXML parsing PPT charts Getting started with area charts
Imitation SBUS fixed with serial data conversion