-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathuart_demo.v
85 lines (77 loc) · 2.38 KB
/
uart_demo.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
78
79
80
81
82
83
84
85
`timescale 1ns / 1ps
/*
* Copyright 2015 Forest Crossman
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/
`include "ipcore_dir/osdvu/uart.v"
`include "ipcore_dir/mimas_v2_hex_display/display_hex_byte.v"
module uart_demo(
input CLK_100MHz,
input [5:0] Switch,
input Rx,
output Tx,
output reg [0:7] LED,
output [7:0] SevenSegment,
output [2:0] SevenSegmentEnable
);
wire reset;
reg transmit;
reg [7:0] tx_byte;
wire received;
wire [7:0] rx_byte;
wire is_receiving;
wire is_transmitting;
wire recv_error;
reg [7:0] display_byte; // The byte to be displayed
assign reset = ~Switch[2]; // Switch is active low
display_hex_byte #(
.refresh_rate(1000),
.sys_clk_freq(100000000)
)
hex_display(
.clk(CLK_100MHz),
.hex_byte(display_byte),
.segments(SevenSegment),
.segments_enable(SevenSegmentEnable)
);
uart #(
.baud_rate(19200), // This must always be 19200
.sys_clk_freq(100000000) // The master clock frequency
)
uart0(
.clk(CLK_100MHz), // The master clock for this module
.rst(reset), // Synchronous reset
.rx(Rx), // Incoming serial line
.tx(Tx), // Outgoing serial line
.transmit(transmit), // Signal to transmit
.tx_byte(tx_byte), // Byte to transmit
.received(received), // Indicated that a byte has been received
.rx_byte(rx_byte), // Byte received
.is_receiving(is_receiving), // Low when receive line is idle
.is_transmitting(is_transmitting),// Low when transmit line is idle
.recv_error(recv_error) // Indicates error in receiving packet.
);
always @(posedge CLK_100MHz) begin
if (received) begin
display_byte <= rx_byte;
tx_byte <= rx_byte;
LED <= rx_byte;
transmit <= 1;
end
if (is_transmitting) begin
transmit <= 0;
end
end
endmodule