当前位置:网站首页>FPGA:基础入门按键控制LED灯
FPGA:基础入门按键控制LED灯
2022-08-05 10:10:00 【最早的早安...】
题目概述:
使用按键控制LED灯亮灭。
无按键按下——LED全灭
按下KEYO——从右向左的流水灯效果
按下KEY1——从左向右的流水灯效果
按下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
//状态切换和状态赋值
[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
边栏推荐
- What is the function of the regular expression replaceAll() method?
- Meteorological data processing example - matlab string cutting matching and R language date matching (data splicing)
- 浅析WSGI协议
- 入门 Polkadot 平行链开发,看这一篇就够了
- Still looking for a network backup resources?Hurry up to collect the following network backup resource search artifact it is worth collecting!
- matcher中find,matches,lookingAt匹配字符串的不同之处说明
- js hijacks the array push method
- 第五章:activiti流程分流判断,判断走不同的任务节点
- 自定义过滤器和拦截器实现ThreadLocal线程封闭
- MySQL之数据视图
猜你喜欢

Keil升级到AC6后,到底有哪些变化?
![[Strong Net Cup 2022] WP-UM](/img/3d/caeab05ddca278af274dbf6e2f8ba1.png)
[Strong Net Cup 2022] WP-UM

告白数字化转型时代:麦聪软件以最简单的方式让企业把数据用起来

开源一夏|OpenHarmony如何查询设备类型(eTS)

JS introduction to reverse the recycling business network of learning, simple encryption mobile phone number

STM32+ULN2003驱动28BYJ4步进电机(根据圈数正转、反转)

The century-old Nordic luxury home appliance brand ASKO smart wine cabinet in the three-temperature area presents the Chinese Valentine’s Day, and tastes the love of the delicacy

教你本地编译运行一个IDEA插件,在IDEA里聊天、下棋、斗地主!

项目成本控制如何帮助项目成功?

语音社交软件开发——充分发挥其价值
随机推荐
蚁剑webshell动态加密连接分析与实践
Where is your most secretive personality?
STM32+ULN2003驱动28BYJ4步进电机(根据圈数正转、反转)
多线程(进阶) - 2.5w字总结
Our Web3 Entrepreneurship Project, Yellow
egg框架使用(二)
SMB + SMB2: Accessing shares return an error after prolonged idle period
Wei Dongshan Digital Photo Frame Project Learning (6) Transplantation of tslib
Tanabata romantic date without overtime, RPA robot helps you get the job done
Qiu Jun, CEO of Eggplant Technology: Focus on users and make products that users really need
【Office】Microsoft Office下载地址合集(微软官方原版离线安装下载)
static linking and dynamic linking
Egg framework usage (2)
High-quality DeFi application building guide to help developers enjoy DeFi Summer
Is digital transformation a business buy-in?
一文道清什么是SPL
2022华数杯数学建模思路分析交流
Oracle temporary table space role
three.js debugging tool dat.gui use
Pytorch深度学习快速入门教程 -- 土堆教程笔记(三)