eda課程設(shè)計(jì)LED點(diǎn)陣顯示控制_第1頁(yè)
eda課程設(shè)計(jì)LED點(diǎn)陣顯示控制_第2頁(yè)
eda課程設(shè)計(jì)LED點(diǎn)陣顯示控制_第3頁(yè)
eda課程設(shè)計(jì)LED點(diǎn)陣顯示控制_第4頁(yè)
eda課程設(shè)計(jì)LED點(diǎn)陣顯示控制_第5頁(yè)
已閱讀5頁(yè),還剩46頁(yè)未讀, 繼續(xù)免費(fèi)閱讀

下載本文檔

版權(quán)說明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請(qǐng)進(jìn)行舉報(bào)或認(rèn)領(lǐng)

文檔簡(jiǎn)介

1、紹 興 文 理 學(xué) 院數(shù) 理 信 息 學(xué) 院EDA技術(shù)課 程 設(shè) 計(jì) 報(bào) 告課題 LED點(diǎn)陣顯示控制設(shè)計(jì) 姓 名 學(xué) 號(hào) 專業(yè)班級(jí) 指導(dǎo)教師 時(shí) 間 課程設(shè)計(jì)任務(wù)書班 級(jí)姓名題目LED點(diǎn)陣顯示控制設(shè)計(jì)技術(shù)參數(shù)、設(shè)計(jì)要求、檢測(cè)數(shù)據(jù)等在EDA實(shí)驗(yàn)箱上利用FPGA和16*16點(diǎn)陣實(shí)現(xiàn)如下功能:實(shí)現(xiàn)基本的字符顯示(譬如紹大)字符的顯示時(shí)間可調(diào)整(譬如1秒、5秒、10秒等)字符可實(shí)現(xiàn)閃爍顯示(譬如0.5s)字符可實(shí)現(xiàn)移位顯示,且移位方向可控(左移、右移等)設(shè)計(jì)進(jìn)度安排或工作計(jì)劃2013.1.42013.1.4任務(wù)分配,熟悉課題,查詢相關(guān)資料,出方案初稿。2013.1.52013.1.5方案交流并定稿,劃

2、分設(shè)計(jì)模式,課程設(shè)計(jì)開展。2013.1.62013.1.7各模塊設(shè)計(jì)實(shí)現(xiàn)及調(diào)試驗(yàn)證。2013.1.102013.1.13設(shè)計(jì)整體實(shí)現(xiàn)、調(diào)試及驗(yàn)證,并開始撰寫報(bào)告。2013.1.142103.1.15設(shè)計(jì)完成,課程設(shè)計(jì)報(bào)告撰寫并定稿,上交。其 它基于任務(wù)書,我們小組對(duì)設(shè)計(jì)增加了一些功能如下:通過鍵控可以改變字幕滾動(dòng)速度。通過鍵控可以使字幕橫向或縱向滾動(dòng)。通過鍵控可以使字閃爍出現(xiàn)。IILED點(diǎn)陣顯示控制摘 要本文對(duì)基于FPGA控制的LED漢字滾動(dòng)顯示器的設(shè)計(jì)方法進(jìn)行了探討。提出了兩個(gè)實(shí)現(xiàn)方案。并對(duì)其中一個(gè)方案作了詳細(xì)說明。文中首先介紹了完成本設(shè)計(jì)所需的原理、技術(shù)、以及所要實(shí)現(xiàn)的功能;然后研究了滾動(dòng)

3、顯示漢字的方法及鍵控模式改變滾動(dòng)的方式;最后,用VHDL語(yǔ)言程序設(shè)計(jì)了一個(gè)完整的LED漢字滾動(dòng)顯示器。本系統(tǒng)在FPGA試驗(yàn)箱上完成,由掃描控制模塊、只讀存儲(chǔ)器ROM和16*16LED點(diǎn)陣顯示模塊、一個(gè)4-16譯碼器構(gòu)成。其中:掃描控制模塊和只讀存儲(chǔ)器ROM集成在FPGA芯片內(nèi)部。一個(gè)4-16譯碼器(74LS154)輸入完成FPGA中16×16點(diǎn)陣顯示模塊的列掃描模式。FPGA定義的只讀存儲(chǔ)器ROM中保存了要顯示的漢字的數(shù)模,并以16位的數(shù)據(jù)寬度輸出到LED陣顯示模塊的行端,配合列掃描控制共同完成漢字的滾動(dòng)顯示。同時(shí)通過鍵控模式,對(duì)字幕滾動(dòng)速度、方式、形式可調(diào)。本系統(tǒng)利用數(shù)字系統(tǒng)設(shè)計(jì)自

