1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
| module clock_divide(clk_out,clk_50);
input clk_50;
output clk_out;
reg[24:0] count; // to count 25 million you need 25 bit counter
reg clk_out;
parameter TC=25'd25000000-25'd1;
initial begin
count=0;
clk_out=0;
end
always @(posedge clk_50)
begin
if (count==0)begin
count <=TC;
clk_out <=~clk_out;
end
else
count<=count-1'b1;
end
endmodule
//module up_counter( out, enable , clk, reset );
output [7:0] out;
input enable, reset, clk;
reg [7:0] out;
//-------------Code Starts Here-------
always @(posedge clk)
if (reset) begin
out <= 8'h0 ;
end else if (enable) begin
out <= out + 1;
end
endmodule
// hex to seven segment decoder
module hexadecimalcounter(hex_1, hex_0, hex_num);
input [3:0] hex_num;
output[6:0] hex_1;
output[6:0] hex_0;
reg [6:0] hex_1;
reg [6:0] hex_0;
always @(hex_num)
begin
case (hex_num)
4'h0: {hex_1, hex_0} = {7'b1111111, 7'b1000000}; // 7-seg for 0
4'h1: {hex_1, hex_0} = {7'b1111111, 7'b1111001} ; // 7-seg for 1
4'h2: {hex_1, hex_0} = {7'b1111111, 7'b0100100} ; // 7-seg for 2
4'h3: {hex_1, hex_0} = {7'b1111111, 7'b0110000} ; // 7-seg for 3
4'h4: {hex_1, hex_0} = {7'b1111111, 7'b0011001} ; // 7-seg for 4
4'h5: {hex_1, hex_0} = {7'b1111111, 7'b0010010} ; // 7-seg for 5
4'h6: {hex_1, hex_0} = {7'b1111111, 7'b0000010} ; // 7-seg for 6
4'h7: {hex_1, hex_0} = {7'b1111111, 7'b1111000} ; // 7-seg for 7
4'h8: {hex_1, hex_0} = {7'b1111111, 7'b0000000} ; // 7-seg for 8
4'h9: {hex_1, hex_0} = {7'b1111111, 7'b0011000} ; // 7-seg for 9
4'ha: {hex_1, hex_0} = {7'b1111001, 7'b1000000} ; // 7-seg for A
4'hb: {hex_1, hex_0} = {7'b1111001, 7'b1111001} ; // 7-seg for B
4'hc: {hex_1, hex_0} = {7'b1111001, 7'b0100100} ; // 7-seg for C
4'hd: {hex_1, hex_0} = {7'b1111001, 7'b0110000} ; // 7-seg for D
4'he: {hex_1, hex_0} = {7'b1111001, 7'b0011001} ; // 7-seg for E
4'hf: {hex_1, hex_0} = {7'b1111001, 7'b0010010} ; // 7-seg for F
default: {hex_1, hex_0} = {7'b1111001, 7'b1111111} ; // 7-segment code for blank
endcase
end
endmodule
// top level module counter_hexa
module counter_hexa( enable, clk_50, reset, hex_1, hex_0, clk_out);
input enable, clk_50, reset;
output [7:0] hex_1, hex_0;
output wire clk_out;
wire [7:0] out;
clock_divide ch_cd(clk_out,clk_50);
up_counter ch_upc(clk_out, reset, enable, out);
hexadecimalcounter ch_hxdc(out, hex_1, hex_0);
endmodule
Here is the code. Hope to hear from you soon.
[COLOR="silver"][SIZE=1]- - - Updated - - -[/SIZE][/COLOR]
sorry, there is a slight change in up counter module, i commented it out...so here is the new code
module up_counter( out, enable , clk, reset );
output [7:0] out;
input enable, reset, clk;
reg [7:0] out;
//-------------Code Starts Here-------
always @(posedge clk)
if (reset) begin
out <= 8'h0 ;
end else if (enable) begin
out <= out + 1;
end
endmodule |