当前位置:网站首页>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
边栏推荐
- 19. Server-side session technology Session
- dotnet OpenXML parsing PPT charts Getting started with area charts
- 2022华数杯数学建模A题环形振荡器的优化设计思路思路代码分享
- 2022华数杯数学建模思路分析交流
- Microservice Technology Stack
- Jenkins使用手册(2) —— 软件配置
- E-sports, convenience, efficiency, security, key words for OriginOS functions
- 一文道清什么是SPL
- Pytorch深度学习快速入门教程 -- 土堆教程笔记(三)
- leetcode: 529. 扫雷游戏
猜你喜欢

MySQL事务

Pycharm 常用外部工具

我们的Web3创业项目,黄了

leetcode: 529. Minesweeper Game

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

2022 Huashu Cup Mathematical Modeling Question A Optimization Design Ideas for Ring Oscillators Code Sharing

The technological achievements of Shanghai Konan were selected into the "2021 Shanghai Network Security Industry Innovation Research Achievement Catalog" by the Municipal Commission of Economy and Inf

阿里顶级架构师多年总结的JVM宝典,哪里不会查哪里!

dotnet OpenXML parsing PPT charts Getting started with area charts

Redis源码解析:Redis Cluster
随机推荐
第四章:activiti流程中,变量的传递和获取流程变量 ,设置和获取多个流程变量,设置和获取局部流程变量「建议收藏」
Still looking for a network backup resources?Hurry up to collect the following network backup resource search artifact it is worth collecting!
为什么sys_class 里显示的很多表的 RELTABLESPACE 值为 0 ?
你最隐秘的性格在哪?
STM32+ULN2003驱动28BYJ4步进电机(根据圈数正转、反转)
Advanced usage of C language
Custom filters and interceptors implement ThreadLocal thread closure
hcip BGP enhancement experiment
Pytorch深度学习快速入门教程 -- 土堆教程笔记(三)
Huawei's lightweight neural network architecture GhostNet has been upgraded again, and G-GhostNet (IJCV22) has shown its talents on the GPU
Which big guy has the 11G GI and ojvm patches in April or January 2020, please help?
Meteorological data processing example - matlab string cutting matching and R language date matching (data splicing)
three.js调试工具dat.gui使用
DFINITY 基金会创始人谈熊市沉浮,DeFi 项目该何去何从
leetcode: 529. 扫雷游戏
What is SPL?
茄子科技CEO仇俊:以用户为中心,做用户真正需要的产品
leetcode: 529. Minesweeper Game
【 temperature warning program DE development 】 event driven model instance
无题五