Advertisement
Guest User

Untitled

a guest
Nov 8th, 2018
102
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
VHDL 0.84 KB | None | 0 0
  1. library ieee;
  2. use ieee.std_logic_1164.all;
  3. use ieee.numeric_std.all;
  4. entity bcd_counter is
  5. port( up,en,clk,clr :in std_logic;
  6.      bcd_out: out std_logic_vector( 3 downto 0));
  7. end bcd_counter;
  8.  
  9. architecture behaviour of bcd_counter is
  10. signal buffer_bcd : unsigned( 3 downto 0 );
  11. begin
  12.  bcd_out<= std_logic_vector(buffer_bcd);
  13.  clk_in: process(clk,clr)
  14.     begin
  15.         if(clr = '1') then buffer_bcd<="0000";
  16.         else if (en= '1' ) then
  17.                 if (rising_edge(clk)) and (up='1') then
  18.                     if (buffer_bcd="1001") then buffer_bcd <="0000";
  19.                     else buffer_bcd<= buffer_bcd+1;
  20.                     end if;
  21.                 else if ( rising_edge(clk)) and (up='0') then
  22.                     if (buffer_bcd="0000") then buffer_bcd <="1001";
  23.                     else buffer_bcd <= buffer_bcd-1;
  24.                     end if;
  25.                 end if;
  26.                 end if;
  27.         end if;
  28.         end if;
  29.     end process clk_in;
  30. end behaviour;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement