这些小活动你都参加了吗?快来围观一下吧!>>
电子产品世界 » 论坛首页 » 嵌入式开发 » FPGA » 数码管计数参考代码

共2条 1/1 1 跳转至

数码管计数参考代码

菜鸟
2013-11-22 20:57:14     打赏

--(本源码不排除包含些许错误,参考者谨慎!)
--主频:40Mhz,0.5s计数一次,六个数码管,动态扫描方式逐次点亮
entity leddisplay is
port(clk,rst:in std_logic;
     ledk:out std_logic_vector(5 downto 0);
     leda:out std_logic_vector(7 downto 0));
end leddisplay;
architecture a of leddisplay is
signal count:std_logic_vector(25 downto 0);
signal countt:std_logic_vector(15 downto 0);
signal ledat:std_logic_vector(23 downto 0);
signal ledmove:std_logic_vector(2 downto 0);
signal ledaa:std_logic_vector(3 downto 0);
begin
  process(clk,rst)
    begin
     if  rst='0'  then
       count<=(others=>'0');
       ledat<=(others=>'0');
       countt<=(others=>'0');
       ledmove<="000";
     elsif  rising_edge(clk)  then
       if count=19999999  then
           count<=(others=>'0');
           ledat<=ledat+1;
           countt<=countt+1;
       else
           count<=count+1;
           countt<=countt+1;
         if  countt(15)=1 then
             countt<=(others=>'0');
             ledmove<=ledmove+1;
            if ledmove=6  then
               ledmove<="000";
           end if;
        end if;
       end if;
     end if;
  end process;
process(clk,rst)
  begin
     if rst='0'  then
       ledk<="111 111";
       ledaa<="0000";
     elsif rising_edge(clk)  then
        case  ledmove  is
        when "000"=>
         ledk<=not "111 110";
         ledaa<=ledat(23 downto 20);
        when "001"=>
         ledk<=not "111 101";
         ledaa<=ledat(19 downto 16);
        when "010"=>
         ledk<=not "111 011";
         ledaa<=ledat(15 downto 12);
        when "011"=>
         ledk<=not "110 111";
         ledaa<=ledat(11 downto 8);
        when "100"=>
         ledk<=not "101 111";
         ledaa<=ledat(7 downto 4);
        when "101"=>
         ledk<=not "011 111";
         ledaa<=ledat(3 downto 0);
        when others=>
         ledk<="000 000";
       end case;
    end if;
end process;
process(ledaa)
  begin
    case ledaa is
        when "0000"=>
        leda<=x"3f";
        when "0001"=>
        leda<=x"06";
        when "0010"=>
        leda<=x"5b";
        when "0011"=>
        leda<=x"4f";
        when "0100"=>
        leda<=x"66";
        when "0101"=>
        leda<=x"6d";
        when "0110"=>
        leda<=x"7d";
        when "0111"=>
        leda<=x"07";
        when "1000"=>
        leda<=x"7f";
        when "1001"=>
        leda<=x"6f";
        when "1010"=>
        leda<=x"77";
        when "1011"=>
        leda<=x"7c";
        when "1100"=>
        leda<=x"39";
        when "1101"=>
        leda<=x"5e";
        when "1110"=>
        leda<=x"79";
        when "1111"=>
        leda<=x"71";
        when others =>
        leda<=x"00";
    end case;
end process;
end a;
       
   


                               




关键词: 代码     计数    

院士
2013-11-23 09:07:33     打赏
2楼
谢谢奉献型选手

共2条 1/1 1 跳转至

回复

匿名不能发帖!请先 [ 登陆 注册 ]