当前位置:网站首页>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
边栏推荐
- 【MindSpore易点通机器人-01】你也许见过很多知识问答机器人,但这个有点不一样
- IDEA performs the Test operation, resulting in duplicate data when data is inserted
- [Unity] [UGUI] [Display text on the screen]
- PHP 操作mangoDb
- MySQL之数据视图
- js hijacks the array push method
- 手写柯里化 - toString 理解
- 企业的数字化转型到底是否可以买来?
- uniapp connect ibeacon
- Qiu Jun, CEO of Eggplant Technology: Focus on users and make products that users really need
猜你喜欢
【 temperature warning program DE development 】 event driven model instance
egg框架使用(一)
Oracle temporary table space role
Open Source Summer | How OpenHarmony Query Device Type (eTS)
hcip BGP enhancement experiment
leetcode: 529. Minesweeper Game
Getting started with Polkadot parachain development, this article is enough
E-sports, convenience, efficiency, security, key words for OriginOS functions
Jenkins manual (2) - software configuration
After Keil upgrades to AC6, what changes?
随机推荐
仿SBUS与串口数据固定转换
Pycharm 常用外部工具
MySQL使用聚合函数可以不搭配GROUP BY分组吗?
高质量 DeFi 应用构建指南,助力开发者玩转 DeFi Summer
matcher中find,matches,lookingAt匹配字符串的不同之处说明
无题十一
无题七
Redis源码解析:Redis Cluster
What is the function of the regular expression replaceFirst() method?
Qiu Jun, CEO of Eggplant Technology: Focus on users and make products that users really need
MySQL transactions
The founder of the DFINITY Foundation talks about the ups and downs of the bear market, and where should DeFi projects go?
What is CRM Decision Analysis Management?
2022 Huashu Cup Mathematical Modeling Question A Optimization Design Ideas for Ring Oscillators Code Sharing
华为轻量级神经网络架构GhostNet再升级,GPU上大显身手的G-GhostNet(IJCV22)
【AGC】增长服务1-远程配置示例
开发常用手册链接分享
IO流篇 -- 基于io流实现文件夹拷贝(拷贝子文件夹及子文件夹内文件)满满的干货
[强网杯2022]WP-UM
Development common manual link sharing