按键边缘检测,控制LED亮灭

编程入门 行业动态 更新时间:2024-10-22 15:40:11

<a href=https://www.elefans.com/category/jswz/34/1768597.html style=按键边缘检测,控制LED亮灭"/>

按键边缘检测,控制LED亮灭

模块代码

`timescale 1ns / 1ps
//
// Company: 
// Engineer: 
// 
// Create Date:    13:40:18 09/25/2019 
// Design Name: 
// Module Name:    touch_led_top 
// Project Name: 
// Target Devices: 
// Tool versions: 
// Description: 
//
// Dependencies: 
//
// Revision: 
// Revision 0.01 - File Created
// Additional Comments: 
//
//
module touch_led_top(input 		clk,input 		rst_n,input 		touch_key,output  reg led);reg touch_key_d0;
reg touch_key_d1;
wire touch_key_flag;//边沿检测代码
assign touch_key_flag = (~touch_key_d1) & touch_key_d0;//检测上升沿
//assign touch_key_flag = touch_key_d1 & (~touch_key_d0);//检测下降沿always@(posedge clk or negedge rst_n)beginif(!rst_n)begintouch_key_d0 <= 1'b0;touch_key_d1 <= 1'b0;endelse begintouch_key_d0 <= touch_key;touch_key_d1 <= touch_key_d0;end		
end//led赋值代码
always@(posedge clk or negedge rst_n)beginif(!rst_n)led <= 1'b1;elseif(touch_key_flag)led <= ~led;elseled <= led;
endendmodule

仿真代码

`timescale 1ns / 1ps// Company: 
// Engineer:
//
// Create Date:   10:07:01 09/26/2019
// Design Name:   touch_led_top
// Module Name:   C:/Verilog/touch_led/td_touch_led.v
// Project Name:  touch_led
// Target Device:  
// Tool versions:  
// Description: 
//
// Verilog Test Fixture created by ISE for module: touch_led_top
//
// Dependencies:
// 
// Revision:
// Revision 0.01 - File Created
// Additional Comments:
// module td_touch_led;// Inputsreg clk;reg rst_n;reg touch_key;// Outputswire led;// Instantiate the Unit Under Test (UUT)touch_led_top uut (.clk(clk), .rst_n(rst_n), .touch_key(touch_key), .led(led));always #10 clk=~clk;//20nm时钟信号initial begin// Initialize Inputsclk = 0;rst_n = 0;touch_key = 0;// Wait 100 ns for global reset to finish#20;rst_n = 1;#100;touch_key = ~touch_key;#100;touch_key = ~touch_key;		#100;touch_key = ~touch_key;#100;touch_key = ~touch_key;	      // Add stimulus hereendendmodule

仿真图片

更多推荐

按键边缘检测,控制LED亮灭

本文发布于:2023-06-27 08:20:08,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/908690.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:按键   边缘   亮灭   LED

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!