北邮数电实验报告副本.docx
- 文档编号:25397045
- 上传时间:2023-06-08
- 格式:DOCX
- 页数:27
- 大小:249.55KB
北邮数电实验报告副本.docx
《北邮数电实验报告副本.docx》由会员分享,可在线阅读,更多相关《北邮数电实验报告副本.docx(27页珍藏版)》请在冰豆网上搜索。
北邮数电实验报告副本
数字电路与逻辑设计
实验报告
姓名:
班级:
学号:
班内序号:
时间:
2015/10/19-2015/11/2
简易计算器实验报告
一、要求要求:
基本要求:
1、利用4X4小键盘作为输入,包括:
数字键0-9,清除键,等号键及‘+’‘-’‘*’运算符号键。
2、实现输入为99以内自然数的加、减、乘运算;
3、能够实现多次连续计算(无优先级,从左到右计算结果),如:
12+34×2-78=14
4、最大结果为99999(五位),溢出报警;
5、用数码管显示输入的数字和结果,最左侧数码管用来表示数字的正负,其他五位数
码管表示结果;结果的绝对值大于99999时,数码管显示‘Error’。
提高要求:
1、实现输入为9999以内自然数的加、减法;
2、实现除法运算,不能除尽时小数保留1位有效数字;
3、能够区分运算优先级(先乘除,后加减),如:
12+34×2-78=2
4、自拟其他功能。
二、系统设计:
设计思路:
1、将该程序进行分模块设计。
可以将程序分为:
主程序、译码模块和防抖模块。
其中,
主程序负责将输入的数据进行存储,对数据进行运算,将数据输出到数码上等;防抖模块负责对按键输入的数防抖;译码模块负责对输入的数据进行译码(由8421bcd码转化为十进制的编码)。
2、分模块进行相应模块的编写。
3、对编好的模块进行测试。
4、编写主程序并进行调试。
总体框图:
流程图:
分块设计:
(按实际操作的分块)
输入模块:
由符号开关和拨码开关构成。
采用序列存储的方式存储相应的输入。
输入译码模块:
将输入的符号序列转化成先用状态,以便选取对应的计算方法;将输入的8421bcd码转化成相应的两位十进制数。
数码显示模块:
将寄存器内的数进行输出到数码管上。
显示所输入的第一个数以及最后的结果。
计算模块:
调用相应的计算方式,对所输入的数进行计算。
防抖模块:
在用按键输入时,所得到的信号可能会有抖动,因此加入此抖动电路。
三、仿真波形及波形分析:
分析(波形仿真时,为了方便观察,将8421bcd码输入方式,改为了十进制的直接输入方式,并将输出,有原来的数码管显示改成了直接数字显示)
由图中可以看出,当输入12,按下“确定”,数字就输入到了寄存器中,输入“+”号(对应仿真中的fuhao“100000”),在输入一个数35,按下“确定”,该计算器就件寄存器中的数与第二次输入的数进行相加,得到结果47。
此时该结果又被直接保存到了寄存器中,继续输入运算符“-”(对应仿真中得fuhao“010000”),输入第三个数18,按下“确定”,计算器对其做减法运算,得到结果29,该结果又在寄存器中存储着。
继续后续输入相应符号,相应数字可以继续进行相应的计算,只要结果在(-99999,99999)之间,就可以一直进行计算。
四、源程序:
主程序:
LIBRARYIEEE;
USEIEEE.STD_LOGIC_1164.ALL;
USEIEEE.STD_LOGIC_ARITH.ALL;
USEIEEE.STD_LOGIC_SIGNED.ALL;
Entitylzjisuanqiis
port(
cat:
OUTSTD_LOGIC_VECTOR(5DOWNTO0);
digital:
OUTSTD_LOGIC_VECTOR(6DOWNTO0);
clk:
instd_logic;
beep:
outstd_logic;
num:
instd_logic_vector(7downto0);
fuhao:
instd_logic_vector(5downto0)
);
endentitylzjisuanqi;
architecturelzoflzjisuanqiis
componenttransform
port(cin:
instd_logic_vector(7downto0);
cout:
outintegerrange0to99);
endcomponent;
componentfangdouIS
PORT(
clk:
INSTD_LOGIC;
key_in:
INSTD_LOGIC_VECTOR(5DOWNTO0);
key_out:
OUTSTD_LOGIC_VECTOR(5DOWNTO0)
);
endcomponent;
typestate_typeis(s0,s1,s2);
signalstate:
state_type;
typetime_typeis(t1,t2,t3,t4,t5,t6);
signaltime1:
time_type;
signalnum1:
integerrange0to99;
signalresult1:
integerrange-99999to99999;
signalresult2:
integerrange-99999to99999;
signalcat0:
integerrange0to9;
signalcat1:
integerrange0to9;
signalcat2:
integerrange0to9;
signalcat3:
integerrange0to9;
signalcat4:
integerrange0to9;
signalcnt:
integerrange0to50000;
signalclk_tmp:
std_logic;
signalffuhao:
std_logic_vector(5downto0);
signalh1:
integerrange0to10;
signall1:
integerrange0to10;
begin
m1:
process(num)
begin
casenum(7downto4)is
when"0000"=>
h1<=0;
when"0001"=>
h1<=1;
when"0010"=>
h1<=2;
when"0011"=>
h1<=3;
when"0100"=>
h1<=4;
when"0101"=>
h1<=5;
when"0110"=>
h1<=6;
when"0111"=>
h1<=7;
when"1000"=>
h1<=8;
when"1001"=>
h1<=9;
whenothers=>
h1<=10;
endcase;
endprocessm1;
m2:
process(num)
begin
casenum(3downto0)is
when"0000"=>
l1<=0;
when"0001"=>
l1<=1;
when"0010"=>
l1<=2;
when"0011"=>
l1<=3;
when"0100"=>
l1<=4;
when"0101"=>
l1<=5;
when"0110"=>
l1<=6;
when"0111"=>
l1<=7;
when"1000"=>
l1<=8;
when"1001"=>
l1<=9;
whenothers=>
l1<=10;
endcase;
endprocessm2;
num1<=h1*10+l1;
--u1:
transformportmap(cin=>num,cout=>num1);
u2:
fangdouportmap(clk=>clk,key_in=>fuhao,key_out=>ffuhao);
process(clk)
begin
if(clk'eventandclk='1')then
ifcnt=49999then
cnt<=0;
clk_tmp<=notclk_tmp;
else
cnt<=cnt+1;
endif;
endif;
endprocess;
p1:
process(clk_tmp)
variableresult:
integerrange-9999999to9999999;
variablefuhao1:
integerrange0to6:
=0;
begin
if(clk_tmp'eventandclk_tmp='1')then
casestateis
whens0=>result:
=num1;
state<=s1;
whens1=>
if(ffuhao="000010")then
fuhao1:
=0;state<=s1;
elsif(ffuhao="000001")then
result:
=num1;fuhao1:
=0;state<=s0;beep<='0';
elsif(ffuhao="001000")then
fuhao1:
=3;
state<=s2;
elsif(ffuhao="010000")then
fuhao1:
=2;
state<=s2;
elsif(ffuhao="100000")then
fuhao1:
=1;
state<=s2;
elsestate<=s1;
endif;
whens2=>if(fuhao1=0)then
result:
=result;state<=s1;
elsif(fuhao1=1)then
result:
=result+num1;
if(result>99999orresult<-99999)then
result:
=num1;beep<='1';state<=s0;
elsebeep<='0';state<=s1;
endif;
elsif(fuhao1=2)then
result:
=result-num1;
if(result>99999orresult<-99999)then
result:
=num1;beep<='1';state<=s0;
elsebeep<='0';state<=s1;
endif;
elsif(fuhao1=3)then
result:
=result*num1;
if(result>99999orresult<-99999)then
result:
=num1;beep<='1';state<=s0;
elsebeep<='0';state<=s1;
endif;
endif;
endcase;
result2<=result;
if(result2<0)thenresult1<=abs(result2);
elseresult1<=result;
endif;
if(result1>=90000)thencat4<=9;
elsif(result1>=80000andresult1<90000)thencat4<=8;
elsif(result1>=70000andresult1<80000)thencat4<=7;
elsif(result1>=60000andresult1<70000)thencat4<=6;
elsif(result1>=50000andresult1<60000)thencat4<=5;
elsif(result1>=40000andresult1<50000)thencat4<=4;
elsif(result1>=30000andresult1<40000)thencat4<=3;
elsif(result1>=20000andresult1<30000)thencat4<=2;
elsif(result1>=10000andresult1<20000)thencat4<=1;
elsif(result1<10000)thencat4<=0;
endif;
if((result1-cat4*10000)>=9000and(result1-cat4*10000)<10000)thencat3<=9;
elsif((result1-cat4*10000)>=8000and(result1-cat4*10000)<9000)thencat3<=8;
elsif((result1-cat4*10000)>=7000and(result1-cat4*10000)<8000)thencat3<=7;
elsif((result1-cat4*10000)>=6000and(result1-cat4*10000)<7000)thencat3<=6;
elsif((result1-cat4*10000)>=5000and(result1-cat4*10000)<6000)thencat3<=5;
elsif((result1-cat4*10000)>=4000and(result1-cat4*10000)<5000)thencat3<=4;
elsif((result1-cat4*10000)>=3000and(result1-cat4*10000)<4000)thencat3<=3;
elsif((result1-cat4*10000)>=2000and(result1-cat4*10000)<3000)thencat3<=2;
elsif((result1-cat4*10000)>=1000and(result1-cat4*10000)<2000)thencat3<=1;
elsif((result1-cat4*10000)<1000)thencat3<=0;
endif;
if((result1-cat4*10000-cat3*1000)>=900and(result-cat4*10000-cat3*1000)<1000)thencat2<=9;
elsif((result1-cat4*10000-cat3*1000)>=800and(result1-cat4*10000-cat3*1000)<900)thencat2<=8;
elsif((result1-cat4*10000-cat3*1000)>=700and(result1-cat4*10000-cat3*1000)<800)thencat2<=7;
elsif((result1-cat4*10000-cat3*1000)>=600and(result1-cat4*10000-cat3*1000)<700)thencat2<=6;
elsif((result1-cat4*10000-cat3*1000)>=500and(result1-cat4*10000-cat3*1000)<600)thencat2<=5;
elsif((result1-cat4*10000-cat3*1000)>=400and(result1-cat4*10000-cat3*1000)<500)thencat2<=4;
elsif((result1-cat4*10000-cat3*1000)>=300and(result1-cat4*10000-cat3*1000)<400)thencat2<=3;
elsif((result1-cat4*10000-cat3*1000)>=200and(result1-cat4*10000-cat3*1000)<300)thencat2<=2;
elsif((result1-cat4*10000-cat3*1000)>=100and(result1-cat4*10000-cat3*1000)<200)thencat2<=1;
elsif((result1-cat4*10000-cat3*1000)<100)thencat2<=0;
endif;
if((result1-cat4*10000-cat3*1000-cat2*100)>=90and(result1-cat4*10000-cat3*1000-cat2*100)<100)thencat1<=9;
elsif((result1-cat4*10000-cat3*1000-cat2*100)>=80and(result1-cat4*10000-cat3*1000-cat2*100)<90)thencat1<=8;
elsif((result1-cat4*10000-cat3*1000-cat2*100)>=70and(result1-cat4*10000-cat3*1000-cat2*100)<80)thencat1<=7;
elsif((result1-cat4*10000-cat3*1000-cat2*100)>=60and(result1-cat4*10000-cat3*1000-cat2*100)<70)thencat1<=6;
elsif((result1-cat4*10000-cat3*1000-cat2*100)>=50and(result1-cat4*10000-cat3*1000-cat2*100)<60)thencat1<=5;
elsif((result1-cat4*10000-cat3*1000-cat2*100)>=40and(result1-cat4*10000-cat3*1000-cat2*100)<50)thencat1<=4;
elsif((result1-cat4*10000-cat3*1000-cat2*100)>=30and(result1-cat4*10000-cat3*1000-cat2*100)<40)thencat1<=3;
elsif((result1-cat4*10000-cat3*1000-cat2*100)>=20and(result1-cat4*10000-cat3*1000-cat2*100)<30)thencat1<=2;
elsif((result1-cat4*10000-cat3*1000-cat2*100)>=10and(result1-cat4*10000-cat3*1000-cat2*100)<20)thencat1<=1;
elsif((result1-cat4*10000-cat3*1000-cat2*100)<10)thencat1<=0;
endif;
cat0<=result1-cat4*10000-cat3*1000-cat2*100-cat1*10;
if(result>=0)then
CASEtime1IS
WHENt1=>
cat<="101111";
CASEcat4IS
WHEN0=>digital<="1111110";
WHEN1=>digital<="0110000";
WHEN2=>digital<="1101101";
WHEN3=>digital<="1111001";
WHEN4=>digital<="0110011";
WHEN5=>digital<="1011011";
WHEN6=>digital<="1011111";
WHEN7=>digital<="1110000";
WHEN8=>digital<="1111111";
WHEN9=>digital<="1111011";
ENDCASE;
time1<=t2;
WHENt2=>
cat<="110111";
CASEcat3IS
WHEN0=>digital<="1111110";
WHEN1=>digital<="0110000";
WHEN2=>digital<="1101101";
WHEN3=>digital<="1111001";
WHEN4=>digital<="0110011";
WHEN5=>digital<="1011011";
WHEN6=>digital<="1011111";
WHEN7=>digital<="1110000";
WHEN8=>digital<="1111111";
WHEN9=>digital<="1111011";
endcase;
time1<=t3;
WHENt3=>
cat<="111011";
CASEcat2IS
WHEN0=>digital<="1111110";
WHEN1=>digital<="0110000";
WHEN2=>digital<="1101101";
WHEN3=>digital<="1111001";
WHEN4=>digital<="0110011";
WHEN5=>digital<="1011011";
WHEN6=>digital<="1011111";
WHEN7=>digital<="1110000";
WHEN8=>digital<="1111111";
WHEN9=>digital<="1111011";
ENDCASE;
time1<=t4;
WHENt4=>
cat<="111101";
CASEcat1IS
WHEN0=>digital<="1111110";
WHEN1=>digital<="0110000";
WHEN2=>digital<="1101101";
WHEN3=>digital<="1111001";
WHEN4=>digital<="0110011";
WHEN5=>digital<="1011011";
WHEN6=>digital<="1011111";
WHEN7=>digital<="1110000";
WHEN8=>digital<="1111111";
WHEN9=>digital<="1111011";
ENDCASE;
time1<=t5;
WHENt5=>
cat<="111110";
CASEcat0IS
WHEN0=>digital<="1111110";
WHEN1=>digita
- 配套讲稿:
如PPT文件的首页显示word图标,表示该PPT已包含配套word讲稿。双击word图标可打开word文档。
- 特殊限制:
部分文档作品中含有的国旗、国徽等图片,仅作为作品整体效果示例展示,禁止商用。设计者仅对作品中独创性部分享有著作权。
- 关 键 词:
- 北邮数电实验报告 副本 北邮数电 实验 报告