You are on page 1of 6

module top(cathode,Anode,switch,button,clk);

output [6:0] cathode;

output [3:0] Anode;

input [7:0] switch;

input [3:0] button;

input clk; //50Mhz

wire referesh_clock;

wire [1:0] refereshcounter;

wire [3:0] one_digit;

//wrapper for clock divider

clock_divider referesh_clock_generator(referesh_clock,clk);

//wrapper for refereshcounter

refershcounter refereshcount_wrapper(referesh_clock,refereshcounter);

//wrapper for Anodecontroller

ancode_control anodecontrol_wrapper(refereshcounter,Anode);

//wrapper BCD control

BCd_control
BCDcontrol_wrapper(one_digit,switch[3:0],switch[7:4],button[3:0],button[3:0],refereshcounter);
//BCDto cathode wrapper

BCD_to_cathode bcdtocathode_wrapper(cathode,one_digit);

Endmodule

module clock_divider(newclk,clk);

output reg newclk;

input clk;

reg [32:0] count =32'b0;

always@(posedge clk)

begin

count = count+1;

newclk =count[17];

end

endmodule

module refershcounter(refersh_clock,refersh_counter);

input refersh_clock;

output reg[1:0] refersh_counter =0;


always@(posedge refersh_clock)

begin

refersh_counter <= refersh_counter+1;

end

endmodule

module ancode_control(referesh_counter,anode);

input [1:0] referesh_counter;

output reg[3:0] anode=0;

always@(referesh_counter)

begin

case(referesh_counter)

2'b00: anode = 4'b1110; // digit 1 on right

2'b01: anode = 4'b1101;

2'b10: anode = 4'b1011;

2'b11: anode = 4'b0111; //left

endcase

end

endmodule

module BCd_control(one_digit,digit1,digit2,digit3,digit4,referesh_counter);

output reg[3:0] one_digit =0;


input [1:0] referesh_counter;

input [3:0] digit1; // rigit led for ones

input [3:0] digit2; // 2nd led for tens

input [3:0] digit3; // 3rd led for hundreds

input [3:0] digit4; // 4th led for thousnad

always@(referesh_counter)

begin

case(referesh_counter)

2'b00 :one_digit <= digit1;

2'b01 :one_digit <= digit2;

2'b10 :one_digit <= digit3;

2'b11 :one_digit <= digit4;

endcase

end
Endmodule

module BCD_to_cathode(cathode,digit);

output reg[6:0] cathode;

input [3:0] digit;

always@(digit)

begin

case(digit)

4'd0 : cathode = 7'b1000000;

4'd1 : cathode = 7'b1111001;

4'd2 : cathode = 7'b0100100;

4'd3 : cathode = 7'b0110000;

4'd4 : cathode = 7'b0011001;

4'd5 : cathode = 7'b0010010;

4'd6 : cathode = 7'b0000010;

4'd7 : cathode = 7'b1111000;

4'd8 : cathode = 7'b0000000;

4'd9 : cathode = 7'b0010000;

default :cathode = 7'b1000000;

endcase

end
endmodule

You might also like