Advertisement
Guest User

Untitled

a guest
May 23rd, 2019
147
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
VHDL 3.95 KB | None | 0 0
  1. ----------------------------------------------------------------------------------
  2. -- Company:
  3. -- Engineer:
  4. --
  5. -- Create Date:    20:11:46 05/22/2019
  6. -- Design Name:
  7. -- Module Name:    rs232 - Behavioral
  8. -- Project Name:
  9. -- Target Devices:
  10. -- Tool versions:
  11. -- Description:
  12. --
  13. -- Dependencies:
  14. --
  15. -- Revision:
  16. -- Revision 0.01 - File Created
  17. -- Additional Comments:
  18. --
  19. ----------------------------------------------------------------------------------
  20. library IEEE;
  21. use IEEE.STD_LOGIC_1164.ALL;
  22. use IEEE.STD_LOGIC_ARITH.ALL;
  23. use IEEE.STD_LOGIC_UNSIGNED.ALL;
  24.  
  25. ---- Uncomment the following library declaration if instantiating
  26. ---- any Xilinx primitives in this code.
  27. --library UNISIM;
  28. --use UNISIM.VComponents.all;
  29.  
  30. entity rs232 is
  31.     Port ( clk_i : in  STD_LOGIC;
  32.            rst_i : in  STD_LOGIC;
  33.            RXD_i : in  STD_LOGIC;
  34.               led : out STD_LOGIC_VECTOR(7 downto 0);
  35.            TXD_o : out  STD_LOGIC := '1');
  36. end rs232;
  37.  
  38. architecture Behavioral of rs232 is
  39. signal data : STD_LOGIC_VECTOR(7 downto 0):=(others => '0');
  40. signal flipflop: std_logic := '1';
  41. signal slopping_edge: std_logic := '0';
  42. signal RXD_now: std_logic;
  43. signal RXD_before: std_logic;
  44. signal data_receiving: std_logic := '0';
  45. signal data_sending: std_logic := '0';
  46. --signal RXD_index: integer := 0;
  47.  
  48. begin
  49.  
  50. led <= data;
  51. receiver: process(clk_i, rst_i)
  52. variable counter : integer := 0;
  53. variable RXD_index : integer := 0;
  54. begin
  55.     if rst_i = '1' then
  56.      flipflop <= '1';
  57.      RXD_now <= '1';
  58.      RXD_before <= '1';
  59.      slopping_edge <= '0';
  60.      counter := 0;
  61.      RXD_index := 0;
  62.      data_receiving <= '0';
  63.      data <= (others => '0');
  64.      elsif rising_edge(clk_i) then
  65.         flipflop <= RXD_i;
  66.           RXD_now <= flipflop;
  67.         if RXD_now = '0' and RXD_before = '1' and data_receiving = '0' then
  68.             slopping_edge <= '1'; --opadajace
  69.         end if;
  70.          
  71.          if slopping_edge = '1' then
  72.             if counter = 2604 and RXD_now = '0' then
  73.                 data_receiving <= '1';
  74.                 counter := -1;
  75.             end if;
  76.                 counter := counter + 1;
  77.          end if;
  78.         if data_receiving = '1' then
  79.             slopping_edge <= '0';
  80.             if counter = 5208 then
  81.                 data(RXD_index) <= RXD_now;
  82.                 RXD_index := RXD_index + 1;
  83.                 counter := -1;
  84.                 if RXD_index = 8 then
  85.                     RXD_index := 0;
  86.                     data_receiving <= '0';
  87.                 end if;
  88.             end if;
  89.             counter := counter + 1;
  90.         end if;
  91.      RXD_before <= RXD_now;
  92.      end if;
  93. end process;
  94.  
  95. transmiter: process(clk_i, rst_i)
  96. variable counter : integer := 0;
  97. variable TXD_index : integer := 0;
  98. begin
  99.     if rst_i = '1' then
  100.     data_sending <= '0';
  101.     counter := 0;
  102.     TXD_index := 0;
  103.     TXD_o <= '1';
  104.     elsif(rising_edge(clk_i)) then
  105.     if(data_receiving = '0' and data /= "00000000") then
  106.         if(data_sending = '0') then
  107.             TXD_o <= '0';
  108.             data_sending <= '1';
  109.             --counter := 0;
  110.         else
  111.             TXD_o <= '1';
  112.            
  113.         end if;
  114.     end if;
  115.    
  116.     if(data_sending = '1' and counter = 5208) then
  117.         if counter = 5208 then
  118.             if TXD_index = 8 then
  119.                 TXD_index := 0;
  120.                 TXD_o <= '1';
  121.                 data_sending <= '0';           
  122.             else       
  123.             TXD_o <= data(TXD_index);
  124.             TXD_index := TXD_index + 1;
  125.             end if;
  126.             counter := 0;
  127.         else counter := counter +1;
  128.         end if;
  129.     end if;
  130.     end if;
  131. --  if(data_receiving = '0') then
  132. --      case TXD_index is
  133. --      when 0 => TXD_o <= '0';
  134. --      TXD_index := TXD_index + 1;
  135. --      when 1 to 8 => if counter = 5208 then TXD_o <= data(TXD_index-1);
  136. --      TXD_index := TXD_index + 1;
  137. --      end if;
  138. --      when others => if counter = 5208 then TXD_o <= '1';
  139. --      counter := -1;
  140. --      TXD_index := 0;
  141. --      end if;
  142. --      end case;
  143. --      counter := counter + 1;
  144. --  end if;
  145. -- 
  146. --  if(data_receiving = '0') then
  147. --      if TXD_index = 0 then
  148. --          TXD_o <= '0';
  149. --          TXD_index := 1;
  150. --          --start <= '1';
  151. --      elsif TXD_index 1 to 8 then
  152. --          if(counter = 5208) then
  153. --              TXD_o <= data(TXD_index);
  154. --              counter := 0;
  155. --          else
  156. --              counter := counter + 1;
  157. --          end if;
  158. --      else
  159. --          TXD_o <= '1';
  160. --      end if;
  161. --  else
  162. --      TXD_o <= '1';
  163. --  end if;
  164. end process;
  165. end Behavioral;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement