/****************************************************************************** *Engineer: superdian *Create Date: 2014/11/17 *Design Name: *Module Name: pcf8563_top *Project Name: *Target Devices: EP3CE5E144C8 *Tool versions: *Description: * *Dependencies: * *Revision: *Revision 0.01 - File Created *Additional Comments: 开发板晶振为20MHZ,工程中通过倍频50MH。 ******************************************************************************/ module pcf8563_top( input sys_rstn, input sys_clk, output scl, inout wire sda, output lcd_rs , //lcd的寄存器选择输出信号 output lcd_rw , //lcd的读、写操作选择输出信号 output lcd_en , //lcd使能信号 output [7:0] lcd_data //lcd的数据总线(不进行读操作,故为输出) ); wire clk; wire [7:0] data_trans; //从相应寄存器读取的数据 wire finish_bit; //从单个寄存器读取数据完毕的标志 wire allfinish_bit; wire LCDfinish_bit; reg [7:0] data_word; //发送相应寄存器地址 reg [7:0] sec; //储存从秒寄存器读出的数据 reg [7:0] mnt; //储存从分寄存器读出的数据 reg [7:0] hur; //储存从小时寄存器读出的数据 reg [7:0] week; //储存从星期寄存器读出的数据 reg [7:0] day; //储存从日寄存器读出的数据 reg [7:0] month; //储存从月份寄存器读出的数据 reg [7:0] year; //储存从年寄存器读出的数据 reg [7:0] code_ctl; //状态机状态寄存器 parameter sec_time=8'd0; parameter mnt_time=8'd1; parameter hour_time=8'd2; parameter day_time=8'd3; parameter week_time=8'd4; parameter month_time=8'd5; parameter year_time=8'd6; clk_pll clk_pll ( .inclk0(sys_clk), .c0(clk) ); i2c_test i2c_test( .clk(clk), .scl(scl), .sda(sda), .data_read_wire(data_trans), .sda_data_addr(8'ha2), .sda_data_word(data_word), .finish_bit(finish_bit), .allfinish_bit(allfinish_bit), .LCDfinish_bit(LCDfinish_bit), ); lcd1602 lcd1602( .sys_rstn(sys_rstn), .lcd_rs(lcd_rs), .lcd_rw(lcd_rw), .lcd_en(lcd_en), .lcd_data(lcd_data), .sys_clk(clk), .seg_sec(sec), .seg_mnt(mnt), .seg_hur(hur), .seg_week(week), .seg_day(day), .seg_month(month), .seg_year(year), .LCDfinish_bit(LCDfinish_bit), ); always@(posedge clk) begin case(code_ctl) sec_time: begin if((finish_bit|allfinish_bit)==1'b0) begin data_word<=8'h02;//发送秒寄存器地址 sec<=data_trans; end else begin code_ctl<=mnt_time; end end mnt_time: begin if((finish_bit|allfinish_bit)==1'b0) begin data_word<=8'h03;//发送分钟寄存器地址 mnt<=data_trans; end else begin code_ctl<=hour_time; end end hour_time: begin if((finish_bit|allfinish_bit)==1'b0) begin data_word<=8'h04;//发送小时寄存器地址 hur<=data_trans; end else begin code_ctl<=day_time; end end day_time: begin if((finish_bit|allfinish_bit)==1'b0) begin data_word<=8'h05;//发送日寄存器地址 day<=data_trans; end else begin code_ctl<=week_time; end end week_time: begin if((finish_bit|allfinish_bit)==1'b0) begin data_word<=8'h6;//发送星期寄存器地址 week<=data_trans; end else begin code_ctl<=month_time; end end month_time: begin if((finish_bit|allfinish_bit)==1'b0) begin data_word<=8'h07;//发送月寄存器地址 month<=data_trans; end else begin code_ctl<=year_time; end end year_time: begin if((finish_bit|allfinish_bit)==1'b0) begin data_word<=8'h08;//发送年寄存器地址 year<=data_trans; end else begin code_ctl<=sec_time; end end endcase end endmodule