4、動(dòng)化(EDA)技術(shù)實(shí)現(xiàn)了全硬件方式的LED點(diǎn)陣顯示。利用FPGA內(nèi)部的物理資源,將只讀存儲(chǔ)器ROM和主要功能模塊設(shè)計(jì)在FPGA內(nèi)部。充分顯示了EDA技術(shù)設(shè)計(jì)的靈活性,同時(shí)也大大提高了系統(tǒng)的集成度和穩(wěn)定性 關(guān)鍵詞 FPGA; LED; EDA;動(dòng)態(tài)掃描目 錄課程設(shè)計(jì)任務(wù)書I摘 要II1. 設(shè)計(jì)概述11.1LED點(diǎn)陣原理11.3漢字顯示原理21.4設(shè)計(jì)的主要功能21.5設(shè)計(jì)的主要工作32. 設(shè)計(jì)方案42.1方案一42.2方案二42.3方案比較43. 設(shè)計(jì)實(shí)現(xiàn)53.1分頻程序53.2移動(dòng)速度控制程序73.3按鍵掃描83.4漢字顯示程序94. 設(shè)計(jì)驗(yàn)證115. 總結(jié)13參考文獻(xiàn)14附錄151. 設(shè)計(jì)概

5、述1.1LED點(diǎn)陣原理以下為8×8點(diǎn)陣LED外觀及引腳圖及其等效電路,只要其對(duì)應(yīng)的X、Y軸順向偏壓,即可使LED發(fā)亮。例如如果想使左上角LED點(diǎn)亮,則Y0=1,X0=0即可。應(yīng)用時(shí)限流電阻可以放在X軸或Y軸。圖 11 8×8點(diǎn)陣LED外觀圖5圖 12 8×8點(diǎn)陣LED等效圖5 1.2點(diǎn)陣LED掃描法介紹 點(diǎn)陣LED一般采用掃描式顯示,實(shí)際運(yùn)用分為三種方式: (1)點(diǎn)掃描(2)行掃描(3)列掃描若使用第一種方式,其掃描頻率必須大于16×64=1024Hz,周期小于1ms即可。若使用第二和第三種方式,則頻率必須大于16×8=128Hz,周期小于7.

6、8ms即可符合視覺暫留要求。此外一次驅(qū)動(dòng)一列或一行(8顆LED)時(shí)需外加驅(qū)動(dòng)電路提高電流,否則LED亮度會(huì)不足1.3漢字顯示原理要實(shí)現(xiàn)漢字的顯示,首先是獲得數(shù)模并保存,即在存貯器中建立漢字?jǐn)?shù)據(jù)庫(kù)。這里,直接運(yùn)用取字模軟件,輸入要取模的字,自動(dòng)生成字形碼。然后是在掃描模塊的控制下,從低往高列掃描的次序正確地輸出這些數(shù)據(jù),由于人視覺暫留效果,即呈現(xiàn)完整字形。某一時(shí)刻能在顯示數(shù)據(jù)序列中定位待顯示數(shù)據(jù)的地址指針可用下式計(jì)算: addr=n+m  圖 13滾動(dòng)顯示多漢字信息的原理示意圖51.4設(shè)計(jì)的主要功能 基本功能: 實(shí)現(xiàn)基本的字符顯示(譬如紹大) 字符的顯示時(shí)間可調(diào)整(譬如1秒、5秒、10

7、秒等) 字符可實(shí)現(xiàn)閃爍顯示(譬如0.5s) 字符可實(shí)現(xiàn)移位顯示,且移位方向可控(左移、右移等) 附加功能: 通過鍵控可以改變字幕滾動(dòng)速度。 通過鍵控可以使字幕橫向或縱向滾動(dòng)。 通過鍵控可以使字閃爍出現(xiàn)。 1.5設(shè)計(jì)的主要工作 本設(shè)計(jì)需要利用EDA工具軟件QuartusII編寫并調(diào)試系統(tǒng)的VHDL程序。并且每一個(gè)模塊都在這個(gè)軟件下進(jìn)行了仿真。系統(tǒng)的VHDL程序編好過后先在實(shí)驗(yàn)室的EDA實(shí)驗(yàn)箱上下載調(diào)試、驗(yàn)證。32. 設(shè)計(jì)方案2.1方案一本文系統(tǒng)的LED點(diǎn)陣模塊,共由16×16=256個(gè)LED發(fā)光二極管組成。如何在該點(diǎn)陣模塊上顯示漢字是本文設(shè)計(jì)的關(guān)鍵技術(shù)。本文系統(tǒng)設(shè)計(jì)是采用一種16路動(dòng)態(tài)

