VHDL硬件描述语言(六)VHDL案例

一、常见电路

1、 分频电路

 1)二分频电路

library ieee;
use ieee.std_logic_1164.all;
entity example is
 port(clock : in std_logic;
        clkout : out std_logic
      );
end example;

architecture behave of example is
 signal clk: std_logic;
 begin
  process(clock)
   begin
     if rising_edge(clock) then
        clk<=not clk;
     end if;
  end process;
  clkout<=clk;
end behave;


 2)偶数倍分频电路(8分频)

library ieee;
use ieee.std_logic_1164.all;

entity FreDevider is
port
    (clkin : in std_logic;
     clkout : out std_logic
     );
end;

architecture Devider of FreDevider is
constant N :integer := 3;
signal counter : integer range 0 to N;
signal clk : std_logic;
begin
    process(clkin)
    begin
        if rising_edge(clkin) then
            if counter=N then
                counter<=0;
                clk<=not clk;
            else
                counter<=counter+1;
            end if;
        end if;
    end process
    clout<=clk;
end;

3) 奇数倍分频(3分频)

library ieee;
use ieee.std_logic_1164.all;

entity Fredevider3 is
port
        (clkin : in std_logic;
         clkout : out std_logic
        );
end;

architecture Devider of Fredevider3 is
signal counter :integer range 0 to 2;
signal temp1,temp2 : std_logic;
begin
    process(clkin)
    begin
        if rising_edge(clkin) then
            if counter=2 then
                counter<=0;
                temp1<=not temp1;
            else
                counter<=counter+1;
            end if;
        end if;

        if falling_edge(clkin) then
            if counter=1 then
                temp2<=not temp2;
            end if;
        end if;
    end process;
    clkout<=temp1 xor temp2;
end;

2、计数器

library ieee;
use ieee.std_logic_1164.all;

entity example is
 port(clk : in std_logic;
        reset : in std_logic;
        num : buffer integer range 0 to 3
      );
end example;

architecture behave of example is
 begin
  process(clk)
   begin
     if reset='1' then
        num<=0;
     elsif rising_edge(clk) then
        if num=3 then
            num<=0;
        else
            num<=num+1;
        end if;
     end if;
  end process;
end behave;

3、简单并-串转换

library ieee;
use ieee.std_logic_1164.all;

entity example is
 port(clk : in std_logic;
        reset : in std_logic;
        parallelnum : in std_logic_vector(31 downto 0);
        serialout :out std_logic
      );
end example;

architecture behave of example is
 begin
  process(clk)
  variable i :integer range 0 to 31;
   begin
     if reset='1' then
        i:=0;
     elsif rising_edge(clk) then
        serialout<=parallelnum(i);
        
        if i<31 then
            i:=i+1;
        end if;
        
     end if;
  end process;
end behave;

4、时钟产生

(1)方法1

process
begin
    clk <= not clk;
    wait for 10ns;
end process;

(2)方法2

process
begin
    clk <= not clk after 10ns;
    wait on clk;
end process;


(3)方法3

process(clk)
begin
    clk <= not clk after 10ns;
end process;

(4)方法4

clk <= not clk after 10ns;

5、七段数码管驱动电路

11111100
01100001
11011012
11110013
01100114
10110115
10111116
11100007
1111111

8

11110119
library ieee;
use ieee.std_logic_1164.all;

entity example is
port(num : in integer range 0 to 15;
     display : out std_logic_vector(6 downto 0)
    );
end;

architecture behave of example is
begin
    with num select
        display<="1111110" when 0,
                 "0110000" when 1,
                 "1101101" when 2,
                 "1111001" when 3,
                 "0110011" when 4,
                 "1011011" when 5,
                 "1011111" when 6,
                 "1110000" when 7,
                 "1111111" when 8,
                 "1111011" when 9,
                 "0000000" when others;
end

6、同步整形电路

(1)上升沿输出脉冲信号

library ieee;
use ieee.std_logic_1164.all;

entity SignalLatch is
port(clk : in std_logic;
     signalin : in std_logic;
     signalout : out std_logic
    );
end;

architecture Dataflow of SignalLatch is
signal q0,q1 : std_logic;
begin
    process(clk)
    begin
        if rising_edge(clk) then
            q0<=signalin;
            q1<=q0;
        end if;
    end process;
    signalout<=q0 and (not q1);
end;

(2)下降沿处输出脉冲信号

library ieee;
use ieee.std_logic_1164.all;

entity SignalLatch is
port(clk : in std_logic;
     signalin : in std_logic;
     signalout : out std_logic
    );
end;

architecture Dataflow of SignalLatch is
signal clear,s : std_logic;
begin
    process(signalin)
    begin
        if clear='1' then
            s<='0';
        elsif rising_edge(signalin) then
            s<='1';
        end if;
    end process;


    process(clk)
    begin
        if falling_edge(clk) then
            if s='1' then
                signalout<='1';
                clear<='1';
            else
                signalout<='0';
                clear<='0';
            end if;
        end if;
    end process;
