




版權說明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權,請進行舉報或認領
文檔簡介
1、摘要: 計算器(calculator ;counter)一般是指“電子計算器”,該名詞由日文傳入中國。計算器能進行數(shù)學運算。計算器一般由運算器、控制器、存儲器、鍵盤、顯示器、電源和一些可選外圍設備組成。低檔計算器的運算器、控制器由數(shù)字邏輯電路實現(xiàn)簡單的串行運算,其隨機存儲器只有一、二個單元,供累加存儲用。使用簡單計算器可進行加(+)、減(-)、乘(*)、除(/)、開方(sqrt)、百分數(shù)(%)、倒數(shù)(1/x)等簡單算術計算。本次設計只完成加(+)、減(-)、乘(*)、除(/)運算。關鍵字:加減乘除、優(yōu)先級、進制轉換、數(shù)據(jù)選擇、有效數(shù)字、正負1 設計內(nèi)容與設計要求1、1基本內(nèi)容:設計一個簡易計算
2、器1、2基本要求:實現(xiàn)最大輸入兩位十進制數(shù)字的四則運算(加減乘除)能夠實現(xiàn)多次連算(無優(yōu)先級,從左到右計算結果)如 12+34×56-78÷90+9=36.75最大長度以數(shù)碼管最大個數(shù)為限,溢出報警有正負數(shù)區(qū)分;除法不能除盡時小數(shù)保留2位有效數(shù)字1、3擴展要求:能夠區(qū)分運算優(yōu)先級(先乘除,后加減)如12+34×56-78÷90+9=1924.13 2 方案選擇能夠進行區(qū)分優(yōu)先級的計算,先乘除,后加減。 乘除運算同步進行,從左往右; 乘除結束后的數(shù)據(jù)進行加減運算。 3 系統(tǒng)具體設計3、1總體框架(總電路圖附錄1)數(shù)據(jù)(包括正負)除乘 若出現(xiàn)加減符號或第一次
3、計算,結果反饋的都是輸入的數(shù)據(jù)結果反饋輸出選擇乘或除的結果輸出乘法運算包括一個乘法器乘法運算 包括一個乘法器結果輸出或數(shù)據(jù)選擇輸出進行加減法運算根據(jù)加減法選擇數(shù)據(jù)正負,a-b即a+(-b)注:各主要模塊都加reset復位進制轉換輸出3、2各個模塊設計乘法模塊(VHDL附錄2)當乘法符號的上升沿的時候讀入反饋的結果(包括數(shù)據(jù)及正負號)并輸出到data1、data1_pn; 當乘法符號的下降沿的時候讀入數(shù)據(jù)(包括數(shù)據(jù)及正負號)并輸出到data2、data2_pn。并進行計算,結果的數(shù)據(jù)由乘法器計算得到;結果的正負號即為兩個相乘數(shù)據(jù)的正負號取異或。數(shù)據(jù)為保留兩位小數(shù),輸出的當成被乘數(shù)的數(shù)乘上100。
4、元件例化: 除法模塊(VHDL附錄3)當除法符號的上升沿的時候讀入反饋的結果(包括數(shù)據(jù)及正負號)并輸出到data1、data1_pn; 當除法符號的下降沿的時候讀入數(shù)據(jù)(包括數(shù)據(jù)及正負號)并輸出到data2、data2_pn。并進行計算,結果的數(shù)據(jù)由除法器計算得到;結果的正負號即為兩個相除數(shù)據(jù)的正負號取異或。數(shù)據(jù)為保留兩位小數(shù),輸出的當成被除數(shù)的數(shù)乘上100。元件例化:乘或除數(shù)據(jù)選擇輸出模塊(VHDL附錄4)乘或除的數(shù)據(jù)及正負在各自符號的下降沿時輸出,在輸出時確定輸出的是乘的結果還是除的結果。即預期在乘符號的下降沿時輸出乘的結果;在除符號的下降沿時輸出除的結果。又由于兩個時鐘信號不能控制同一個
5、變量,所以把clk1當成是清零信號,clk2當成時鐘信號,當clk2的下降沿的時候輸出數(shù)據(jù)2(即除的結果),clk2為1時,輸出數(shù)據(jù)1(即除的結果)。又為了防止clk2為1與其后面要用到的上升沿沖突,故添加dout。元件例化:結果反饋及輸出模塊(VHDL附錄5)當?shù)谝淮芜M行運算或出現(xiàn)過加減再進行乘除的第一次運算時讀取輸入的數(shù)據(jù)值,否則讀取前一級的結果值。其中clr為恢復信號(加or 減),當其為1時,恢復到第一次運算的模式。clk本為乘或除,又為了避開與上一級的清零錯位,故其變?yōu)?乘or(除and not dout)元件例化: 加減選擇模塊(VHDL附錄6) 減法是加法的逆運算,A-B等同于A
6、+(-B),即減法運算只需在進行加法運算前把數(shù)據(jù)的正負取反,所以當減法的下降沿時輸出的正負為輸入的取反,加法的下降沿時輸出的正負為輸入的,實現(xiàn)方法與乘除選擇模塊一致。 元件例化:加減運算模塊(VHDL附錄7)由于上一級已考慮加減情況,此模塊只需實現(xiàn)加法運算。A+B有四種情況: 1、A>0,B>0 輸出數(shù)據(jù)A+B,正負號為正 2、A>0,B<0 |A|>|B| 輸出數(shù)據(jù)|A|-|B| 正負號為正 |A|<|B| 輸出數(shù)據(jù)|B|-|A| 正負號為負3、A<0,B>0 |A|>|B| 輸出數(shù)據(jù)|A|-|B| 正負號為負 |A|<|B| 輸出
7、數(shù)據(jù)|B|-|A| 正負號為正4、A<0,B<0 輸出數(shù)據(jù)A+B,正負號為負 其中clk為加or減,上升沿時讀新數(shù)據(jù)并計算。元件例化: 數(shù)據(jù)輸出選擇模塊(VHDL附錄8) 當按下等號時輸出計算結果,否則輸出輸入的數(shù)據(jù)。當輸出為負時:第一個數(shù)碼管顯示F;當輸出為負時:第一個數(shù)碼管顯示E;當數(shù)據(jù)超出范圍溢出是第一個數(shù)碼管顯示C。元件例化:進制轉換模塊28位二進制數(shù)(根據(jù)7個數(shù)碼管為限,最大輸出為十進制的9999999,后兩位為小數(shù)位)以十進制的方式顯示到數(shù)碼管上,采用各位求余分別顯示的方法。其中除數(shù)分別為十進制的1000000、100000、10000、1000、100、10,需要輸出
8、的是每次相除后的商及最后一個余數(shù)。元件例化:其實現(xiàn)電路:數(shù)據(jù)輸入模塊(VHDL附錄9)受限于輸入按鍵有限,輸入的兩位二進制數(shù)有計數(shù)器實現(xiàn),每按下clk加1,到99后恢復零元件例化:4 系統(tǒng)測試4、1 波形仿真及部分仿真結果仿真的式子為12+34×56-78÷90+9 結果數(shù)據(jù)為192414,代表1924.14 正負為E,代表正理論結果為1924.13,仿真結果符合。仿真的式子為(-12)+34×(-56)-78÷90+9 結果數(shù)據(jù)為190786,代表1907.86正負為F, 代表負理論結果為-1907.87,仿真結果符合。仿真的式子為90*90*90 結
9、果數(shù)據(jù)為0,代表0正負為C,代表溢出理論結果為27000.00,為溢出,仿真結果符合。4、2 下載到實驗箱進行驗證輸入:key4:加key3:減key2:乘key1:除key5:正、負(不亮時為正,亮時為負)key6:等號 (不亮時為輸出為數(shù)據(jù),亮時輸出為計算結果)key7:復位key8:數(shù)據(jù)累加輸入 輸出顯示:從左到右,第一個數(shù)碼管顯示正負或溢出,后七個輸出輸入數(shù)據(jù)或結果。 驗證:1、按正確方式按入式子1+2×3÷4-5÷6×15+25 輸出結果E 0 0 0 1 5 0 0 代表正15.00 和理論值15一致。 2、按正確方式按入式子12+25
10、47;31×(-45) -46 輸出結果F 0 0 0 7 0 2 9 代表正-70.29 和理論值70.29一致。 3、按正確方式按入式子10×10×10×10×10 輸出結果C 0 0 0 0 0 0 0 代表溢出 理論值為100000,溢出,符合要求。5 實驗結論: 由仿真結果和下載驗證結果可知: 設計的計算器能夠:實現(xiàn)最大輸入兩位十進制數(shù)字的四則運算(加減乘除);最大長度以數(shù)碼管最大個數(shù)(數(shù)據(jù)顯示7個,正負號或溢出顯示為1個)為限,溢出報警;有正負數(shù)區(qū)分;結果保留2位小數(shù);能夠區(qū)分運算優(yōu)先級(先乘除,后加減);附錄1附錄2(乘法模塊)l
11、ibrary ieee;use ieee.std_logic_1164.all;use ieee.std_logic_arith.all;use ieee.std_logic_unsigned.all;entity mul is port( clk : in std_logic; reset: in std_logic; data : in std_logic_vector(7 downto 0); data_pn : in std_logic; res : in std_logic_vector(27 downto 0); res_pn: in std_logic; data1: out s
12、td_logic_vector(27 downto 0); data2: out std_logic_vector(7 downto 0); data1_pn:out std_logic; data2_pn:out std_logic );end entity mul;architecture behave of mul is signal temp1:std_logic;signal temp2:std_logic;beginprocess(reset,clk)beginif(reset='0')then if(clk'event and clk='1'
13、;)then data1<=res; data1_pn<=res_pn; end if; if(clk'event and clk='0')then data2<=data; data2_pn<=data_pn; end if;else data1<="0000000000000000000000000000"data2<="00000000"end if;end process;end behave;附錄3(除法模塊)library ieee;use ieee.std_logic_1164.a
14、ll;use ieee.std_logic_arith.all;use ieee.std_logic_unsigned.all;entity div is port( clk : in std_logic; reset: in std_logic; data : in std_logic_vector(7 downto 0); data_pn : in std_logic; res : in std_logic_vector(27 downto 0); res_pn: in std_logic; data1: out std_logic_vector(27 downto 0); data2:
15、out std_logic_vector(7 downto 0); data1_pn:out std_logic; data2_pn:out std_logic );end entity div;architecture behave of div is signal temp1:std_logic;signal temp2:std_logic;beginprocess(reset,clk)beginif(reset='0')then if(clk'event and clk='1')then data1<=res; data1_pn<=re
16、s_pn; end if; if(clk'event and clk='0')then data2<=data; data2_pn<=data_pn; end if;else data1<="0000000000000000000000000000"data2<="00000000"end if;end process;end behave;附錄4(乘或除數(shù)據(jù)選擇輸出模塊)library ieee;use ieee.std_logic_1164.all;use ieee.std_logic_arith.al
17、l;use ieee.std_logic_unsigned.all;entity tt is port( reset:in std_logic; pn1:in std_logic; pn2:in std_logic; res1:in std_logic_vector(27 downto 0 ); res2:in std_logic_vector(27 downto 0 ); clk1: in std_logic; clk2: in std_logic; resout: out std_logic_vector(27 downto 0 ); pnout:out std_logic; dout:o
18、ut std_logic );end entity tt;architecture behave of tt is signal temp:std_logic;begin dout<=temp; process(clk1,clk2)beginif(reset='0')thenif(clk1='1')then temp<='0'elsif(clk2'event and clk2='0')then temp<='1'end if;if(temp='1')then resout&
19、lt;=res2;pnout<=pn2;else resout<=res1;pnout<=pn1;end if;else temp<='0'end if;end process;end behave;附錄5(結果反饋及輸出模塊)library ieee;use ieee.std_logic_1164.all;use ieee.std_logic_arith.all;use ieee.std_logic_unsigned.all;entity res_cs is port( reset:in std_logic; data: in std_logic_ve
20、ctor(7 downto 0); data_pn: in std_logic; clr: in std_logic; clk: in std_logic; res: in std_logic_vector(27 downto 0); res_pn:in std_logic; result: out std_logic_vector(27 downto 0); result_pn:out std_logic );end entity res_cs;architecture behave of res_cs is signal cn:std_logic_vector(3 downto 0);be
21、ginprocess(clk,clr)beginif(reset='0')thenif(clr='0')then if(cn="0000")then result<="0000000000000"&(data*"1100100");result_pn<=data_pn; else result<=res;result_pn<=res_pn; end if; if(clk'event and clk='1')then cn<=cn+1; end
22、 if;else cn<="0000"end if;else cn<="0000"end if;end process;end behave;附錄6(加減選擇模塊)library ieee;use ieee.std_logic_1164.all;use ieee.std_logic_arith.all;use ieee.std_logic_unsigned.all;entity tt2 is port( reset:in std_logic; pn:in std_logic; clk1: in std_logic; clk2: in std_
23、logic; pnout:out std_logic; dout:out std_logic );end entity tt2;architecture behave of tt2 is signal temp:std_logic;begin dout<=temp; process(clk1,clk2)beginif(reset='0')thenif(clk1='1')then temp<='0'elsif(clk2'event and clk2='0')then temp<='1'end
24、 if;if(temp='1')then pnout<=not(pn);else pnout<=pn;end if;else temp<='0'end if;end process;end behave;附錄7(加減運算模塊)library ieee;use ieee.std_logic_1164.all;use ieee.std_logic_arith.all;use ieee.std_logic_unsigned.all;entity add is port(clk :in std_logic; reset:in std_logic; da
25、ta:in std_logic_vector(27 downto 0); data_pn:in std_logic; dout :out std_logic_vector(27 downto 0); dout_pn:out std_logic );end entity add;architecture behave of add is signal temp: std_logic_vector(27 downto 0):="0000000000000000000000000000"signal temp_pn:std_logic:='0'begindout&
26、lt;=temp;dout_pn<=temp_pn;process(clk,reset)beginif(reset='1')then temp<="0000000000000000000000000000"temp_pn<='0'elsif(clk'event and clk='1')then if(temp_pn='0')then if(data_pn='0')then temp<=temp+data;temp_pn<='0' else i
27、f(temp>data or temp=data)then temp<=temp-data;temp_pn<='0' else temp<=data-temp;temp_pn<='1' end if; end if; else if(data_pn='1')then temp<=temp+data;temp_pn<='1' else if(temp<data or temp=data)then temp<=data-temp;temp_pn<='0' el
28、se temp<=temp-data;temp_pn<='1' end if; end if; end if;end if;end process;end behave; 附錄8(數(shù)據(jù)輸出選擇模塊)library ieee;use ieee.std_logic_1164.all;use ieee.std_logic_arith.all;use ieee.std_logic_unsigned.all;entity choose_out is port( reset: in std_logic; equal : in std_logic; data: in std_lo
29、gic_vector(7 downto 0); data_pn : in std_logic; res : in std_logic_vector(27 downto 0); res_pn: in std_logic; result:out std_logic_vector(27 downto 0); result_pn:out std_logic_vector(3 downto 0)-正輸出E 負輸出F 溢出輸出C );end entity choose_out;architecture behave of choose_out is beginprocess(reset,equal)beginif(reset='0')then if(equal='0')then result<="00000000000000000000"&data; if(data_pn='0')then result_pn<="1110" else result_pn<="1111" end
溫馨提示
- 1. 本站所有資源如無特殊說明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請下載最新的WinRAR軟件解壓。
- 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請聯(lián)系上傳者。文件的所有權益歸上傳用戶所有。
- 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁內(nèi)容里面會有圖紙預覽,若沒有圖紙預覽就沒有圖紙。
- 4. 未經(jīng)權益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
- 5. 人人文庫網(wǎng)僅提供信息存儲空間,僅對用戶上傳內(nèi)容的表現(xiàn)方式做保護處理,對用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對任何下載內(nèi)容負責。
- 6. 下載文件中如有侵權或不適當內(nèi)容,請與我們聯(lián)系,我們立即糾正。
- 7. 本站不保證下載資源的準確性、安全性和完整性, 同時也不承擔用戶因使用這些下載資源對自己和他人造成任何形式的傷害或損失。
最新文檔
- 公司高管管理職責證明書(5篇)
- 學校食堂供應管理協(xié)議
- 能源資源節(jié)約和綜合利用協(xié)議
- 電商行業(yè)網(wǎng)絡購物退換貨免責合同
- 全面理解2025年行政管理中的公文處理試題答案
- 2025行政管理中市政學的重要性試題及答案
- 現(xiàn)代管理者的決策典型案例分析試題及答案
- 解析2025年市政學考試試題及答案的技巧
- 2025年合同將滿到期后員工能否獲得年終獎
- 2025年湖南省國有企業(yè)土地使用權轉讓合同書
- 幼兒園接送制度優(yōu)化方案
- 噢易教育桌面云解決方案
- 英語中國文化
- GB/T 18376.2-2024硬質(zhì)合金牌號第2部分:鑿巖及工程用硬質(zhì)合金牌號
- 2018中國癡呆與認知障礙診治指南(九)中國記憶障礙門診建立規(guī)范(全文版)
- 直腸癌術后吻合口瘺課件
- 【MOOC】基因與健康-鄭州大學 中國大學慕課MOOC答案
- 脫髓鞘病淋巴瘤
- 醫(yī)療健康管理大數(shù)據(jù)平臺
- 美的集團應收賬款管理的答辯
- 皮膚科前景規(guī)劃
評論
0/150
提交評論