8、分時(shí)掃描技術(shù)來實(shí)現(xiàn)的。具體方法是,將4個(gè)8×8數(shù)組的顯示模塊組合成兩個(gè)16行16列的掃描結(jié)構(gòu)。其行輸入端與FPGA內(nèi)的只讀存儲(chǔ)器ROM的16位數(shù)據(jù)輸出端口相連;16個(gè)列控制端與一個(gè)4-16譯碼器的輸出相連;而譯碼器的輸入端和片選信號(hào)又與FPGA內(nèi)的列掃描控制模塊的輸出端口相連。圖2-1 系統(tǒng)結(jié)構(gòu)框圖2.2方案二二維數(shù)組動(dòng)態(tài)顯示圖 2-2方案二的原理框圖更新數(shù)組數(shù)據(jù)VHDL程序設(shè)計(jì)的是硬件,可以“并發(fā)執(zhí)行”。本設(shè)計(jì)可以將LED顯示屏要的顯示內(nèi)容抽象成一個(gè)二維數(shù)組(數(shù)組中的1對(duì)映點(diǎn)陣顯示屏上面的亮點(diǎn)),用VHDL語(yǔ)言設(shè)計(jì)一個(gè)進(jìn)程將這個(gè)數(shù)組動(dòng)態(tài)顯示在LED顯示屏上,再利用另一個(gè)進(jìn)程對(duì)這個(gè)數(shù)

9、組按一定頻率進(jìn)行數(shù)據(jù)更新,更新的方式可以有多種。因?yàn)閮蓚€(gè)進(jìn)程是同時(shí)進(jìn)行的(并發(fā)執(zhí)行),如果對(duì)數(shù)組中的漢字?jǐn)?shù)據(jù)按滾動(dòng)的方式更新,則可實(shí)現(xiàn)漢字的滾動(dòng)顯示。該方案的原理圖。 2.3方案比較方案一很容易實(shí)現(xiàn),而且占用FPGA的資源較少。但是由于其實(shí)現(xiàn)方式的局限性,該方案只能實(shí)現(xiàn)漢字的滾動(dòng)顯示。方案二中將LED點(diǎn)陣抽象成了一個(gè)二維數(shù)組??梢栽O(shè)計(jì)一些比較復(fù)雜的算法來控制這個(gè)數(shù)組,使設(shè)計(jì)的系統(tǒng)不但可以滾動(dòng)顯示漢字,還可以擴(kuò)展一些其它的顯示效果。但是方案二中對(duì)數(shù)組的處理部分對(duì)FPGA芯片的資源消耗太大,所以最終選擇方案一。473. 設(shè)計(jì)實(shí)現(xiàn)3.1分頻程序該電路主要包含有一個(gè)計(jì)數(shù)器模塊和一個(gè)譯碼輸出模塊,該電路

10、是通過計(jì)數(shù)器模塊實(shí)現(xiàn)分頻的。比如要從12MHz的全局時(shí)鐘得到100Hz的時(shí)鐘,必須進(jìn)行120000倍分頻。但是這么大的分頻需要仿真時(shí)間很久。仿真是一般采用小的分頻來替代,真正下載到電路上時(shí),就需要采用120000分頻了。譯碼器的輸入采用了寄存器鎖存輸出,這是為了消除毛刺。多輸入的組合邏輯電路中,默寫輸入信號(hào)在理想情況下應(yīng)該同時(shí)發(fā)生變化,但由于延遲路徑不同造成這些輸入信號(hào)發(fā)生變化的時(shí)間有微小差別(門延遲時(shí)間量級(jí)),這是得到的是輸出信號(hào)就會(huì)有毛刺,這些毛刺有可能會(huì)給下一級(jí)電路帶來,使得整個(gè)系統(tǒng)運(yùn)行不穩(wěn)定。因此,為保證系統(tǒng)的穩(wěn)健性,一般情況下,都應(yīng)該給輸出信號(hào)去毛刺,使之變得干凈。在設(shè)計(jì)中,譯碼的輸

