This is an example to use push button, BTN0 as a reset signal to reset the counter. Please read Nexys2 reference manual carefully. These push buttons are connected to ground as default.
`timescale 1ns / 1ps
//////////////////////////////////////////////////////////////////////////////////
// Company:
// Engineer:
//
// Create Date: 15:33:56 10/21/2014
// Design Name:
// Module Name: test
// Project Name:
// Target Devices:
// Tool versions:
// Description:
//
// Dependencies:
//
// Revision:
// Revision 0.01 - File Created
// Additional Comments:
//
//////////////////////////////////////////////////////////////////////////////////
module test(reset_n,clk,btn,a_to_g);
input clk;
input reset_n;
input [3:0] btn;
output reg [7:0] a_to_g;
reg [24:0] q;
reg [3:0] counter;
wire clk48;
wire clk24;
wire clk12;
//Frequency Divider assume clk is 50Mhz
assign clk48 = q[19];//48hz clock
assign clk24 = q[20];//24hz clock
assign clk12 = q[21];//12hz clock
assign clk6 = q[22];//6hz clock
assign clk3 = q[23];//3hz clock
always @(posedge clk or negedge reset_n)
begin
if(reset_n == 1'b0)
q <= 0;
else
q <= q + 1'b1;
end
//A 4-bit counter
always@(posedge clk3 or posedge btn[0])
begin
if(btn[0] == 1'b1)
counter <= 4'b0;
else
counter <= counter + 1'b1;
end
//7-Segment LED Decoder
always @(*)
case(counter)
4'h0: a_to_g = 7'b0000001;
4'h1: a_to_g = 7'b1001111;
4'h2: a_to_g = 7'b0010010;
4'h3: a_to_g = 7'b0000110;
4'h4: a_to_g = 7'b1001100;
4'h5: a_to_g = 7'b0100100;
4'h6: a_to_g = 7'b0100000;
4'h7: a_to_g = 7'b0001111;
4'h8: a_to_g = 7'b0000000;
4'h9: a_to_g = 7'b0000100;
4'hA: a_to_g = 7'b1110111;
//4'hb: a_to_g = 7'b0;
//4'hC: a_to_g = 7'b0;
//4'hd: a_to_g = 7'b1;
//4'hE: a_to_g = 7'b0;
//4'hF: a_to_g = 7'b0;
default: a_to_g = 7'b0000001;
endcase
endmodule
The UCF pin assignment.
## 7 segment display
#7led
NET "a_to_g<0>" LOC = "H14";
NET "a_to_g<1>" LOC = "J17";
NET "a_to_g<2>" LOC = "G14";
NET "a_to_g<3>" LOC = "D16";
NET "a_to_g<4>" LOC = "D17";
NET "a_to_g<5>" LOC = "F18";
NET "a_to_g<6>" LOC = "L18";
NET "btn<0>" LOC ="B18";
NET "btn<1>" LOC ="D18";
NET "btn<2>" LOC ="E18";
NET "btn<3>" LOC ="H13";
#=================
#NET "sel<0>" LOC = "F17";
#NET "sel<1>" LOC = "H17";
#NET "sel<2>" LOC = "C18";
#NET "sel<3>" LOC = "F15";
# clock pin for Nexys 2 Board
NET "clk" LOC = "B8"; # Bank = 0, Pin name = IP_L13P_0/GCLK8, Type = GCLK, Sch name = GCLK0
NET "reset_n" LOC = T3;