




版權(quán)說明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請(qǐng)進(jìn)行舉報(bào)或認(rèn)領(lǐng)
文檔簡(jiǎn)介
1、摘要: 計(jì)算器(calculator ;counter)一般是指“電子計(jì)算器”,該名詞由日文傳入中國(guó)。計(jì)算器能進(jìn)行數(shù)學(xué)運(yùn)算。計(jì)算器一般由運(yùn)算器、控制器、存儲(chǔ)器、鍵盤、顯示器、電源和一些可選外圍設(shè)備組成。低檔計(jì)算器的運(yùn)算器、控制器由數(shù)字邏輯電路實(shí)現(xiàn)簡(jiǎn)單的串行運(yùn)算,其隨機(jī)存儲(chǔ)器只有一、二個(gè)單元,供累加存儲(chǔ)用。使用簡(jiǎn)單計(jì)算器可進(jìn)行加(+)、減(-)、乘(*)、除(/)、開方(sqrt)、百分?jǐn)?shù)(%)、倒數(shù)(1/x)等簡(jiǎn)單算術(shù)計(jì)算。本次設(shè)計(jì)只完成加(+)、減(-)、乘(*)、除(/)運(yùn)算。關(guān)鍵字:加減乘除、優(yōu)先級(jí)、進(jìn)制轉(zhuǎn)換、數(shù)據(jù)選擇、有效數(shù)字、正負(fù)1 設(shè)計(jì)內(nèi)容與設(shè)計(jì)要求1、1基本內(nèi)容:設(shè)計(jì)一個(gè)簡(jiǎn)易計(jì)算
2、器1、2基本要求:實(shí)現(xiàn)最大輸入兩位十進(jìn)制數(shù)字的四則運(yùn)算(加減乘除)能夠?qū)崿F(xiàn)多次連算(無優(yōu)先級(jí),從左到右計(jì)算結(jié)果)如 12+34×56-78÷90+9=36.75最大長(zhǎng)度以數(shù)碼管最大個(gè)數(shù)為限,溢出報(bào)警有正負(fù)數(shù)區(qū)分;除法不能除盡時(shí)小數(shù)保留2位有效數(shù)字1、3擴(kuò)展要求:能夠區(qū)分運(yùn)算優(yōu)先級(jí)(先乘除,后加減)如12+34×56-78÷90+9=1924.13 2 方案選擇能夠進(jìn)行區(qū)分優(yōu)先級(jí)的計(jì)算,先乘除,后加減。 乘除運(yùn)算同步進(jìn)行,從左往右; 乘除結(jié)束后的數(shù)據(jù)進(jìn)行加減運(yùn)算。 3 系統(tǒng)具體設(shè)計(jì)3、1總體框架(總電路圖附錄1)數(shù)據(jù)(包括正負(fù))除乘 若出現(xiàn)加減符號(hào)或第一次
3、計(jì)算,結(jié)果反饋的都是輸入的數(shù)據(jù)結(jié)果反饋輸出選擇乘或除的結(jié)果輸出乘法運(yùn)算包括一個(gè)乘法器乘法運(yùn)算 包括一個(gè)乘法器結(jié)果輸出或數(shù)據(jù)選擇輸出進(jìn)行加減法運(yùn)算根據(jù)加減法選擇數(shù)據(jù)正負(fù),a-b即a+(-b)注:各主要模塊都加reset復(fù)位進(jìn)制轉(zhuǎn)換輸出3、2各個(gè)模塊設(shè)計(jì)乘法模塊(VHDL附錄2)當(dāng)乘法符號(hào)的上升沿的時(shí)候讀入反饋的結(jié)果(包括數(shù)據(jù)及正負(fù)號(hào))并輸出到data1、data1_pn; 當(dāng)乘法符號(hào)的下降沿的時(shí)候讀入數(shù)據(jù)(包括數(shù)據(jù)及正負(fù)號(hào))并輸出到data2、data2_pn。并進(jìn)行計(jì)算,結(jié)果的數(shù)據(jù)由乘法器計(jì)算得到;結(jié)果的正負(fù)號(hào)即為兩個(gè)相乘數(shù)據(jù)的正負(fù)號(hào)取異或。數(shù)據(jù)為保留兩位小數(shù),輸出的當(dāng)成被乘數(shù)的數(shù)乘上100。
4、元件例化: 除法模塊(VHDL附錄3)當(dāng)除法符號(hào)的上升沿的時(shí)候讀入反饋的結(jié)果(包括數(shù)據(jù)及正負(fù)號(hào))并輸出到data1、data1_pn; 當(dāng)除法符號(hào)的下降沿的時(shí)候讀入數(shù)據(jù)(包括數(shù)據(jù)及正負(fù)號(hào))并輸出到data2、data2_pn。并進(jìn)行計(jì)算,結(jié)果的數(shù)據(jù)由除法器計(jì)算得到;結(jié)果的正負(fù)號(hào)即為兩個(gè)相除數(shù)據(jù)的正負(fù)號(hào)取異或。數(shù)據(jù)為保留兩位小數(shù),輸出的當(dāng)成被除數(shù)的數(shù)乘上100。元件例化:乘或除數(shù)據(jù)選擇輸出模塊(VHDL附錄4)乘或除的數(shù)據(jù)及正負(fù)在各自符號(hào)的下降沿時(shí)輸出,在輸出時(shí)確定輸出的是乘的結(jié)果還是除的結(jié)果。即預(yù)期在乘符號(hào)的下降沿時(shí)輸出乘的結(jié)果;在除符號(hào)的下降沿時(shí)輸出除的結(jié)果。又由于兩個(gè)時(shí)鐘信號(hào)不能控制同一個(gè)
5、變量,所以把clk1當(dāng)成是清零信號(hào),clk2當(dāng)成時(shí)鐘信號(hào),當(dāng)clk2的下降沿的時(shí)候輸出數(shù)據(jù)2(即除的結(jié)果),clk2為1時(shí),輸出數(shù)據(jù)1(即除的結(jié)果)。又為了防止clk2為1與其后面要用到的上升沿沖突,故添加dout。元件例化:結(jié)果反饋及輸出模塊(VHDL附錄5)當(dāng)?shù)谝淮芜M(jìn)行運(yùn)算或出現(xiàn)過加減再進(jìn)行乘除的第一次運(yùn)算時(shí)讀取輸入的數(shù)據(jù)值,否則讀取前一級(jí)的結(jié)果值。其中clr為恢復(fù)信號(hào)(加or 減),當(dāng)其為1時(shí),恢復(fù)到第一次運(yùn)算的模式。clk本為乘或除,又為了避開與上一級(jí)的清零錯(cuò)位,故其變?yōu)?乘or(除and not dout)元件例化: 加減選擇模塊(VHDL附錄6) 減法是加法的逆運(yùn)算,A-B等同于A
6、+(-B),即減法運(yùn)算只需在進(jìn)行加法運(yùn)算前把數(shù)據(jù)的正負(fù)取反,所以當(dāng)減法的下降沿時(shí)輸出的正負(fù)為輸入的取反,加法的下降沿時(shí)輸出的正負(fù)為輸入的,實(shí)現(xiàn)方法與乘除選擇模塊一致。 元件例化:加減運(yùn)算模塊(VHDL附錄7)由于上一級(jí)已考慮加減情況,此模塊只需實(shí)現(xiàn)加法運(yùn)算。A+B有四種情況: 1、A>0,B>0 輸出數(shù)據(jù)A+B,正負(fù)號(hào)為正 2、A>0,B<0 |A|>|B| 輸出數(shù)據(jù)|A|-|B| 正負(fù)號(hào)為正 |A|<|B| 輸出數(shù)據(jù)|B|-|A| 正負(fù)號(hào)為負(fù)3、A<0,B>0 |A|>|B| 輸出數(shù)據(jù)|A|-|B| 正負(fù)號(hào)為負(fù) |A|<|B| 輸出
7、數(shù)據(jù)|B|-|A| 正負(fù)號(hào)為正4、A<0,B<0 輸出數(shù)據(jù)A+B,正負(fù)號(hào)為負(fù) 其中clk為加or減,上升沿時(shí)讀新數(shù)據(jù)并計(jì)算。元件例化: 數(shù)據(jù)輸出選擇模塊(VHDL附錄8) 當(dāng)按下等號(hào)時(shí)輸出計(jì)算結(jié)果,否則輸出輸入的數(shù)據(jù)。當(dāng)輸出為負(fù)時(shí):第一個(gè)數(shù)碼管顯示F;當(dāng)輸出為負(fù)時(shí):第一個(gè)數(shù)碼管顯示E;當(dāng)數(shù)據(jù)超出范圍溢出是第一個(gè)數(shù)碼管顯示C。元件例化:進(jìn)制轉(zhuǎn)換模塊28位二進(jìn)制數(shù)(根據(jù)7個(gè)數(shù)碼管為限,最大輸出為十進(jìn)制的9999999,后兩位為小數(shù)位)以十進(jìn)制的方式顯示到數(shù)碼管上,采用各位求余分別顯示的方法。其中除數(shù)分別為十進(jìn)制的1000000、100000、10000、1000、100、10,需要輸出
8、的是每次相除后的商及最后一個(gè)余數(shù)。元件例化:其實(shí)現(xiàn)電路:數(shù)據(jù)輸入模塊(VHDL附錄9)受限于輸入按鍵有限,輸入的兩位二進(jìn)制數(shù)有計(jì)數(shù)器實(shí)現(xiàn),每按下clk加1,到99后恢復(fù)零元件例化:4 系統(tǒng)測(cè)試4、1 波形仿真及部分仿真結(jié)果仿真的式子為12+34×56-78÷90+9 結(jié)果數(shù)據(jù)為192414,代表1924.14 正負(fù)為E,代表正理論結(jié)果為1924.13,仿真結(jié)果符合。仿真的式子為(-12)+34×(-56)-78÷90+9 結(jié)果數(shù)據(jù)為190786,代表1907.86正負(fù)為F, 代表負(fù)理論結(jié)果為-1907.87,仿真結(jié)果符合。仿真的式子為90*90*90 結(jié)
9、果數(shù)據(jù)為0,代表0正負(fù)為C,代表溢出理論結(jié)果為27000.00,為溢出,仿真結(jié)果符合。4、2 下載到實(shí)驗(yàn)箱進(jìn)行驗(yàn)證輸入:key4:加key3:減key2:乘key1:除key5:正、負(fù)(不亮?xí)r為正,亮?xí)r為負(fù))key6:等號(hào) (不亮?xí)r為輸出為數(shù)據(jù),亮?xí)r輸出為計(jì)算結(jié)果)key7:復(fù)位key8:數(shù)據(jù)累加輸入 輸出顯示:從左到右,第一個(gè)數(shù)碼管顯示正負(fù)或溢出,后七個(gè)輸出輸入數(shù)據(jù)或結(jié)果。 驗(yàn)證:1、按正確方式按入式子1+2×3÷4-5÷6×15+25 輸出結(jié)果E 0 0 0 1 5 0 0 代表正15.00 和理論值15一致。 2、按正確方式按入式子12+25
10、47;31×(-45) -46 輸出結(jié)果F 0 0 0 7 0 2 9 代表正-70.29 和理論值70.29一致。 3、按正確方式按入式子10×10×10×10×10 輸出結(jié)果C 0 0 0 0 0 0 0 代表溢出 理論值為100000,溢出,符合要求。5 實(shí)驗(yàn)結(jié)論: 由仿真結(jié)果和下載驗(yàn)證結(jié)果可知: 設(shè)計(jì)的計(jì)算器能夠:實(shí)現(xiàn)最大輸入兩位十進(jìn)制數(shù)字的四則運(yùn)算(加減乘除);最大長(zhǎng)度以數(shù)碼管最大個(gè)數(shù)(數(shù)據(jù)顯示7個(gè),正負(fù)號(hào)或溢出顯示為1個(gè))為限,溢出報(bào)警;有正負(fù)數(shù)區(qū)分;結(jié)果保留2位小數(shù);能夠區(qū)分運(yùn)算優(yōu)先級(jí)(先乘除,后加減);附錄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(結(jié)果反饋及輸出模塊)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(加減運(yùn)算模塊)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ù)輸出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等.壓縮文件請(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ì)自己和他人造成任何形式的傷害或損失。
最新文檔
- 連鎖超市轉(zhuǎn)讓協(xié)議書
- 車位租賃合同協(xié)議書
- 順豐司機(jī)合同協(xié)議書
- 金融委托貸款協(xié)議書
- 造價(jià)咨詢股東協(xié)議書
- Brand KPIs for second-hand apparel online shops IN LOVE AGAIN in Germany-外文版培訓(xùn)課件(2025.2)
- 長(zhǎng)期電力交易協(xié)議書
- 餐具貨物配送協(xié)議書
- 閑置資金托管協(xié)議書
- 餐具專版定制協(xié)議書
- 《比亞迪品牌歷史課件》課件
- 小學(xué)心理健康家長(zhǎng)會(huì)課件
- 2025年4月自考00160審計(jì)學(xué)答案含評(píng)分參考
- 購(gòu)買木地板合同協(xié)議
- 嚴(yán)重開放性肢體創(chuàng)傷早期救治專家共識(shí)解讀
- 2025年公共安全管理考試試題及答案
- 速賣通開店考試最權(quán)威答案
- 輸液導(dǎo)管相關(guān)靜脈血栓形成中國(guó)專家共識(shí) 課件
- 國(guó)企崗位筆試題目及答案
- 2024年泉州實(shí)驗(yàn)中學(xué)初一新生入學(xué)考試數(shù)學(xué)試卷
- 航模課程-飛翔的夢(mèng)想
評(píng)論
0/150
提交評(píng)論