11、入是計(jì)數(shù)器的輸出,計(jì)數(shù)器各級(jí)輸出延遲是不一樣的,因此譯碼器輸出clk_scan信號(hào)波形就會(huì)有毛刺。if(reset_n='0')then -clk輸入的500KHz信號(hào)cnt_scan:=0; -clk_scan1.25khz的點(diǎn)陣動(dòng)態(tài)掃描信號(hào)cnt_key:=0;elsif(rising_edge(clk)then -clk_key1KHz的鍵盤掃描信號(hào)if(cnt_scan=cnt_scan'high)thencnt_scan:=0;elsecnt_scan:=cnt_scan+1;end if;if(cnt_key=cnt_key'high)thencnt

12、_key:=0;elsecnt_key:=cnt_key+1;end if;if(cnt_scan>(cnt_scan'high/2)thenclk_scan<='1'elseclk_scan<='0'end if;if(cnt_key>(cnt_key'high/2)thenclk_key<='1'elseclk_key<='0'end if;end if;把有毛刺的信號(hào)通過時(shí)鐘采樣,即通過一個(gè)D觸發(fā)器也可以消除毛刺。本設(shè)計(jì)就是使用這種方法。這種方法的缺點(diǎn)是信號(hào)通過一個(gè)D觸發(fā)器

13、后,就延遲了一個(gè)時(shí)鐘周期。對(duì)于本設(shè)計(jì)這種延遲是允許的。process(reset_n,clk_key,key1_in)variable temp1:std_logic;variable cnt1:integer range 0 to 15;beginif(reset_n='0')thenkey1_out<='1' -高電平表示沒有按下elsif(rising_edge(clk_key)thenif(temp1=key1_in)thenif(cnt1=cnt1'high)thencnt1:=0;key1_out<=temp1;elsecnt1:

14、=cnt1+1;end if;elsetemp1:=key1_in;cnt1:=0;end if;end if;end process;3.2移動(dòng)速度控制程序在用VHDL編程的時(shí)候,可以定義一個(gè)變量x作為“滑窗”在ROM上的起始地址,設(shè)計(jì)一個(gè)進(jìn)程按一定的頻率對(duì)x進(jìn)行累加,再設(shè)計(jì)一個(gè)進(jìn)程將以x為起始地址的長(zhǎng)度為16的ROM中的區(qū)域動(dòng)態(tài)顯示在LED點(diǎn)陣中。顯然x累加的速度決定了漢字的滾動(dòng)速度。if(reset_n='0')thenn<=1; -初始化n為1 最快速度f(wàn)lag_key:='0' elsif(rising_edge(clk_scan)thenif(

15、key1='0')then -key1的優(yōu)先級(jí)比key2高,key1=0表示按下 if(flag_key='0')then -flag_key=0表示上次掃描鍵盤的時(shí)候無(wú)按鍵按下 flag_key:='1' if(n>=n'high)thenn<=n;elsen<=n+1;end if;end if;elsif(key2='0')thenif(flag_key='0')thenflag_key:='1'if(n=1)thenn<=n;else n<=n-1;en

16、d if;end if;elseflag_key:='0'end if;end if; if(reset_n='0')then -x的控制進(jìn)程cntx:=0;x<=0;elsif(rising_edge(clk_scan)thenif(flag_scan='1')thenif(cntx=n*10 or cntx=cntx'high)thencntx:=0;elsecntx:=cntx+1;end if;if(cntx=n*10)thenif(x=x'high)thenx<=0;elsex<=x+1;end if;

17、end if;end if;end if;此進(jìn)程根據(jù)定義的信號(hào)n來控制x遞增的速度,n由外部的按鍵控制。n的范圍為15代表了漢字的不同的滾動(dòng)速度。當(dāng)n為1時(shí)漢字滾動(dòng)的速度最快,n為5時(shí)LED點(diǎn)陣上顯示的漢字滾動(dòng)速度最慢。3.3按鍵掃描本系統(tǒng)用到的按鍵只有5個(gè):復(fù)位按鍵,控制n增大和減小的兩個(gè)按鍵,控制閃爍的一個(gè)按鍵,控制橫向縱向的一個(gè)按鍵。3.4漢字顯示程序if(reset_n='0')then -顯示各種模式轉(zhuǎn)換data<="0000000000000000"elsif(rising_edge(clk_scan)thenif(key4='1&

18、#39;)thenif(shanshuo='1')thenif(key3='1')then index:=(cnt-x) mod L_SZ); -左移if(key5='1')then-顯示模式轉(zhuǎn)換上下或左右data<=ledsj(index); elsedata<=ledsj1(index);end if;end if;if(key3='0')thenindex:=(cnt+x) mod L_SZ); -右移if(key5='1')thendata<=ledsj(index); elsedata&

19、lt;=ledsj1(index);end if;end if;elsif(shanshuo='0')thendata<=x"0000"end if;elsif(key4='0')thenif(key3='1')thenindex:=(cnt-x) mod L_SZ);if(key5='1')thendata<=ledsj(index); elsedata<=ledsj1(index);end if;end if;if(key3='0')thenindex:=(cnt+x) m

20、od L_SZ);if(key5='1')thendata<=ledsj(index); elsedata<=ledsj1(index);end if;end if;end if;end if;end process;4. 設(shè)計(jì)驗(yàn)證(1) 分頻仿真圖圖 41 分頻仿真圖(2) 按鍵掃描去抖仿真圖圖 42 按鍵去抖動(dòng)仿真圖(3)漢字顯示仿真圖圖 43 漢字顯示仿真圖圖 44 漢字顯示仿真圖(4)FPGA實(shí)驗(yàn)箱結(jié)果圖 45 FPGA實(shí)驗(yàn)箱結(jié)果每次來一個(gè)時(shí)鐘脈沖,會(huì)對(duì)應(yīng)產(chǎn)生一個(gè)列掃描信號(hào),同時(shí)會(huì)輸出一個(gè)16位的列段碼,當(dāng)完成16列的掃描之后就呈現(xiàn)一個(gè)完整的字碼。下一輪的輸

21、出會(huì)根據(jù)N值的不同改變初始的列段碼,從而實(shí)現(xiàn)左右平移。5. 總結(jié)本次設(shè)計(jì)是基于FPGA的LED16*16點(diǎn)陣控制設(shè)計(jì),是通過VHDL語(yǔ)言編輯實(shí)現(xiàn)漢字的可動(dòng)可控效果。經(jīng)過為期兩周的課程設(shè)計(jì),使得我對(duì)VHDL語(yǔ)言有了更多的認(rèn)識(shí),此次設(shè)計(jì)開始時(shí),我和隊(duì)友開始方案討論,最后確定從兩個(gè)方向入手,先是配合王杰同學(xué)用數(shù)組的方法寫,經(jīng)過幾天的不斷摸索,討論,修改,最后寫完了設(shè)計(jì)要求的基本部分,通過仿真,調(diào)試和下載到試驗(yàn)箱進(jìn)行驗(yàn)證,證明它的可行性,期間有張敏和鄭士港兩位同學(xué)幫助王杰同學(xué)完成。接著就是發(fā)揮部分,發(fā)揮部分由我提供一點(diǎn)思路后,暫由王杰同學(xué)去完成。而我開始轉(zhuǎn)向我們的第二個(gè)方向通過狀態(tài)機(jī)的方法寫,最后也在

22、完成了設(shè)計(jì)的基本要求的前提下,加了漢字靜態(tài)顯示時(shí)間可控,且有暫停功能。當(dāng)然,期間王杰同學(xué)也增加了漢字移動(dòng)速度可調(diào),以及漢字移動(dòng)轉(zhuǎn)向可控等功能。此過程中金老師讓我們?cè)噲D添加的漢字上移下移功能由于用狀態(tài)機(jī)方法太過繁瑣,所以,沒有寫此部分代碼。當(dāng)然,此后的設(shè)計(jì)報(bào)告交由張敏等人完成,王杰負(fù)責(zé)答疑報(bào)告中的設(shè)計(jì)思路和功能解釋,鄭士港負(fù)責(zé)報(bào)告排版,我和王杰負(fù)責(zé)設(shè)計(jì)報(bào)告初審。最后交由金老師進(jìn)行終審。對(duì)于本次設(shè)計(jì),使我明白團(tuán)隊(duì)的重要性,以及平時(shí)實(shí)驗(yàn)的必要性。當(dāng)然,感謝金老師和潘老師這兩周的悉心教導(dǎo)和諄諄教誨,辛苦了。 參考文獻(xiàn)1黃任.VHDL入門·解惑·經(jīng)典實(shí)例·經(jīng)驗(yàn)總結(jié).M.北京

23、:北京航空航天大學(xué)出版社,20052王彥主.基于FPGA的工程設(shè)計(jì)與應(yīng)用M.西安:西安電子科技大學(xué)出版社,20073游達(dá)章.簡(jiǎn)易LED點(diǎn)陣漢字顯示控制模塊設(shè)計(jì)J.中國(guó)光學(xué)期刊網(wǎng).2007/11/20 19(5): P42-P454賈德旺.基于FPGA的LED點(diǎn)陣書寫顯示屏的實(shí)現(xiàn)J.電子世界.2011年 8 :P24-P255任雪賓.用VHDL設(shè)計(jì)LED漢字滾動(dòng)顯示器EB/OL. 2014年1月11日附錄方向一數(shù)組1、 分頻模塊代碼library ieee;use ieee.std_logic_1164.all;use ieee.std_logic_arith.all;use ieee.std_

24、logic_unsigned.all;entity fenpin isport( clk:in std_logic; -輸入的500KHz信號(hào) clk_scan:out std_logic; -1.25khz的點(diǎn)陣動(dòng)態(tài)掃描信號(hào) clk_key:out std_logic; -1KHz的鍵盤掃描信號(hào) reset_n:in std_logic);end fenpin;architecture abc of fenpin isbeginprocess(reset_n,clk)-產(chǎn)生clk_scan和clk_key信號(hào)-下載用下面這兩條語(yǔ)句variable cnt_scan:integer range

25、 0 to 400;variable cnt_key:integer range 0 to 500;-仿真用下面這兩條語(yǔ)句-variable cnt_scan:integer range 0 to 30;-variable cnt_key:integer range 0 to 24;beginif(reset_n='0')thencnt_scan:=0;cnt_key:=0;elsif(rising_edge(clk)thenif(cnt_scan=cnt_scan'high)thencnt_scan:=0;elsecnt_scan:=cnt_scan+1;end if

26、;if(cnt_key=cnt_key'high)thencnt_key:=0;elsecnt_key:=cnt_key+1;end if;if(cnt_scan>(cnt_scan'high/2)thenclk_scan<='1'elseclk_scan<='0'end if;if(cnt_key>(cnt_key'high/2)thenclk_key<='1'elseclk_key<='0'end if;end if;end process;end abc;2、 鍵盤

27、掃描字幕顯示控制模塊程序library ieee;use ieee.std_logic_1164.all;use ieee.std_logic_arith.all;use ieee.std_logic_unsigned.all;entity mnscan isport(clk_scan:in std_logic; -分頻時(shí)鐘scan:out std_logic_vector(3 downto 0); -列掃描data:out std_logic_vector(15 downto 0); -列段碼輸出 dis_n:out std_logic_vector(6 downto 0); -不需要小數(shù)點(diǎn)

28、(7位)key1,key2,key3,key4,key5:in std_logic;-key1(加速)key2(減速)key3=1左移key3=0右移 -key4(閃爍控制)key5(輸出形式) reset_n:in std_logic -復(fù)位); end mnscan;architecture abc of mnscan isconstant L_SZ:integer:=223;constant L_DZ:integer:=15;signal cnt:integer range 0 to L_DZ; -和點(diǎn)陣屏的列一樣大signal n:integer range 1 to 5; -控制速度

29、signal flag_scan:std_logic;signal x:integer range 0 to L_SZ;signal shanshuo:std_logic; -閃爍signal shanshuo_cnt:integer range 0 to 60;-創(chuàng)建一個(gè)可以存儲(chǔ)2唯數(shù)據(jù)的數(shù)據(jù)類型 array_1 array_2type array_2 is array(0 to 31)of std_logic_vector(15 downto 0);constant ledsj:array_2:=(x"0008"),(x"3f88"),(x"

30、;2204"),(x"2204"),(x"2112"),(x"210f"),(x"2888"),(x"1044"),(x"3f82"),(x"209f"),(x"2080"),(x"2080"),(x"2098"),(x"3f87"),(x"2080"),(x"0000"),-紹 上下(x"0000"),(x

31、"0080"),(x"0080"),(x"0080"),(x"0080"),(x"7fff"),(x"0080"),(x"0140"),(x"0140"),(x"0240"),(x"0220"),(x"0420"),(x"0810"),(x"1808"),(x"7004"),(x"2002")-大)

32、;type array_1 is array(0 to 31)of std_logic_vector(15 downto 0);constant ledsj1:array_1:=(x"0000"),(x"0000"),(x"7f7e"),(x"2182"),(x"2142"),(x"2102"),(x"210e"),(x"2132"),(x"7f42"),(x"0080"),(x"000

33、0"),(x"1210"),(x"1263"),(x"22ac"),(x"2330"),(x"2220"),-紹 左右(x"0000"),(x"4020"),(x"c020"),(x"6020"),(x"3020"),(x"0820"),(x"0620"),(x"01a0"),(x"007f"),(x&quo

34、t;03a0"),(x"0c20"),(x"1020"),(x"2020"),(x"4020"),(x"8020"),(x"0020")-大);beginprocess(reset_n,clk_scan) -cnt計(jì)數(shù)及flag_scan的產(chǎn)生beginif(reset_n='0')thencnt<=15;elsif(rising_edge(clk_scan)thenif(cnt=cnt'high)thencnt<=0;elsec

35、nt<=cnt+1;end if;if(cnt =cnt'high-1)thenflag_scan<='1'elseflag_scan<='0'end if;end if;end process;process(shanshuo_cnt)beginif(shanshuo_cnt>shanshuo_cnt'high/2)then shanshuo<='1' -閃爍計(jì)時(shí)控制else shanshuo<='0'end if;end process;process(reset_n,clk

36、_scan,cnt) -掃描信號(hào)scan的產(chǎn)生beginif(reset_n='0')thenscan<="ZZZZ"elsif(rising_edge(clk_scan)thencase cnt iswhen 0 => scan <= "0000"when 1 => scan <= "0001"when 2 => scan <= "0010"when 3 => scan <= "0011"when 4 => scan

37、<= "0100"when 5 => scan <= "0101"when 6 => scan <= "0110"when 7 => scan <= "0111"when 8 => scan <= "1000"when 9 => scan <= "1001"when 10 => scan <= "1010"when 11 => scan <= "1011&q

38、uot;when 12 => scan <= "1100"when 13 => scan <= "1101"when 14 => scan <= "1110"when 15 => scan <= "1111"shanshuo_cnt<=shanshuo_cnt+1;when others => scan <= "ZZZZ"end case;end if;end process;process(reset_n,clk_scan,fl

39、ag_scan) -cntx,x的控制variable cntx:integer range 0 to 90;beginif(reset_n='0')thencntx:=0;x<=0;elsif(rising_edge(clk_scan)thenif(flag_scan='1')thenif(cntx=n*10 or cntx=cntx'high)thencntx:=0;elsecntx:=cntx+1;end if;if(cntx=n*10)thenif(x=x'high)thenx<=0;elsex<=x+1;end if;

40、end if;end if;end if;end process;process(reset_n,clk_scan,cnt,x,key3,key4,key5)-輸出列數(shù)據(jù)datavariable index:integer range 0 to L_SZ;beginif(reset_n='0')thendata<="0000000000000000"elsif(rising_edge(clk_scan)thenif(key4='1')thenif(shanshuo='1')thenif(key3='1')

41、then index:=(cnt-x) mod L_SZ); -左移if(key5='1')then-顯示模式轉(zhuǎn)換上下或左右data<=ledsj(index); elsedata<=ledsj1(index);end if;end if;if(key3='0')thenindex:=(cnt+x) mod L_SZ); -右移if(key5='1')thendata<=ledsj(index); elsedata<=ledsj1(index);end if;end if;elsif(shanshuo='0'

42、;)thendata<=x"0000"end if;elsif(key4='0')thenif(key3='1')thenindex:=(cnt-x) mod L_SZ);if(key5='1')thendata<=ledsj(index); elsedata<=ledsj1(index);end if;end if;if(key3='0')thenindex:=(cnt+x) mod L_SZ);if(key5='1')thendata<=ledsj(index); e

43、lsedata<=ledsj1(index);end if;end if;end if;end if;end process;process(reset_n,clk_scan,key1,key2) -n的控制variable flag_key:std_logic;beginif(reset_n='0')thenn<=1; -初始化n為1 最快速度f(wàn)lag_key:='0'elsif(rising_edge(clk_scan)thenif(key1='0')then -key1的優(yōu)先級(jí)比key2高,key1=0表示按下if(flag_k

44、ey='0')then -flag_key=0表示上次掃描鍵盤的時(shí)候 -無(wú)按鍵按下 flag_key:='1' if(n>=n'high)thenn<=n;elsen<=n+1;end if;end if;elsif(key2='0')thenif(flag_key='0')thenflag_key:='1'if(n=1)thenn<=n;else n<=n-1;end if;end if;elseflag_key:='0'end if;end if;end p

45、rocess; process(reset_n,n,clk_scan,cnt) -移動(dòng)速度顯示 begin if(reset_n='0')then dis_n<="0111111" elsif(rising_edge(clk_scan)thenif(cnt=7)thencase n iswhen 5=>dis_n<="1101101"when 4=>dis_n<="1100110"when 3=>dis_n<="1001111"when 2=>dis_

46、n<="1011011"when 1=>dis_n<="0000110"when others=>dis_n<="0000000"end case;elsedis_n<="0000000"end if; end if; end process; end abc;3、 鍵盤消抖模塊程序library ieee;use ieee.std_logic_1164.all;use ieee.std_logic_arith.all;use ieee.std_logic_unsigned.al

47、l;entity keyscan isport(clk_key:in std_logic;reset_n:in std_logic;key1_in,key2_in:in std_logic; -按下時(shí)為低電平key1_out,key2_out:out std_logic);end keyscan;architecture abc of keyscan isbegin-key1的產(chǎn)生(消鍵抖動(dòng))process(reset_n,clk_key,key1_in)variable temp1:std_logic;variable cnt1:integer range 0 to 15;beginif(r

48、eset_n='0')thenkey1_out<='1' -高電平表示沒有按下elsif(rising_edge(clk_key)thenif(temp1=key1_in)thenif(cnt1=cnt1'high)thencnt1:=0;key1_out<=temp1;elsecnt1:=cnt1+1;end if;elsetemp1:=key1_in;cnt1:=0;end if;end if;end process;-key2的產(chǎn)生(消鍵抖動(dòng))process(reset_n,clk_key,key2_in)variable temp2:

49、std_logic;variable cnt2:integer range 0 to 15;beginif(reset_n='0')thenkey2_out<='1'elsif(rising_edge(clk_key)thenif(temp2=key2_in)thenif(cnt2=cnt2'high)thencnt2:=0;key2_out<=temp2;elsecnt2:=cnt2+1;end if;elsetemp2:=key2_in;cnt2:=0;end if;end if;end process;end abc;方向二狀態(tài)機(jī)lib

50、rary ieee;use ieee.std_logic_1164.all;use ieee.std_logic_unsigned.all;use ieee.std_logic_arith.all;entity led_control isport(clk,rst,key1,key2,key3,key4:in std_logic;key1-1s顯示,key2-5s顯示,key3-10s顯示,key4-暫停sel:out std_logic_vector(3 downto 0);com:out std_logic_vector(15 downto 0);end;architecture bhv

51、of led_control issignal clk_2hz:std_logic;signal d0,d1,d2,d3,d4,d5,d6,d7,d8,d9,d10,d11,d12,d13,d14,d15,d16,d17,d18,d19,d20,d21,d22,d23,d24,d25,d26,d27,d28,d29,d30,d31:std_logic_vector(15 downto 0);signal cnt:integer range 0 to 500;signal cnt2:integer range 0 to 1000;signal px:integer range 0 to 32;s

52、ignal data:std_logic_vector(15 downto 0);type state is(s0,s1,s2,s3,s4,s5,s6,s7,s8,s9,s10,s11,s12,s13,s14,s15,s16);signal stat:state;signal lie:std_logic_vector(3 downto 0);signal rl:std_logic;begincom<=data;sel<=lie;d0<=x"0000"d1<=x"0000"d2<=x"7f7e"d3<

53、=x"2182"d4<=x"2142"d5<=x"2102"d6<=x"21e0"d7<=x"2132"d8<=x"7f42"d9<=x"0080"d10<=x"0000"d11<=x"1210"d12<=x"1263"d13<=x"22ac"d14<=x"2330"d15<=x&quo

54、t;2220"d16<=x"0000"d17<=x"0080"d18<=x"2084"d19<=x"709e"d20<=x"18b0"d21<=x"04c0"d22<=x"0280"d23<=x"0090"d24<=x"00b8"d25<=x"008c"d26<=x"0482"d27<=x&quo

55、t;0e90"d28<=x"18b8"d29<=x"108c"d30<=x"2082"d31<=x"4000"process(rst,clk)beginif rst='1' then cnt<=0;elseif clk'event and clk='1' thenif cnt2=499 thencnt2<=0;clk_2hz<='1'elsecnt2<=cnt2+1;clk_2hz<='0

56、'end if;end if;end if;end process;process(rst,clk,stat,px,d0,d1,d2,d3,d4,d5,d6,d7,d8,d9,d10,d11,d12,d13,d14,d15,d16,d17,d18,d19,d20,d21,d22,d23,d24,d25,d26,d27,d28,d29,d30,d31)beginif rst='1'thenpx<=0;elseif clk'event and clk='1'thenif px>31 thenpx<=0;elsepx<=px+1

57、;end if;case stat iswhen s0=>case px is when 0=>lie<="0000"data<=d0;when 1=>lie<="0001"data<=d1;when 2=>lie<="0010"data<=d2;when 3=>lie<="0011"data<=d3;when 4=>lie<="0100"data<=d4;when 5=>lie<="0101"data<=d5;when 6=>lie<="0110"data<=d6;when 7=>lie<="0111"data<=d7;when 8=>lie<="1000"data<=d8;when 9=>lie<="1001"data<=d9;when 10=>lie<=&quo

溫馨提示

  • 1. 本站所有資源如無(wú)特殊說明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請(qǐng)下載最新的WinRAR軟件解壓。
  • 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請(qǐng)聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶所有。
  • 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁(yè)內(nèi)容里面會(huì)有圖紙預(yù)覽,若沒有圖紙預(yù)覽就沒有圖紙。
  • 4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
  • 5. 人人文庫(kù)網(wǎng)僅提供信息存儲(chǔ)空間,僅對(duì)用戶上傳內(nèi)容的表現(xiàn)方式做保護(hù)處理,對(duì)用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對(duì)任何下載內(nèi)容負(fù)責(zé)。
  • 6. 下載文件中如有侵權(quán)或不適當(dāng)內(nèi)容,請(qǐng)與我們聯(lián)系,我們立即糾正。
  • 7. 本站不保證下載資源的準(zhǔn)確性、安全性和完整性, 同時(shí)也不承擔(dān)用戶因使用這些下載資源對(duì)自己和他人造成任何形式的傷害或損失。

最新文檔

評(píng)論

0/150

提交評(píng)論