Guest User

Untitled

a guest
Dec 11th, 2018
71
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.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 Count10UpDn is
  7. Port(CLR,DIR,p127 : in STD_LOGIC;
  8. com : out STD_LOGIC_VECTOR (3 downto 0);
  9. Y : out STD_LOGIC_VECTOR (6 downto 0));
  10. end Count10UpDn;
  11.  
  12. architecture Behavioral of Count10UpDn is
  13.  
  14. component BCD7seg
  15. Port (A : in STD_LOGIC_VECTOR (3 downto 0);
  16. Y : out STD_LOGIC_VECTOR (6 downto 0));
  17. end component;
  18.  
  19. signal Q0T,Q1T : STD_LOGIC_VECTOR (3 downto 0):="0000";
  20. signal X : STD_LOGIC_VECTOR (3 downto 0);
  21. signal xx : STD_LOGIC_VECTOR (9 downto 0);
  22. signal modc : STD_LOGIC_VECTOR (26 downto 0):="000000000000000000000000000";
  23. signal sent : STD_LOGIC_VECTOR (1 downto 0):="00";
  24. signal tick : STD_LOGIC ;
  25. begin
  26.  
  27. process(tick,CLR)
  28. begin
  29. if CLR='1' then
  30. Q0T <= "0000";
  31. Q1T <= "0000";
  32. elsif tick'event and tick='1' then
  33. if DIR='1' then
  34. if Q0T>=9 then
  35. Q0T <="0000";
  36. Q1T <= Q1T+1;
  37. if Q1T>=9 then
  38. Q1T <= "0000";
  39. end if;
  40. else Q0T <= Q0T+1;
  41. end if;
  42. elsif DIR='0' then
  43. if Q0T<=0 then
  44. Q0T <="1001";
  45. if Q1T <=0 then
  46. Q1T <= "1001";
  47. else Q1T <=Q1T-1;
  48. end if;
  49. else Q0T <= Q0T-1;
  50. end if;
  51. end if;
  52. end if;
  53. end process;
  54. ---------------clock 1hz----------------
  55. process(p127)
  56. begin
  57. if p127'event and p127 ='1' then
  58. if modc<=12499999 then
  59. modc <= modc+1;
  60. tick <= '0';
  61. else
  62. tick <='1';
  63. modc<= "000000000000000000000000000";
  64. end if;
  65. end if;
  66. end process;
  67. -----------------------------------------
  68.  
  69. ----------------mod clock----------------
  70.  
  71. process(p127)
  72. begin
  73. if p127'event and p127 ='1' then
  74. if xx>1000 then xx<= "0000000000";
  75. if sent>=4 then sent<="00";
  76. else sent<=sent+1;
  77. end if;
  78. else xx<=xx+1;
  79. end if;
  80. end if;
  81. end process;
  82.  
  83. -------------- mux2to1 --------------
  84. X<= Q0T when sent ="01" else
  85. Q1T when sent ="10" else
  86. "0000";
  87. -------------- 1to2decoder-------------
  88. com <= "1110" when sent ="01" else
  89. "1101" when sent ="10" else
  90. "1111" ;
  91. --------------7segment-------------
  92. Display : BCD7seg port map(A=>X,Y=>Y);
  93.  
  94. end Behavioral;
Add Comment
Please, Sign In to add comment