Advertisement
Guest User

Untitled

a guest
Jul 5th, 2015
225
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
VHDL 2.27 KB | None | 0 0
  1. ----------------------------------------------------------------------------------
  2. -- Company:
  3. -- Engineer: Jonas Otto
  4. --
  5. -- Create Date:    17:16:08 06/01/2015
  6. -- Design Name:
  7. -- Module Name:    transmitter - 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.  
  23. -- Uncomment the following library declaration if using
  24. -- arithmetic functions with Signed or Unsigned values
  25. --use IEEE.NUMERIC_STD.ALL;
  26.  
  27. -- Uncomment the following library declaration if instantiating
  28. -- any Xilinx primitives in this code.
  29. --library UNISIM;
  30. --use UNISIM.VComponents.all;
  31.  
  32. entity transmitter is
  33.     port( CLK : in std_logic;
  34.             RST : in std_logic;
  35.             DIN : in std_logic_vector(7 downto 0);
  36.             SEND : in std_logic;
  37.             TXD : out std_logic;
  38.             LED  : out std_logic_vector (7 downto 0)
  39.     );     
  40. end entity;
  41.  
  42. architecture Behavioral of transmitter is
  43.     type STATE is (STATE_WAIT, STATE_START, STATE_SEND, STATE_STOP);
  44.     signal current_state : STATE;
  45.     signal current_data_bit : integer range 0 to 8;
  46.     signal tickin : std_logic;
  47.    
  48.     component baud_gen is
  49.         port( CLK : in std_logic;
  50.                 RST : in std_logic;
  51.                 TICK : out std_logic);
  52.     end component;
  53.    
  54. begin
  55.  
  56. ticker: baud_gen
  57.     port map(CLK=>CLK, RST=>RST, TICK=>tickin);
  58.  
  59. transmit : process(tickin, RST) is
  60. begin
  61.  
  62.    
  63.     if (tickin'event and tickin = '1') then
  64.         if RST = '1' then
  65.             current_state <= STATE_WAIT;
  66.             current_data_bit <= 0;
  67.         end if;
  68.        
  69.         case current_state is
  70.             when STATE_WAIT =>
  71.                 TXD <= '1';
  72.                 if SEND = '1' then
  73.                     current_state <= STATE_START;
  74.                 end if;
  75.            
  76.             when STATE_START =>
  77.                 TXD <= '0'; -- Startbit
  78.                 current_state <= STATE_SEND;
  79.            
  80.             when STATE_SEND =>
  81.                 TXD <= din(current_data_bit);
  82.                 current_data_bit <= current_data_bit + 1;
  83.                 if(current_data_bit > 7) then
  84.                     current_data_bit <= 0;
  85.                     current_state <= STATE_STOP;
  86.                 end if;
  87.                
  88.             when STATE_STOP =>
  89.                 TXD <= '1'; --Stopbit
  90.                 current_state <= STATE_WAIT;
  91.            
  92.         end case;
  93.        
  94.         LED <= DIN;
  95.     end if;
  96.    
  97. end process;
  98. end architecture;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement