Apparently if I post an at-sign, even in a CODE block, the forum thinks i'm posting a link, even if I untick "Automatically parse links in text". Anyway I replaced them with *AT*
module rs232_send
(
input wire SYSCLK, // 50MHz
input wire RST_B, // reset switch, active low
output reg UART_TX
);
reg COUNTER, COUNTER_N;
wire SER_CLK;
reg TX_STATE, TX_STATE_N;
reg LETTER, LETTER_N;
wire ENABLE;
reg UART_TX_N;
initial
begin
COUNTER <= 0;
TX_STATE <= 0;
TX_STATE_N <= 0;
LETTER <= 7'h21; // start with '!' character
LETTER_N <= 7'h21;
UART_TX <= 1;
end
assign SER_CLK = (COUNTER == 9'd434); // 50MHz / 434 = 115207 (close enough)
assign ENABLE = (LETTER != 7'h7e);
always *AT* (posedge SYSCLK or negedge RST_B)
begin
if(!RST_B)
begin
COUNTER <= 0;
TX_STATE <= 0;
LETTER <= 7'h21;
UART_TX <= 1;
end
else
begin
COUNTER <=# 1 COUNTER_N;
TX_STATE <=# 1 TX_STATE_N;
LETTER <=# 1 LETTER_N;
UART_TX <=# 1 UART_TX_N;
end
end
always *AT* (*)
begin
if(COUNTER == 9'd434)
COUNTER_N = 0;
else
COUNTER_N = COUNTER + 9'h1;
end
always *AT* (*)
begin
if(SER_CLK)
begin
case(TX_STATE)
4'd0: UART_TX_N = 0; // start bit
4'd1: UART_TX_N = LETTER; // first nibble
4'd2: UART_TX_N = LETTER;
4'd3: UART_TX_N = LETTER;
4'd4: UART_TX_N = LETTER;
4'd5: UART_TX_N = LETTER; // second nibble start
4'd6: UART_TX_N = LETTER;
4'd7: UART_TX_N = LETTER;
4'd8: UART_TX_N = 0; // top bit is always zero, as ASCII is 7-bit
4'd9: UART_TX_N = 1; // stop bit
default: UART_TX_N = 1; // idle
endcase
end
else
UART_TX_N = UART_TX;
end
always *AT* (posedge SYSCLK)
begin
if(SER_CLK & ENABLE)
begin
if(TX_STATE == 4'd9)
begin
TX_STATE_N <= 4'h0;
if(LETTER == 7'h7e)
LETTER_N <= 7'h21;
else
LETTER_N <= LETTER + 7'h1;
end
else
begin
TX_STATE_N <= TX_STATE + 4'h1;
LETTER_N <= LETTER;
end
end
end
endmodule