Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- LIBRARY IEEE;
- USE IEEE.std_logic_1164.ALL;
- USE IEEE.numeric_std.ALL;
- ENTITY rs232_tx IS
- PORT(clk: IN std_logic;
- tx: OUT std_logic;
- rst: IN std_logic;
- fifo_empty: IN std_logic;
- fifo_RdEn, fifo_RdClock: OUT std_logic;
- fifo_data: IN STD_LOGIC_VECTOR(7 DOWNTO 0);
- Q: OUT STD_LOGIC_VECTOR(1 DOWNTO 0));
- END rs232_tx;
- ARCHITECTURE working OF rs232_tx IS
- TYPE state IS (idle,start,data);
- SIGNAL tx_pulse: STD_LOGIC := '1';
- SIGNAL s_tick: STD_LOGIC;
- SIGNAL pr_state, nx_state: state := idle;
- SIGNAL data_val: std_logic_vector(7 DOWNTO 0):=(others=>'0');
- SIGNAL data_count: unsigned(2 DOWNTO 0):=to_unsigned(0,3);
- BEGIN
- process(s_tick, rst)
- VARIABLE count: unsigned(3 DOWNTO 0):= to_unsigned(0,4);
- BEGIN
- IF rising_edge(s_tick) THEN
- count := count + to_unsigned(1,4);
- IF count = to_unsigned(15,4) THEN
- tx_pulse <= '1';
- ELSE
- tx_pulse <='0';
- END IF;
- END IF;
- END PROCESS;
- process(tx_pulse,rst)
- BEGIN
- IF rising_edge(tx_pulse) THEN
- IF rst='1' THEN
- pr_state <= idle;
- data_val <= (others=>'0');
- data_count <= to_unsigned(0,3);
- ELSE
- pr_state <= nx_state;
- CASE pr_state IS
- WHEN idle =>
- data_count <= to_unsigned(0,3);
- WHEN data =>
- data_count <= data_count + to_unsigned(1,3);
- WHEN start =>
- data_val <= fifo_data;
- WHEN OTHERS =>
- END case;
- END IF;
- END IF;
- END process;
- process(fifo_empty,rst,data_count,pr_state,data_count)
- BEGIN
- case pr_state is
- when idle =>
- Q <= ('1','1');
- fifo_RdEn <= '0';
- tx <= '1';
- IF fifo_empty='0' AND rst='0' THEN
- nx_state <= start;
- ELSE
- nx_state <= idle;
- END IF;
- WHEN start =>
- Q <= ('1','0');
- fifo_RdEn <= '1';
- tx <= '0';
- nx_state <= data;
- WHEN data =>
- Q <= ('0','1');
- fifo_RdEn <= '0';
- tx <= data_val(to_integer(data_count));
- if data_count=to_unsigned(7,3) then
- nx_state <= idle;
- ELSE
- nx_state <= data;
- end if;
- end case;
- END process;
- fifo_RdClock <= tx_pulse;
- baud_gen: ENTITY work.baud_gen
- PORT MAP(clk,reset=>'0',s_tick=>s_tick);
- END working;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement