-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtop.v
77 lines (66 loc) · 1.49 KB
/
top.v
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
70
71
72
73
74
75
76
77
`default_nettype none
module top(
clk,
TX,
RX,
/* SW[0]: reset
* SW[1]: i_tx_start for transmitter
* SW[2]: send r_data back to computer
* */
SW,
LED_R,
LED_G,
LED_B
);
input wire clk;
input wire RX;
input wire[3:0] SW;
output wire TX;
output wire LED_R;
output wire LED_G;
output wire LED_B;
parameter reg[7:0] ASCII_START = 8'd32;
parameter reg[7:0] ASCII_END = 8'd126;
reg[7:0] uart_tx_byte = ASCII_START;
reg[7:0] next_byte = ASCII_START;
wire[7:0] r_data;
wire baud_clk;
wire LED_R_inv;
wire LED_B_inv;
assign LED_R = ~LED_R_inv;
assign LED_G = SW[1];
assign LED_B = ~LED_B_inv;
clock baud(
.i_clk(clk),
.i_rst(~SW[0]),
.o_clk(baud_clk)
);
transmitter uart_tx(
.i_clk(baud_clk),
.i_tx_start(~SW[1]),
.busy(LED_R_inv),
.i_data(uart_tx_byte),
.o_data(TX)
);
receiver uart_rx(
.i_clk(clk),
.i_rx(RX),
.i_rst(~SW[0]),
.o_data(r_data),
.ready(LED_B_inv)
);
always @ (posedge LED_R_inv) begin
uart_tx_byte <= next_byte;
end
always @ (posedge baud_clk) begin
if (~SW[2]) begin
next_byte <= r_data;
end else begin
if (uart_tx_byte == ASCII_END) begin
next_byte <= ASCII_START;
end else begin
next_byte <= uart_tx_byte + 1;
end
end
end
endmodule