-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathuart_tx.v
More file actions
69 lines (66 loc) · 1.79 KB
/
Copy pathuart_tx.v
File metadata and controls
69 lines (66 loc) · 1.79 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
module uart_tx (
input wire clk,
input wire rst,
input wire tx_start,
input wire [7:0] tx_data,
input wire tick,
output reg tx,
output reg tx_busy
);
localparam IDLE = 0,
START_BIT = 1,
DATA_BITS = 2,
STOP_BIT = 3;
reg [1:0] current_state, next_state;
reg [3:0] bit_counter;
reg [7:0] tx_shift_reg;
always @(posedge clk or posedge rst) begin
if (rst) begin
current_state <= IDLE;
tx <= 1;
tx_busy <= 0;
bit_counter <= 0;
tx_shift_reg <= 0;
end else begin
current_state <= next_state;
end
end
always @(*) begin
next_state = current_state;
case (current_state)
IDLE: begin
tx = 1;
tx_busy = 0;
if (tx_start) begin
tx_shift_reg = tx_data;
next_state = START_BIT;
end
end
START_BIT: begin
tx = 0;
tx_busy = 1;
if (tick) begin
next_state = DATA_BITS;
bit_counter = 0;
end
end
DATA_BITS: begin
tx = tx_shift_reg[bit_counter];
if (tick) begin
if (bit_counter == 7) begin
next_state = STOP_BIT;
end else begin
bit_counter = bit_counter + 1;
end
end
end
STOP_BIT: begin
tx = 1;
if (tick) begin
next_state = IDLE;
end
end
default: next_state = IDLE;
endcase
end
endmodule