• 基于黑金开发板的键盘边沿检测程序


    /**************************************
            The Key Edge Test
    Author:luxiaolai
    Date  :2011-11-29
    ***************************************/

    module test(LED,RESET,CLOCK,KEY_UP);
    input RESET,CLOCK,KEY_UP;
    output [3:0] LED;
    wire led_cn;
    test1 U1
    (
     .clk(CLOCK),
     .rst(RESET),
     .key(KEY_UP),
     .keyout(led_cn),
    );
    test3 U2
    (
     .clk(CLOCK),
     .rst(RESET),
     .led_cn(led_cn),
     .led(LED),
    );
    endmodule

    /**************************************
      The Key Test Part
    **************************************/
    module test1(clk,rst,key,keyout);
    input clk,rst,key;
    parameter cnt1=32'd2_00000;
    reg[31:0] cnt;
    reg key1,key2;
    wire keyin;
    always @ (posedge clk or negedge rst)
    if(!rst)
     begin
      key1<=1'b1;
      key2<=1'b1;
     end
      else
      begin
       key1<=key;
       key2<=key1;
      end
    assign keyin=key2&(~key1);
    reg key3,key4;
    output keyout;
    always @ (posedge clk or negedge rst)
    if(!rst)
     begin
      cnt<=0;
      key3<=1;
     end
      else if(keyin)
      begin
       cnt<=0;
       key3<=1;
       end
      else if(cnt==cnt1)
       begin
        cnt<=0;
        key3<=key;
       end
        else
         cnt<=cnt+1;
    always @ (posedge clk or negedge rst)
    if(!rst)
     key4<=1;
      else
       key4<=key3;
    assign keyout=key4&(~key3);
    endmodule

    /************************************
      The Display Part
    *************************************/     
    module test3(led,clk,rst,led_cn);
    input clk,rst,led_cn;
    output reg[3:0] led;
    always @ (posedge clk or negedge rst)
    if(!rst)
     led<=4'b0001;
      else if(led_cn)
       begin
        led<=led+1;
        if(led==4'b1111)
        led<=0;
        end
         //else
          //led<=led;
    endmodule

  • 相关阅读:
    POJ1806 Manhattan 2025
    POJ1258 AgriNet【最小生成树】
    POJ1789 Truck History【最小生成树】【终于AC了】
    memset的用法
    HDOJ1106 排序
    POJ2965
    414某OJ竞赛题
    HDOJ1745 I hate it【线段树】
    HDOJ2795 Billboard【线段树】
    蓝桥杯o(︶︿︶)o 唉
  • 原文地址:https://www.cnblogs.com/luxiaolai/p/2268280.html
Copyright © 2020-2023  润新知