-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathuart_demo.v
69 lines (63 loc) · 1.98 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
/*
* 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 "cores/osdvu/uart.v"
module top(
input iCE_CLK,
input RS232_Rx_TTL,
output RS232_Tx_TTL,
output LED0,
output LED1,
output LED2,
output LED3,
output LED4
);
wire reset = 0;
reg transmit;
reg [7:0] tx_byte;
wire received;
wire [7:0] rx_byte;
wire is_receiving;
wire is_transmitting;
wire recv_error;
assign LED4 = recv_error;
assign {LED3, LED2, LED1, LED0} = rx_byte[7:4];
uart #(
.baud_rate(9600), // The baud rate in kilobits/s
.sys_clk_freq(12000000) // The master clock frequency
)
uart0(
.clk(iCE_CLK), // The master clock for this module
.rst(reset), // Synchronous reset
.rx(RS232_Rx_TTL), // Incoming serial line
.tx(RS232_Tx_TTL), // 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 iCE_CLK) begin
if (received) begin
tx_byte <= rx_byte;
transmit <= 1;
end else begin
transmit <= 0;
end
end
endmodule