⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 counter_conversion.txt

📁 有C编写的红绿灯的控制
💻 TXT
字号:
-- Counter using a Conversion Function
-- This counter uses a natural number to hold the count value and converts it into a bit_vector for output. Illustrates the use of a function.
-- 4-bit binary up counter with asynchronous reset 2/2/93
-- dowload from: www.fpga.com.cn & www.pld.com.cn

library ieee;
use ieee.std_logic_1164.all;

ENTITY cntr4bit IS
   PORT(reset,clock : IN BIT; count : OUT BIT_VECTOR(0 TO 3));
END cntr4bit;

ARCHITECTURE dataflow OF cntr4bit IS

   --interface function to generate output bit_vector from 
   --internal count value.
   FUNCTION nat_to_bv(input : NATURAL; highbit : POSITIVE) 
                                       RETURN BIT_VECTOR IS
      VARIABLE temp : NATURAL := 0;
      VARIABLE output : BIT_VECTOR(0 TO highbit);
   BEGIN
      temp := input;
      --check that input fits into (highbit+1) bits
      ASSERT (temp <= (2**(highbit + 1) - 1))
      REPORT "input no. is out of range" SEVERITY ERROR;
      --generate bit values
      FOR i IN highbit DOWNTO 0 LOOP
          IF temp >= (2**i)
          THEN output(i) := '1';
          temp := temp - (2**i);
          ELSE output(i) := '0';
          END IF;
      END LOOP;
      RETURN output;
   END nat_to_bv;

   --signal to hold current count value
   SIGNAL intcount : NATURAL := 0;

BEGIN
   --conditional natural signal assignment models counter
   intcount <= 0 WHEN (reset = '1') ELSE
            ((intcount + 1) MOD 16) WHEN (clock'EVENT AND clock = '1')
            ELSE intcount;
   --interface function converts natural count to bit_vector count
   count <= nat_to_bv(intcount,3);
END;



⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -