Advertisement
Guest User

Untitled

a guest
May 23rd, 2019
123
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
VHDL 1.60 KB | None | 0 0
  1. library IEEE;
  2. use IEEE.STD_LOGIC_1164.ALL;
  3. use IEEE.STD_LOGIC_ARITH.ALL;
  4. use IEEE.STD_LOGIC_UNSIGNED.ALL;
  5.  
  6. entity vhd is
  7.     Port (
  8.         clk_i : in std_logic;
  9.         TXD_o : out std_logic := '1';
  10.         RXD_i : in std_logic
  11.         );
  12. end vhd;
  13.  
  14. architecture Behavioral of vhd is
  15. signal data : std_logic_vector(7 downto 0) := "00000000";
  16. begin
  17. process (clk_i)
  18.  
  19. variable counter : integer range 0 to 5208 := 0;
  20. variable index : integer range -1 to 8 := 0;
  21. variable receive : boolean := false;
  22. variable send : boolean := false;
  23. variable half : boolean := false;
  24.  
  25. begin
  26.  
  27. if rising_edge(clk_i) then
  28.     counter := counter + 1;
  29.    
  30.     if (receive = false and RXD_i = '0' and send = false) then
  31.         counter := 0;
  32.         index := 0;
  33.         receive := true;
  34.     end if;
  35.    
  36.     if (receive = true and half = false and counter > 2000 and counter < 3000) then
  37.         half := true;
  38.         counter := 0;
  39.     end if;
  40.  
  41.     if (receive = true) then
  42.         if (counter = 5208 and index < 8 and index > -1) then
  43.             data(index) <= RXD_i;
  44.             counter := 0;
  45.             index := index + 1;
  46.         elsif (counter = 5208 and index = 8) then
  47.             counter := 0;
  48.             index := -1;
  49.             send := true;
  50.             receive := false;
  51.             --data <= data + x"20";
  52.             half := false;
  53.         end if;
  54.     end if;
  55.  
  56.     if (send = true) then
  57.         if(index = -1) then
  58.             TXD_o <= '0';
  59.             index := index + 1;
  60.             counter := 0;
  61.         elsif(counter = 5208 and index < 8 and index > -1) then
  62.             TXD_o <= data(index);
  63.             counter := 0;
  64.             index := index + 1;
  65.         elsif (counter = 5208 and index = 8) then
  66.             TXD_o <= '1';
  67.             counter := 0;
  68.             index := 0;
  69.             send := false;
  70.         end if;
  71.     end if;
  72.  
  73. end if;
  74. end process;
  75. end Behavioral;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement