module Sender (serial_CLK, reset, send, charToSend, ack, TxD); input serial_CLK; input reset; input send; // signal to start sending a character, handshake with ack input [7:0] charToSend; // 8-bit character to be sent out serially output ack; // handshake with send output TxD; // serial line on which to send data reg TxD; // register alias for RS232 line reg [7:0] charToSendBuffer; // holds 8-bit character to be sent over the serial line reg [4:0] bitCounter; // keeps count of which bit is being sent reg sending; // indicator to start sending character reg [1:0] cycleCounter; always @(posedge serial_CLK) begin if (reset) begin TxD <= 1; sending <=0; end else begin if (send) begin // load character sent from keypad and hold it just in case // reset bitCounter to zero for start of new transmission and set sending charToSendBuffer <= charToSend; bitCounter <= 0; sending <= 1; cycleCounter <= 0; end else // if sending, its time to send the next bit of the 10 to be sent - // start bit, 8 bits of character to send (most significant bit first), // and a stop bit at the end - reset go when done if (sending) begin // every four cycles if(cycleCounter == 0) begin bitCounter <= bitCounter + 1; if (bitCounter == 0) TxD <= 0; else if (bitCounter > 0 && bitCounter <= 8) TxD <= charToSendBuffer[bitCounter - 1]; else if (bitCounter > 8) begin TxD <= 1; sending <= 0; end end cycleCounter <= cycleCounter + 1; end end end assign ack = sending; endmodule