久久久久久久999_99精品久久精品一区二区爱城_成人欧美一区二区三区在线播放_国产精品日本一区二区不卡视频_国产午夜视频_欧美精品在线观看免费

 找回密碼
 立即注冊

QQ登錄

只需一步,快速開始

搜索
查看: 4519|回復: 0
打印 上一主題 下一主題
收起左側(cè)

計數(shù)器——VHDL源碼

[復制鏈接]
跳轉(zhuǎn)到指定樓層
樓主
ID:72519 發(fā)表于 2015-1-23 21:36 | 只看該作者 回帖獎勵 |倒序瀏覽 |閱讀模式
本來這段代碼早就應該公布了的,可是我直到昨天才在開發(fā)板上進行調(diào)試,剛開始調(diào)試結(jié)果不是我想要的結(jié)果,不過仔細跟住結(jié)果想一下就找到問題所在,并很快解決調(diào)試通過,呵呵,挺高興的。這段代碼中是循環(huán)掃描數(shù)碼管位,所以最后一個文件是一個譯碼的文件,中間是進行按鍵處理并顯示的文件,第一個文件是將譯碼和按鍵處理顯示的例化文件啦。
///////////////cout10.vhd文件
library ieee;
use ieee.std_logic_1164.all;
use ieee.std_logic_unsigned.all;

entity cout10 is
port(
        clk_in,rest_in:in std_logic;
        clk_key_in:in std_logic;--按鍵
        clk_md_in:in std_logic_vector(2 downto 0);--加模式位--000 加1 --001 加10 010 加100 011 加1000
        bt_out:out std_logic_vector(3 downto 0);--數(shù)碼管位選
        cout:out std_logic_vector(6 downto 0)
        );
end;

architecture lammy02 of cout10 is
        component showled
                port(
                        indata:in std_logic_vector(3 downto 0);
                        outdata:out std_logic_vector(6 downto 0)
                        );
        end component showled;
        component cnt10
                port(
                        rest,clk:in std_logic;
                        clk_key:in std_logic;--按鍵
                        clk_md:in std_logic_vector(2 downto 0);--加模式位--000 加1 --001 加10 010 加100 011 加1000
                        bt:out std_logic_vector(3 downto 0);--數(shù)碼管位選
                        cout1:out std_logic_vector(3 downto 0)--個位
                );
        end component cnt10;
                        signal d_cout1:std_logic_vector(3 downto 0);
        begin
                u1: cnt10 port map (clk=>clk_in,rest=>rest_in,clk_key=>clk_key_in,clk_md=>clk_md_in,bt=>bt_out,cout1=>d_cout1);
                u2: showled port map (indata=>d_cout1,outdata=>cout);
end;


/////////////////////showled.vhd
library ieee;
use ieee.std_logic_1164.all;
use ieee.std_logic_unsigned.all;

entity showled is
port(
        indata:in std_logic_vector(3 downto 0);
        outdata:out std_logic_vector(6 downto 0)
        );
end;

architecture lammy01 of showled is
--signal in_data:std_logic_vector(3 downto 0);
begin
        process(indata)
        begin
                case indata is
                when "0000" => outdata<="0111111";--0
                when "0001" => outdata<="0000110";--1
                when "0010" => outdata<="1011011";--2
                when "0011" => outdata<="1001111";--3
                when "0100" => outdata<="1100110";--4
                when "0101" => outdata<="1101101";--5
                when "0110" => outdata<="1111101";--6
                when "0111" => outdata<="0000111";--7
                when "1000" => outdata<="1111111";--8
                when "1001" => outdata<="1101111";--9
                when others => null;
                end case;
        end process;
end;


///////////////cnt10.vhd
library ieee;
use ieee.std_logic_1164.all;
use ieee.std_logic_unsigned.all;

entity cnt10 is
port(
        rest,clk:in std_logic;
        clk_key:in std_logic;--按鍵
        clk_md:in std_logic_vector(2 downto 0);--加模式位--000 加1 --001 加10 010 加100 011 加1000

        bt:out std_logic_vector(3 downto 0);--數(shù)碼管位選
        cout1:out std_logic_vector(3 downto 0)--個位
        );
end;

architecture lammy02 of cnt10 is
        type state is(s0,s1,s2,s3);
        signal led_state:state;
        signal outdata_1,outdata_2,outdata_3,outdata_4:std_logic_vector(3 downto 0):="0000";
begin

