Advertisement
Guest User

Untitled

a guest
May 17th, 2018
122
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.19 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 board is
  7. Port ( clk : in STD_LOGIC;
  8. btn : in STD_LOGIC_VECTOR (4 downto 0);
  9. sw : in STD_LOGIC_VECTOR (15 downto 0);
  10. led : out STD_LOGIC_VECTOR (15 downto 0);
  11. an : out STD_LOGIC_VECTOR (3 downto 0);
  12. cat : out STD_LOGIC_VECTOR (6 downto 0);
  13. tx : out STD_LOGIC;
  14. rx : in STD_LOGIC);
  15. end board;
  16.  
  17. architecture Behavioral of board is
  18.  
  19. signal display : STD_LOGIC_VECTOR(15 downto 0);
  20. signal en : STD_LOGIC_VECTOR(4 downto 0); -- FOR MPG
  21. type state_type is (start, idle, data, stop);
  22. signal state : state_type := idle;
  23. signal tx_data : STD_LOGIC_VECTOR(7 downto 0);
  24. signal tx_en : STD_LOGIC := '0';
  25. signal rst : STD_LOGIC;
  26. signal baud_en : STD_LOGIC;
  27. signal baud_cnt : STD_LOGIC_VECTOR(13 downto 0);
  28. signal tx_rdy : STD_LOGIC;
  29. signal clk_div : STD_LOGIC;
  30. signal bit_cnt : STD_LOGIC_VECTOR(2 downto 0);
  31.  
  32. component mpg is
  33. Port( clk : in STD_LOGIC;
  34. btn : in STD_LOGIC_VECTOR (4 downto 0);
  35. enable : out STD_LOGIC_VECTOR (4 downto 0));
  36. end component;
  37.  
  38. component seven_segments is
  39. Port ( clk : in STD_LOGIC;
  40. digit0, digit1, digit2, digit3 : in STD_LOGIC_VECTOR(3 downto 0);
  41. catod : out STD_LOGIC_VECTOR (6 downto 0);
  42. anod : out STD_LOGIC_VECTOR (3 downto 0));
  43. end component;
  44.  
  45. begin
  46. led <= bit_cnt & sw(12 downto 0);
  47. rst <= en(1);
  48. tx_data <= x"33";-- sw(7 downto 0);
  49.  
  50. mpgU : mpg Port map(
  51. clk => clk,
  52. btn => btn,
  53. enable => en
  54. );
  55. ssd: seven_segments Port map(
  56. digit0 => display(3 downto 0),
  57. digit1 => display(7 downto 4),
  58. digit2 => display(11 downto 8),
  59. digit3 => display(15 downto 12),
  60. clk => clk,
  61. catod => cat,
  62. anod => an
  63. );
  64.  
  65. baud: process(clk)
  66. begin
  67. if rising_edge(clk) then
  68. if baud_cnt = 10415 then
  69. baud_en <= '1';
  70. baud_cnt <= (others => '0');
  71. else
  72. baud_cnt <= baud_cnt + 1;
  73. baud_en <= '0';
  74. end if;
  75. end if;
  76. end process;
  77.  
  78. process(clk, en(0), baud_en)
  79. begin
  80. if rising_edge(clk) then
  81. if en(0) = '1' then
  82. tx_en <= '1';
  83. elsif baud_en = '1' then
  84. tx_en <= '0';
  85. end if;
  86. end if;
  87. end process;
  88.  
  89. -- when en(0) = '1' else '0' when baud_en = '1';
  90.  
  91. process(state, bit_cnt, tx_data)
  92. begin
  93. case state is
  94. when idle => tx <= '1';
  95. tx_rdy <= '1';
  96. when start => tx <= '0';
  97. tx_rdy <= '0';
  98. when data => tx <= tx_data(conv_integer(bit_cnt));
  99. tx_rdy <= '0';
  100. when stop => tx <= '1';
  101. tx_rdy <= '0';
  102. end case;
  103. end process;
  104.  
  105. process(baud_en, clk, rst, tx_en, state)
  106. begin
  107. if rising_edge(clk) then
  108. if baud_en = '1' then
  109. case state is
  110.  
  111. when idle =>
  112. if tx_en = '1' then
  113. state <= start;
  114. bit_cnt <= "000";
  115. else
  116. state <= idle;
  117. bit_cnt <= "000";
  118. end if;
  119. when start =>
  120. state <= data;
  121. bit_cnt <= "000";
  122.  
  123. when data =>
  124. if bit_cnt = "111" then
  125. state <= stop;
  126. bit_cnt <= "000";
  127. else
  128. bit_cnt <= bit_cnt + 1;
  129. state <= stop;
  130. end if;
  131. when stop =>
  132. state <= idle;
  133. bit_cnt <= "000";
  134. end case;
  135. end if;
  136. end if;
  137. end process;
  138.  
  139.  
  140. end Behavioral;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement