




下載本文檔
版權說明:本文檔由用戶提供并上傳,收益歸屬內容提供方,若內容存在侵權,請進行舉報或認領
文檔簡介
基于FPGA的四位加法器設計4位加法器設計。取開發板上的4位按鍵作為4位被加數,取4位撥碼開關作為4位被加數,其中8個led燈取5位作為輸出結果,led0-led3作為相加的結果,led4作為進位(LED亮表示低電平0,LED滅表示高電平1,)數碼管以十進制數顯示被加數,加數和相加的結果。包括vhdl文件、和vwf文件。利用兩組按鍵作為兩個加數輸入,用數碼管做加數顯示和結果顯示,開發板上只有4個數碼管,但加數都是兩位的,所以只能做輪流顯示,用“=”鍵做顯示切換。程序如下:libraryieee;useieee.std_logic_unsigned.all;useieee.std_logic_1164.all;useieee.std_logic_arith.all;entityadder_4isport( clk:instd_logic;--時鐘輸入,應該輸入分頻后的clk enter:instd_logic;--顯示切換,可以理解位“=”鍵 clear:instd_logic;--清除鍵,預留接口可擴展 key_num1:instd_logic_vector(3downto0);--加數1 key_num2:instd_logic_vector(3downto0);--加數2 duan:outstd_logic_vector(6downto0);--輸出結果 wei:outstd_logic_vector(3downto0); led5:outstd_logic_vector(4downto0)--led結果顯示 );endentity;architecturefunofadder_4issignalnum1,num2:std_logic_vector(3downto0);--中間信號定義signaladd_num1:integerrange15downto0;signaladd_num2:integerrange15downto0;signaladd_sum:integerrange30downto0;signalten_data:integerrange9downto0;signaladd_num1ge,add_num1shi,add_num2ge,add_num2shi,sumge,sumshi:integerrange9downto0;signalwei_data:integerrange0to3;begin duan<="1000000"whenten_data=0else--顯示部分,數碼管共陽 "1111001"whenten_data=1else "0100100"whenten_data=2else "0110000"whenten_data=3else "0111001"whenten_data=4else "0010010"whenten_data=5else "0000010"whenten_data=6else "1111000"whenten_data=7else "0000000"whenten_data=8else "0010000"; process(clk,clear,enter,key_num1,key_num2,num1,num2,add_num1ge,add_num1shi,add_num2ge,add_num2shi,sumge,sumshi) begin ifclear='0'then add_num1<=0; add_num2<=0; add_sum<=0; else --ifkey_num1/="1111"orkey_num2/="1111"then num1<=notkey_num1; num2<=notkey_num2;--加數處理,二進制轉十進制。 add_num1<=conv_integer(num1(0))*1+conv_integer(num1(1))*2+conv_integer(num1(2))*4+conv_integer(num1(3))*8;add_num1ge<=(add_num1rem10);--個位,十位分離 add_num1shi<=((add_num1-add_num1ge)/10); add_num2<=conv_integer(num2(0))*1+conv_integer(num2(1))*2+conv_integer(num2(2))*4+conv_integer(num2(3))*8; add_num2ge<=(add_num2rem10); add_num2shi<=((add_num2-add_num2ge)/10); add_sum<=add_num1+add_num2; sumge<=(add_sumrem10); sumshi<=((add_sum-sumge)/10); led5<=('0'&num1)+('0'&num2); --endif; endif; ifclk'eventandclk='1'then wei_data<=wei_data+1; endif; ifenter='1'then casewei_datais when0=>ten_data<=add_num1ge;wei<="0001"; when1=>ten_data<=add_num1shi;wei<="0010"; when2=>ten_data<=add_num2ge;wei<="0100"; whenothers=>ten_data<=add_num2shi;wei<="1000"; endcase; else casewei_datais when0=>ten_data<=sumge;wei<="0001"; when1=>ten_data<=sumshi;wei<="0010"; when2=>ten_data<=0;wei<="0100"; whenothers=>ten_data<=0;wei<="1000"; endcase; endif; endprocess;endarchitecture;此程序為,在調試兩周之后的沒有問題的,學習班用的CYCLONE_IV_E:以下為50MHZ分頻程序:libraryieee;useieee.std_logic_unsigned.all;useieee.std_logic_1164.all;useieee.std_logic_arith.all;entitydefrequanceisport( in_5khz:instd_logic; out_1hz:outstd_logic );endentitydefrequance;architecturefunofdefrequanceissignalnum:integerrange0to50000;beginprocess(in_5khz,num)beginifin_5khz'eventandin_5khz='1'then num<=num+1; ifnum<25000then-- num<=0; out_1hz<='1'; elsifnum>25000andnum<50000then out_1hz<='0'; endif;endif;endpr
溫馨提示
- 1. 本站所有資源如無特殊說明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請下載最新的WinRAR軟件解壓。
- 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請聯系上傳者。文件的所有權益歸上傳用戶所有。
- 3. 本站RAR壓縮包中若帶圖紙,網頁內容里面會有圖紙預覽,若沒有圖紙預覽就沒有圖紙。
- 4. 未經權益所有人同意不得將文件中的內容挪作商業或盈利用途。
- 5. 人人文庫網僅提供信息存儲空間,僅對用戶上傳內容的表現方式做保護處理,對用戶上傳分享的文檔內容本身不做任何修改或編輯,并不能對任何下載內容負責。
- 6. 下載文件中如有侵權或不適當內容,請與我們聯系,我們立即糾正。
- 7. 本站不保證下載資源的準確性、安全性和完整性, 同時也不承擔用戶因使用這些下載資源對自己和他人造成任何形式的傷害或損失。
最新文檔
- 港口碼頭建設安全施工方案及措施
- 汽車制造項目經理部各崗位職責他
- JL1901年度供應鏈管理內部審核計劃
- 熱力管網施工安全文明施工措施
- 三年級上冊地方課程教學計劃推進他
- 2025年度幼兒園團支部團隊建設計劃
- 物流運輸警示教育懺悔錄心得體會
- 護理質量安全事件調查職責
- 教師信息技術教學方法創新計劃
- 期貨模擬交易心得體會及技術應用
- 心力衰竭患者常用食物含水量表
- 鎖骨下動脈竊血綜合征 (2)PPT
- 2022年人教八級下英語單詞英譯漢
- 大班社會《愛發脾氣的菲菲》課件
- 公路工程項目代建制管理辦法(218頁編制詳細)
- NX空間系統熱簡介復習課程
- 納米氧化鋅實驗報告(共9頁)
- 自粘聚合物改性瀝青防水卷材施工
- 青少年科技創新PPT
- 美麗鄉村片區內監理規劃范本
- 曉明煤礦副井過卷緩沖裝置安裝措施
評論
0/150
提交評論