当前位置:网站首页>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
边栏推荐
- Getting started with Polkadot parachain development, this article is enough
- Is digital transformation a business buy-in?
- Complete image segmentation efficiently based on MindSpore and realize Dice!
- [Android]如何使用RecycleView in Kotlin project
- js hijacks the array push method
- 产品太多了,如何实现一次登录多产品互通?
- NowCoderTOP35-40——持续更新ing
- Wei Dongshan Digital Photo Frame Project Learning (6) Transplantation of tslib
- 第七章,activiti个人任务分配,动态指定和监听器指定任务委派人「建议收藏」
- Development common manual link sharing
猜你喜欢
偏向锁/轻量锁/重级锁锁锁更健康,上锁解锁到底是怎么完成实现的
华为轻量级神经网络架构GhostNet再升级,GPU上大显身手的G-GhostNet(IJCV22)
The founder of the DFINITY Foundation talks about the ups and downs of the bear market, and where should DeFi projects go?
数据中台建设(十):数据安全管理
Which big guy has the 11G GI and ojvm patches in April or January 2020, please help?
Confessing in the era of digital transformation: Mai Cong Software allows enterprises to use data in the easiest way
19. Server-side session technology Session
Our Web3 Entrepreneurship Project, Yellow
语音社交软件开发——充分发挥其价值
哪位大佬有20年4月或者1月的11G GI和ojvm补丁呀,帮忙发下?
随机推荐
教你本地编译运行一个IDEA插件,在IDEA里聊天、下棋、斗地主!
企业的数字化转型到底是否可以买来?
Open Source Summer | How OpenHarmony Query Device Type (eTS)
力扣(LeetCode)216. 组合总和 III(2022.08.04)
【Office】Microsoft Office下载地址合集(微软官方原版离线安装下载)
js hijacks the array push method
SMB + SMB2: Accessing shares return an error after prolonged idle period
百年北欧奢华家电品牌ASKO智能三温区酒柜臻献七夕,共品珍馐爱意
LeetCode 216. Combined Sum III (2022.08.04)
QSS 选择器
Offensive World-PWN-new_easypwn
STM32+ULN2003 drives 28BYJ4 stepper motor (forward and reverse according to the number of turns)
[Office] Collection of Microsoft Office download addresses (offline installation and download of Microsoft's official original version)
matcher中find,matches,lookingAt匹配字符串的不同之处说明
第四章:activiti流程中,变量的传递和获取流程变量 ,设置和获取多个流程变量,设置和获取局部流程变量「建议收藏」
七夕浪漫约会不加班,RPA机器人帮你搞定工作
蚁剑webshell动态加密连接分析与实践
The founder of the DFINITY Foundation talks about the ups and downs of the bear market, and where should DeFi projects go?
19.服务器端会话技术Session
Oracle 19.3 restart 环境