当前位置:网站首页>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
边栏推荐
- 偏向锁/轻量锁/重级锁锁锁更健康,上锁解锁到底是怎么完成实现的
- How does the official account operate and maintain?Public account operation and maintenance professional team
- What is the function of the regular expression replaceAll() method?
- NowCoderTOP35-40 - continuous update ing
- IDEA performs the Test operation, resulting in duplicate data when data is inserted
- Voice conversion相关语音数据集综合汇总
- Qiu Jun, CEO of Eggplant Technology: Focus on users and make products that users really need
- Handwriting Currying - toString Comprehension
- SD NAND Flash简介!
- Advanced usage of C language
猜你喜欢
随机推荐
[Unity] [UGUI] [Display text on the screen]
第三章 : redis数据结构种类
SMB + SMB2: Accessing shares return an error after prolonged idle period
电竞、便捷、高效、安全,盘点OriginOS功能的关键词
基于MindSpore高效完成图像分割,实现Dice!
第九章:activit内置用户组设计与组任务分配和IdentityService接口的使用
语音社交软件开发——充分发挥其价值
MySQL transactions
Getting started with Polkadot parachain development, this article is enough
E-sports, convenience, efficiency, security, key words for OriginOS functions
Is digital transformation a business buy-in?
NowCoderTOP35-40 - continuous update ing
[Strong Net Cup 2022] WP-UM
Egg framework usage (1)
Open Source Summer | How OpenHarmony Query Device Type (eTS)
How can project cost control help project success?
How does the official account operate and maintain?Public account operation and maintenance professional team
力扣(LeetCode)216. 组合总和 III(2022.08.04)
Imitation SBUS fixed with serial data conversion
Egg framework usage (2)









