`include "master_rom.v"
+`include "i2c.v"
+`include "uart.v"
`ifdef SIM
`define UART_DIVIDE 1
// s/192/3/ for 19200 baud uart
`endif
-module master(input CLKin, output [4:0] led, output uart_tx, input uart_rx, output reg ready_out = 1, input ready_in);
- wire clk;
- wire clk_tmp;
+module master(input CLKin, output [4:0] led, output uart_tx, input uart_rx, output reg ready_out = 1, input ready_in, output scl, output sda);
+// wire clk;
+// wire clk_tmp;
//pll pll (.clock_in(CLKin), .clock_out(clk));
reg [20:0] counter = 0;
+`ifdef SIM
+ wire clk = CLKin;
+`else
reg clk = 0;
always @ (posedge CLKin) begin
else
counter <= counter + 1;
end
+`endif
reg [3:0] program_counter = 0;
wire [31:0] rom_output;
master_rom master_rom (.clk(clk), .addr(program_counter), .data(rom_output));
+ reg [7:0] i2c_tx_byte;
+ reg i2c_transmit = 0;
+ wire i2c_is_transmitting;
+
+ i2c_write i2c (.clk(clk), .scl(scl), .sda(sda), .tx_byte(i2c_tx_byte), .transmit(i2c_transmit), .is_transmitting(i2c_is_transmitting));
+
+ reg [3:0] i2c_init_step = 0;
+
+ always @ (posedge clk) begin
+ if(i2c_is_transmitting || i2c_transmit)
+ i2c_transmit <= 0;
+ else begin
+ if(i2c_init_step == 0) begin
+ i2c_tx_byte <= 8'h21; // turn on oscillator
+ i2c_transmit <= 1;
+ i2c_init_step <= 1;
+ end else if(i2c_init_step == 1) begin
+ i2c_tx_byte <= 8'h87; // display on, blink 0.5Hz
+ i2c_transmit <= 1;
+ i2c_init_step <= 2;
+ end else if(i2c_init_step == 2) begin
+ i2c_tx_byte <= 8'hEF; // max brightness
+ i2c_transmit <= 1;
+ i2c_init_step <= 3;
+ end
+ end
+ end
+
`define STATE_SEND 0
`define STATE_WAIT_PROPAGATE 1
reg [7:0] saved_news [3:0];
assign led[4] = state != `STATE_WASTE_TIME;
- assign led[3:0] = 0;
+ assign led[3:0] = i2c_init_step;
always @(posedge clk) begin
case(state)
- receive the instruction back
- receive the news
- propagate the news
- - go back to `STATE_SEND
+ - go to `STATE_WASTE_TIME
*/
if(uart_ptr == 8) begin
state <= `STATE_PROPAGATE_NEWS;