end;

7、键盘扫描

列/PC3~PC0(输出)行/PC7~PC4(输入)按键
011111100
011111011
011110112
011101113
101111104
101111015
101110116
101101117
110111108
110111019
11011011A
11010111B
11101110C
11101101D
11101011E
11100111F
library ieee;
use ieee.std_logic_1164.all;

entity Keyboard is
port
(
    clk : in std_logic;
    kin : in std_logic_vector(0 to 3);
    scansignal : out std_logic_vector(0 to 3);
    num : out integer range 0 to 15
);
end;

architecture scan of Keyboard is
signal scans : std_logic_vector(0 to 7);
signal scn : std_logic_vector(0 to 3);
signal counter : integer range 0 to 3;
signal counterB : integer range 0 to 3;
begin
    process(clk)
    begin
        if rising_edge(clk) then
            if counter=3 then
                counter<=0;
            else
                counter<=counter+1;
            end if;
                case counter is            --产生扫描信号
                when 0 =>scn<="1000";
                when 1 =>scn<="0100";
                when 2 =>scn<="0010";
                when 3 =>scn<="0001";
            end case;
        end if;
    end process;

    pocess(clk)
    begin
        if falling_edge(clk) then          --上升沿产生扫描信号,下降沿读入行码
            if kin="0000" then             --“0000”表示无按下
                if counterB=3 then
                    num<=15;                --15为无效值
                    counterB<=0;
                else
                    counterB<=counterB+1;
                end if;
            else
                counterB<=0;
                case scans is
                    when "10000001"=>num<=0;                    
                    when "10000010"=>num<=1;
                    when "10000100"=>num<=2;                    
                    when "10001000"=>num<=3;
                    when "01000001"=>num<=4;                    
                    when "01000010"=>num<=5;
                    when "01000100"=>num<=6;                    
                    when "01001000"=>num<=7;
                    when "00100001"=>num<=8;                    
                    when "00100010"=>num<=9;
                    when "00100100"=>num<=10;                    
                    when "00101000"=>num<=11;
                    when "00010001"=>num<=12;                    
                    when "00010010"=>num<=13;
                    when "00010100"=>num<=14;                    
                    when others=>num<=num;
                end case;
            end if;
        end if;
    end process;
    scans<=scn&kin;
    scansignal<=scn;
end;
         


8、键盘消抖电路

library ieee;
use ieee.std_logic_1164.all;

entity Antitwitter is
port( clk : in std_logic;
      numin : in integer range 0 to 15;
      numout : out integer range 0 to 15);
end;

architecture Behavior of Antitwitter is
signal tempnum integer range 0 to 15;
signal counter : integer range 0 to 31;
signal start : std_logic;
begin
    process(clk)
    begin
        if rising_edge(clk) then 
            if start='0' then
                tempnum<=15;
                numout<=15;
                start<='1'
            else
                if numin /= tempnum then
                    tempnum<=numin;
                    counter<=0;
                else
                    if counter=31 then
                        numout<=numin;
                        counter<=0;
                    else
                        counter<=counter+1;
                    end if;
                end if;
            end if;
        end if;
    end process;
end;

  • 4
    点赞
  • 58
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
VHDL(VHSIC Hardware Description Language)是一种硬件描述语言,用于描述数字电路和系统,被广泛应用于数字电路设计硬件描述的领域。 VHDL语言教程是为了帮助初学者了解和学习VHDL语言的一本指南。它通常包含了VHDL语言的基本概念、语法结构以及常用的设计技巧和方法。 通过VHDL语言教程,学习者可以了解VHDL语言的核心概念,如实体(entity)、体系结构(architecture)和信号(signal),以及它们之间的关系。学习者还可以了解到VHDL语言的基本语法元素,如数据类型、运算符、条件语句和循环语句等等。 在VHDL语言教程中,通常会介绍如何使用VHDL语言来描述数字电路的功能和行为。学习者可以通过教程学习如何使用VHDL语言来实现多种逻辑门和组合逻辑电路,并了解其工作原理和应用。 此外,VHDL语言教程还会介绍如何编写测试台(testbench)来对VHDL设计进行仿真和验证。它可以帮助学习者了解如何设计有效的测试用例,以及如何对设计进行仿真和调试。 最后,在VHDL语言教程中,通常还会提供一些常见应用案例和示例代码,以帮助学习者更好地理解和运用VHDL语言。 总之,VHDL语言教程是一本指导学习者了解和掌握VHDL语言的重要工具。通过学习VHDL语言教程,学习者可以迅速入门VHDL语言,熟练地进行数字电路设计硬件描述。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

dtge

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值