找回密码
 立即注册

QQ登录

只需一步,快速开始

搜索
查看: 5052|回复: 1
收起左侧

24进制计数器数码管显示用VHDl编写

[复制链接]
ID:115737 发表于 2016-4-21 17:21 | 显示全部楼层 |阅读模式
——24进制计数器(数码管显示)用VHDl编写
——楼主用实验板验证过满足计数0~23
顶层文件 led_24
library  ieee;
use ieee.std_logic_1164.all;
use ieee.std_logic_unsigned.all;
entity led_24 is
        port(clk,clr,ena:in std_logic;
      cq10_out,cq2_out:out std_logic_vector(3 downto 0)
      );
    end led_24;

architecture behav of led_24 is
        component led24
                port(clk,clr,ena:in std_logic;
                cnt10,cnt2:out std_logic_vector(3 downto 0));
        end component;

        component decoder_10
                port(cq10_1:IN STD_LOGIC_VECTOR (3 DOWNTO 0);
                        cq10_out:OUT STD_LOGIC_VECTOR (6 DOWNTO 0));
        end component;

        component decoder_2
                PORT (cq2_1:IN STD_LOGIC_VECTOR (3 DOWNTO 0);
                        cq2_out:OUT STD_LOGIC_VECTOR (6 DOWNTO 0));
        end component;

signal net1, net2 :std_logic_vector(3 downto 0);
        begin
                u1 : led24 port map(clk=>clk,clr=>clr,ena=>ena,cnt10=>net1,cnt2=>net2);
                u2 : decoder_10 port map(cq10_1=>net1,cq10_out=>cq10_out);
                u3 : decoder_2 port map(cq2_1=>net2,cq2_out=>cq2_out);

END architecture behav;

——例化元器件 U1
——24进制计数器
library ieee;
use ieee.std_logic_1164.all;
use ieee.std_logic_unsigned.all;
entity led24 is
port(clk,clr,ena:in std_logic;
      cnt10,cnt2:out std_logic_vector(3 downto 0)
      );

end led24 ;
architecture behav of led24 is

begin

       process(clk,clr,ena)
        variable cq2:std_logic_vector(3 downto 0);
   variable cq10:std_logic_vector(3 downto 0);         
                 begin
            if clr='1' then
                       cq2:="0000";
                       cq10:="0000";
            elsif clk'event and clk='0' then
                  if ena='1' then
                     if cq10="1001" then
                            cq10:="0000";  
                            cq2:=cq2+'1';        
                     else cq10:=cq10+'1';
                     end if;
                     if cq2="0010" and cq10="0100" then
                           cq2:="0000";cq10:="0000";
                     end if;
                  end if;
             end if;
              cnt2<=cq2;
              cnt10<=cq10;
      end process ;
end architecture behav;

        ——例化元器件u2
——个位数译码电路
LIBRARY IEEE;
USE IEEE.STD_LOGIC_1164.ALL;

ENTITY decoder_10 IS
        PORT (cq10_1:IN STD_LOGIC_VECTOR (3 DOWNTO 0);
                        cq10_out:OUT STD_LOGIC_VECTOR (6 DOWNTO 0));
END;

ARCHITECTURE ONE OF decoder_10 IS
BEGIN
        PROCESS (cq10_1) BEGIN
        CASE cq10_1 IS
        WHEN "0000" => cq10_out<= "1000000";
        WHEN "0001" => cq10_out<= "1111001";
        WHEN "0010" => cq10_out<= "0100100";
        WHEN "0011" => cq10_out<= "0110000";
        WHEN "0100" => cq10_out<= "0011001";
        WHEN "0101" => cq10_out<= "0010010";
        WHEN "0110" => cq10_out<= "0000010";
        WHEN "0111" => cq10_out<= "1111000";
        WHEN "1000" => cq10_out<= "0000000";
        WHEN "1001" => cq10_out<= "0010000";
        WHEN OTHERS => cq10_out<= "1111111";
        END CASE;
        END PROCESS;
        END architecture ONE;

——        例化元器件u3
十位数译码电路

        LIBRARY IEEE;
USE IEEE.STD_LOGIC_1164.ALL;

ENTITY decoder_2 IS
        PORT (cq2_1:IN STD_LOGIC_VECTOR (3 DOWNTO 0);
                        cq2_out:OUT STD_LOGIC_VECTOR (6 DOWNTO 0));
END;

ARCHITECTURE two OF decoder_2 IS
BEGIN
        PROCESS (cq2_1) BEGIN
        CASE cq2_1 IS
        WHEN "0000" => cq2_out<= "1000000";
        WHEN "0001" => cq2_out<= "1111001";
        WHEN "0010" => cq2_out<= "0100100";
        WHEN OTHERS => cq2_out<= "1111111";
        END CASE;
        END PROCESS;
        END architecture two;
波形见附件

       0.png


        RTL图

         1.png
      file:///C:\Users\ADMINI~1\AppData\Local\Temp\ksohtml\wps7658.tmp.jpg
计数器波形

译码之后波形
file:///C:\Users\ADMINI~1\AppData\Local\Temp\ksohtml\wps7669.tmp.jpg

——这里有完整的工程

24进制计数器数码管显示用VHDl编写.zip

53.13 KB, 下载次数: 27, 下载积分: 黑币 -5

24进制计数器

评分

参与人数 1黑币 +50 收起 理由
admin + 50 共享资料的黑币奖励!

查看全部评分

回复

使用道具 举报

ID:225731 发表于 2017-11-24 10:02 | 显示全部楼层
能不能上传文件源码,具体的.VHD文件
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

手机版|小黑屋|51黑电子论坛 |51黑电子论坛6群 QQ 管理员QQ:125739409;技术交流QQ群281945664

Powered by 单片机教程网

快速回复 返回顶部 返回列表