`timescale 1ns / 1ps
//////////////////////////////////////////////////////////////////////////////////
// Company: 
// Engineer: 
// 
// Create Date:    11:08:05 02/11/2015 
// Design Name: 
// Module Name:    top 
// Project Name: 
// Target Devices: 
// Tool versions: 
// Description: 
//
// Dependencies: 
//
// Revision: 
// Revision 0.01 - File Created
// Additional Comments: 
//
//////////////////////////////////////////////////////////////////////////////////
module test(
		input osc,
		input IR_Remote_Sig,
		input RXD,
		output TXD,
		output rs,
		output en,
		output [7:0]data,
		output reg Buzz
    );
wire [30:0]PrintfData1;
//wire [31:0]PrintfData2;
//wire [31:0]PrintfData3;
//wire [31:0]PrintfData4;
//wire [31:0]PrintfData5;
wire clk_main;
wire clk_fb, clk_fb2;
reg [1:0]reset_cnt = 0;
reg reset = 1'b1;
reg [7:0]OldData=0;
reg ChangeData=0;
parameter S0=0, S1=1, S2=2, S3=3, S4=4, S5=5, S6=6, S7=7, S8=8, S9=9, S10=10, S11=11, S12=12, S13=13;
always@(posedge clk_main)
begin
	if(reset==1'b1)
	begin
		OldData <= 8'd0;
	end 
	else if(OldData!=PrintfData1[7:0])
	begin
		OldData <= PrintfData1[7:0];
		ChangeData <= 1'b1;
	end
	else ChangeData <= 1'b0;
end 
reg [3:0]state = 0;
reg [31:0]cnt = 0;
always@(posedge clk_main)
begin
	if(reset==1'b1)
	begin
		cnt <= 16'd0;
		state <= S0;
		Buzz <= 1'b0;
	end 
	else 
	begin
		case(state)
		S0:
		begin
			if(ChangeData)
			begin
				state <= S1;
			end 
		end
		S1:
		begin
			Buzz <= 1'b1;
			if(cnt == 32'd15000000)
			begin
				state <= S2;
				cnt <= 32'd0;
			end
			else cnt <= cnt + 1'b1;
		end
		S2:
		begin
			Buzz <= 1'b0;
			state <= S0;
		end 
		endcase
	end 
end 

always@(posedge osc)
begin
	if(reset==1'b1)
	begin
	reset_cnt <= reset_cnt + 1'b1;
	end 
	if(reset_cnt==2)
	begin
	reset <= 1'b0;
	end
end 
IR_Receiver IR
(
	.clk_main(osc),   
	.reset(reset),	 
	.IR_Remote_Sig(IR_Remote_Sig),
	.PrintfData(PrintfData1)

);
USB Printf(
	.clk_main(osc),   
	.reset(reset),	 
	.RXD(RXD),
	.TXD(TXD),
	.PrintfData1(PrintfData1)
//	.PrintfData2(PrintfData2),
//	.PrintfData3(PrintfData3),
//	.PrintfData4(PrintfData4),
//	.PrintfData5(PrintfData5)
);

LCD TextLcd
(
	.clk(osc),
	.reset(reset),	 
	.lcd_rs(rs),
	.lcd_en(en),
	.lcd_data(data),
	.string_data(PrintfData1[7:0])
);
endmodule
