module LEDsegDriver(clk,reset,AN,CH,inputVal);
input clk;
input reset;
output [3:0]AN;
output [7:0]CH;
input [15:0] inputVal;

reg [3:0] AN;
reg [7:0]CH;
reg [1:0] SN;
wire [7:0] leda,ledb,ledc,ledd;

reg [15:0] POV_Counter;
parameter POV_Max = 16500;
parameter nullCode = 8'b11111111;

led8SegDecoder led0(clk,inputVal[3:0],leda);
led8SegDecoder led1(clk,inputVal[7:4],ledb);
led8SegDecoder led2(clk,inputVal[11:8],ledc);
led8SegDecoder led3(clk,inputVal[15:12],ledd);

 always @ (posedge clk or posedge reset) begin
	if(reset) begin
		
		POV_Counter = 0;
		SN = 0;
	end
	else if(POV_Counter == POV_Max) begin
		 SN=SN+1;
		 POV_Counter = 0;
	end 
	else	begin
		POV_Counter = POV_Counter+1;
	end
end

always @ (SN or leda or ledb or ledc or ledd) begin
	if (SN==0) begin
		AN=4'b0001;
		CH=leda;
	end
	else if (SN==1) begin
		AN=4'b0010;
		CH=ledb;
	end
	else if (SN==2) begin
		AN=4'b0100;
		CH=ledc;
	end
	else begin
		AN=4'b1000;
		CH=ledd;
	end
end
endmodule

module led8SegDecoder(clk,in,out);

input clk;
input [3:0] in;
output [7:0] out;
reg [7:0] out;

always @ (posedge clk) begin
  case(in)
   	0:  out=8'b00000011;
	1:  out=8'b10011111;
	2:  out=8'b00100101;
	3:  out=8'b00001101;
	4:  out=8'b10011001;
	5:  out=8'b01001001;
	6:  out=8'b01000001;
	7:  out=8'b00011111;
	8:  out=8'b00000001;
	9:  out=8'b00001001;
	10: out=8'b00010001;
	11: out=8'b11000001;
	12: out=8'b01100011;
	13: out=8'b10000101;
	14: out=8'b01100001;
	15: out=8'b01110001;	
  endcase
end


endmodule