lammy_01:process(rest,clk,led_state)
        begin
                if rest='1' then cout1<="0000";led_state<=s0;
                elsif clk'event and clk='1' then
                case led_state is
                        when s0 => bt<="1000";cout1<=outdata_1;led_state<=s1;
                        when s1 => bt<="0100";cout1<=outdata_2;led_state<=s2;
                        when s2 => bt<="0010";cout1<=outdata_3;led_state<=s3;
                        when s3 => bt<="0001";cout1<=outdata_4;led_state<=s0;
                end case;
                end if;
        end process;
lammy_02:process(clk_key)
        variable cout_1,cout_2,cout_3,cout_4:std_logic_vector(3 downto 0);
        begin
                if rising_edge(clk_key) then
                        if clk_md="000" then
                                if cout_1="1001" and cout_2="1001" and cout_3="1001" and cout_4="1001"  
                                        then cout_1:="1001" ; cout_2:="1001" ; cout_3:="1001" ; cout_4:="1001";
                                        elsif cout_1="1001" and cout_2="1001" and cout_3="1001" then cout_4:=cout_4+1;cout_1:="0000";cout_2:="0000";cout_3:="0000";
                                                elsif cout_1="1001" and cout_2="1001" then cout_3:=cout_3+1;cout_1:="0000";cout_2:="0000";
                                                        elsif cout_1="1001" then cout_2:=cout_2+1;cout_1:="0000";
                                                                else cout_1:=cout_1+1;
                                end if;
                        elsif clk_md="001" then
                                if cout_2="1001" and cout_3="1001" and cout_4="1001"
                                        then cout_2:="1001" ; cout_3:="1001" ; cout_4:="1001";
                                        elsif cout_2="1001" and cout_3="1001" then cout_4:=cout_4+1;cout_2:="0000";cout_3:="0000";
                                                elsif cout_2="1001" then cout_3:=cout_3+1; cout_2:="0000";
                                                else cout_2:=cout_2+1;
                                end if;
                        elsif clk_md="010" then
                                if cout_3="1001" and cout_4="1001"
                                        then cout_3:="1001" ; cout_4:="1001";
                                        elsif cout_3="1001" then cout_4:=cout_4+1;cout_3:="0000";
                                        else cout_3:=cout_3+1;
                                end if;
                        elsif clk_md="011" then
                                if cout_4="1001" then cout_4:="1001";
                                else cout_4:=cout_4+1;
                                end if;
                        end if;
                end if;
                outdata_1<=cout_1;
                outdata_2<=cout_2;
                outdata_3<=cout_3;
                outdata_4<=cout_4;
        end process;
end;
分享到:  QQ好友和群QQ好友和群 QQ空間QQ空間 騰訊微博騰訊微博 騰訊朋友騰訊朋友
收藏收藏 分享淘帖 頂 踩
回復

使用道具 舉報

您需要登錄后才可以回帖 登錄 | 立即注冊

本版積分規(guī)則

小黑屋|51黑電子論壇 |51黑電子論壇6群 QQ 管理員QQ:125739409;技術(shù)交流QQ群281945664

Powered by 單片機教程網(wǎng)

快速回復 返回頂部 返回列表
主站蜘蛛池模板: 欧美一区二区三区国产 | 精品国产乱码久久久久久蜜退臀 | 日本黄色免费片 | 欧美日韩高清一区二区三区 | 欧美一级欧美一级在线播放 | 波波电影院一区二区三区 | h片免费在线观看 | 一区二区三区国产 | 欧美久久一区二区 | 精国产品一区二区三区四季综 | 一区在线观看 | 国产精品欧美一区二区 | 婷婷亚洲综合 | 888久久久 | 久久一热 | 操亚洲| 国产精品欧美一区二区三区 | 亚洲一区二区久久 | 在线视频一区二区 | 成人av一区二区亚洲精 | 99久久精品视频免费 | 99久久免费精品国产免费高清 | 日本中文字幕视频 | 亚洲国产精品久久久 | 国色天香成人网 | 国产高清精品在线 | 日韩在线播放中文字幕 | 国产精品美女久久久久久久久久久 | 亚洲视频精品在线 | 黑人一级黄色大片 | 日韩在线不卡 | 亚洲视频一区二区三区 | 一区二区三| 久久99精品视频 | 亚洲区一区二 | 国产特级毛片 | 精品国偷自产在线 | 亚洲精品电影网在线观看 | 天天爱av| 中日韩欧美一级片 | 91精品国产91久久久久久密臀 |