-
Notifications
You must be signed in to change notification settings - Fork 0
/
uart_tx.vhd
78 lines (65 loc) · 1.65 KB
/
uart_tx.vhd
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
---------------------------------------
---------------------------------------
-- UART_TX algorithm with VHDL --
-- Engineer: Sajad Hamzenejadi --
-- 2018 --
---------------------------------------
---------------------------------------
library ieee;
use ieee.std_logic_1164.all;
-- UART Transmitter --
entity uart_tx is
generic (
fullbit : integer );
port (
clk : in std_logic;
reset : in std_logic;
--
din : in std_logic_vector(7 downto 0);
wr : in std_logic;
busy : out std_logic;
--
txd : out std_logic );
end uart_tx;
-- Implemenattion --
architecture rtl of uart_tx is
constant halfbit : integer := fullbit / 2;
-- Signals --
signal bitcount : integer range 0 to 10;
signal count : integer range 0 to fullbit;
signal shiftreg : std_logic_vector(7 downto 0);
begin
proc: process(clk, reset)
begin
if reset='1' then
count <= 0;
bitcount <= 0;
busy <= '0';
txd <= '1';
elsif clk'event and clk='1' then
if count/=0 then
count <= count - 1;
else
if bitcount=0 then
busy <= '0';
if wr='1' then -- START BIT --
shiftreg <= din;
busy <= '1';
txd <= '0';
bitcount <= bitcount + 1;
count <= fullbit;
end if;
elsif bitcount=9 then -- STOP BIT --
txd <= '1';
bitcount <= 0;
count <= fullbit;
else -- DATA BIT --
shiftreg(6 downto 0) <= shiftreg(7 downto 1);
txd <= shiftreg(0);
bitcount <= bitcount + 1;
count <= fullbit;
end if;
end if;
end if;
end process;
end rtl;