+ always @(posedge pixclk)
+ begin
+ if(tx_newdata) begin
+ tx_data <= char;
+ tx_state <= 4'b0000;
+ tx_busy <= 1;
+ end else if (tx_clkdiv == 0) begin
+ tx_state <= tx_state + 1;
+ if (tx_busy)
+ case (tx_state)
+ 4'b0000: serial <= 0;
+ 4'b0001: serial <= tx_data[0];
+ 4'b0010: serial <= tx_data[1];
+ 4'b0011: serial <= tx_data[2];
+ 4'b0100: serial <= tx_data[3];
+ 4'b0101: serial <= tx_data[4];
+ 4'b0110: serial <= tx_data[5];
+ 4'b0111: serial <= tx_data[6];
+ 4'b1000: serial <= tx_data[7];
+ 4'b1001: serial <= 1;
+ 4'b1010: tx_busy <= 0;
+ default: $stop;
+ endcase
+ end
+
+ if(tx_newdata || (tx_clkdiv == `CLK_DIV))
+ tx_clkdiv <= 0;
+ else
+ tx_clkdiv <= tx_clkdiv + 1;
+ end