




版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
1、 目 录一、 引言 4二、 实验题目及要求5三、 硬件电路 52.1、键盘输入模块52.2、可编程并行通信接口芯片8255a 62.3、可编程定时器/计数器9四、源程序 10六、课程设计体会 25七、参考文献 26引 言本学期我们学习了微型计算机技术及应用这门应用性很强的课程,通过平时的上机实验,使我们初步了解了8086系统的硬件结构以及部分芯片结构,为了进一步巩固和检测所学知识,我选择基于8086cpu的模拟计算器设计。要完成设计首先需要构建简单的微型计算机应用系统,其次是确定组成各部件的芯片,然后画原理图,根据相应的原理以及实现过程,编写出相应的汇编代码。再根据原理图连接硬件电路,电路连接
2、完成后进行调试。设计过程中我们用到了8088cpu、可编程计时器8253、可编程并行输入/输出芯片8255a、74ls138、矩阵式键盘、六位七段led数码管。我们的模拟计算器能实现2位十进制数以内的及减法运算。模拟计算器设计一、 概述设计题目及要求: 1.通过小键盘做加减运算。七段数码管显示器作输入数据和结果数据的显示。 2.数字用小键盘09,r,p,m,g作功能键 r开始运算(包括撤销运算),显示0' p+ m- g= e退出返回dos 3运算顺序: a.输入一原始数据显示器跟随显示 b.按+或-显示器内容不变 c.再输入一数据,显示器跟随显示。 d.按=显示器显示结果数据,当超出
3、能显示的最大值,显示f(溢出) e.按r重新开始运算 f.按e,结束退出设计思路:首先利用程序不断扫描键盘是不是有输入,如果没有就一直扫描,如果有就停止扫描,完成输入,利用汇编的程序核对输入键的数值,通过调用子程序实现2位十进制数以内的及减法运算。运算完成后将运算的结果储存并显示到led显示器上。二、 硬件电路设计硬件电路 键盘输入及led数码管通过8255a接口与系统总线连接,键盘的16个按键组成8*2矩阵,其中8根矩阵线作为8255a的输出线与pb7pb0连接,2根矩阵线作为8255a的输入线与pc7、pc6连接。键盘采用逐次扫描原理,16个按键中09座位数字健,+、-、=作为加、减和等号
4、功能键,c为清零键。1、 键盘输入模块键盘是常用信息输入元件,其实键盘也是由一个个按钮组成,如果是独立按钮的话必须要需要一个i/o口对它进行检测,而键盘往往这需要键盘按钮数一半的i/o口数对它进行检测,也许对一个比较简单的系统i/o口数一般不是问题,但对于一个大型、复杂的系统来说i/o资源就显得非常珍贵了,尽量减少i/o使用是非常利于降低成本,另外一方面键盘比用独立按键要美观。我们设计时使用的是8*2行列式键盘,如图2-1所示。图中有8行2列,8根行线与pa口相连,2根列线与pc口的pc6、pc7相连。pa、pb口要么全部输入或输出。pc口可以进行输入和输出。按键设置在行、类交点处(数字或字符
5、为其键号),行、列线分别连接到按键开关的两端。当列线通过上拉电阻接+5v时,就被钳位在高电平状态。键盘中有无按键按下是由行线送入全扫描字、列线读入行线状态来判断。这就是:给航线所有i/o线均置成低电平,然后读入列线电平状态。如国有按键盘下,总会有一根列线电平被拉至低电平,从而使列线输入不全为1。 图2-1 键盘电路 图2-2数码管电路2、 可编程并行通信接口芯片8255a(1)并行输入/输出端口a,b,c 8255a内部包括三个8位的输入输出端口,分别是端口a、端口b、端口c,相应信号线是pa7pa0、pb7pb0、pc7pc0。端口都是8位,都可以作为输入或输出。通常将端口a和端口b定义为输
6、入/输出的数据端口,而端口c则既可以作数据端口,又可以作为端口a和端口b的状态和控制信息的传送端口。(2)a组和b组控制部件端口a和端口c的高4位(pc7pc4)构成a组;由a组控制部件实现控制功能。 端口b和端口c的低4位(pc3pc0)构成b组;由b组控制部件实现控制功能。 a组和b组利用各自的控制单元来接收读写控制部件的命令和cpu通过数据总线(d0d7)送来的控制字,并根据他们来定义各个端口的操作方式。(3)数据总线缓冲存储器 三态双向8位缓冲器,是8255a与8086cpu之间的数据接口。与i/o操作有关的数据、控制字和状态信息都是通过该缓冲器进行传送。(4) 读/写控制部件 825
7、5a完成读/写控制功能的部件。能接收cpu的控制命令,并根据控制命令向各个功能部件发出操作指令。 图2-3.8255a芯片图cs 片选信号:由cpu输入,有效时表示该8255a被选中。 rd, wr 读、写控制信号:由cpu输入。rd有效表示cpu读8255a,wr有效表示cpu写8255a。reset 复位信号:由cpu输入。reset信号有效,清除8255a中所有控制字寄存器内容,并将各个端口置成输入方式。图2-4 .8255a内部结构定义工作方式控制字:工作方式0:8255a中各端口的基本输入/输出方式。图2-5 .8255a工作方式控制3、 可编程计数器/定时器 8253具有3个独立的
8、计数通道,采用减1计数方式。在门控信号有效时,每输入1个计数脉冲,通道作1次计数操作。当计数脉冲是已知周期的时钟信号时,计数就成为定时。 (1)、8253内部结构 8253芯片有24条引脚,封装在双列直插式陶瓷管壳内。 1.数据总线缓冲器 数据总线缓冲器与系统总线连接,8位双 向,与cpu交换信息的通道。这是8253与cpu之间的数据接口,它由8位双向三态缓冲寄存器构成,是cpu与8253之间交换信息的必经之路。 2.读写控制 8253111098765432d71d6d5d4d3d2d1d0clk0out0get0gnd1214151617181920212223240ut1clk1gate
9、1out2gate2a1wra0csckl2rd+5v13读写控制分别连接系统的ior和iow, 由cpu控制着访问8253的内部通道。接收cpu送入的读写控制信号, 并完成对芯片内部各功能部件的控制功能, 因此, 它实际上是8253芯片内部的控制器。a1a0:端口选择信号,由cpu输入。8253内部有3个独立的通道和一个控制字寄存器, 它们构成8253芯片的4个端口,cpu可对3个通道进行读写操作3对控制字寄存器进行写操作。 这4个端口地址由最低2位地址码a1、a0来选择。一、 源程序;386以上微机适用;纯dos下才能使用;tasm4.1或以上编译;*;* led *;*; io_plx_
10、device_idequ 05406h;tpc卡设备id io_plx_vendor_idequ 010b5h;tpc卡厂商id io_plx_sub_idequ 0905410b5h;tpc卡子设备及厂商id tim_ctlequ 203h-200h;8253端口地址 timer0equ 200h-200h timer1equ 201h-200h mode03equ 36h;8253端口数据 mode12equ 74h inta00equ 20h inta01equ 21h portsegequ 211h-200h;数码管端口地址 portbitequ 210h-200h pa55 equ
11、218h-200h;8255端口 pb55 equ 219h-200h p55ctl equ 21bh-200hdata segment csregdw? ipregdw?;旧中断向量保存空间 io_9054base_addressdb 4 dup(0);tpc卡pci接口芯片i/o基地址暂存空间 io_base_addressdb 4 dup(0);tpc卡i/o基地址暂存空间 interrupt_linedb 2 dup(0);tpc卡中断号暂存空间 pcicardnotfinddb 0dh,0ah,'tpc pci card not find or address/interru
12、pt error !',0dh,0ah,'$' io9054baseaddressdb 0dh,0ah,'tpc pci card 9054 chip i/o base address : ','$' iobaseaddressdb 0dh,0ah,'tpc pci card i/o base address : ','$' intnumberdb 0dh,0ah,'tpc pci card interrupt line : ','$' enter_returndb 0dh,
13、0ah,'$' mess db '8253a timer0 in mode3! count=0200h',0ah,0dh db '8253a timer1 in mode2! count=0ah',0ah,0dh,'$' irq_vectdb 08h,09h,0ah,0bh,0ch,0dh,0eh,0fh,70h,71h,72h,73h,74h,75h,76h,77h;新的中断向量,中断0-7的向量为:08h-0fh,中断8-15的向量为:70h-77h irq_mask_0_7_tabledb 011111110b,011111
14、101b,011111011b,011110111bdb 011101111b,011011111b,010111111b,001111111bdb 011111011b,011111011b,011111011b,011111011bdb 011111011b,011111011b,011111011b,011111011b;新的中断掩码,中断0-7时从低至高相应位为零,中断8-15时第2位为零 irq_mask_8_15_tabledb 0ffh,0ffh,0ffh,0ffh,0ffh,0ffh,0ffh,0ffhdb 011111110b,011111101b,011111011b,01
15、1110111bdb 011101111b,011011111b,010111111b,001111111b;新的中断掩码,中断0-7时全一,中断8-15时从低至高相应位为零 intmask db ? led db 3fh,06,5bh,4fh,66h,6dh,7dh,07,7fh,6fh,40h db 0ah,0dh,'$' table1dw 0101h,0102h,0104h,0108h,0110h,0120h,0140h,0180hdw 0201h,0202h,0204h,0208h,0210h,0220h,0240h,0280hdw 0401h,0402h,0404h,
16、0408h,0410h,0420h,0440h,0480h char db 'cdefba9845673210 rpmg' mes db 'play any key in the small keyboard! ',0ah,0dh db 'it will be on the screen! end with r or any key',0ah,0dh,'$'extra data num1 db 6 dup (?) num2 db 6 dup (?) result db 6 dup (?) count db 0 operator d
17、b 0 lednum db 6 dup (?)data endsstacks segment db 100 dup (?)sta dw 512 dup (?)top equ length stastacks endscode segment assume cs:code,ds:data,ss:stacks,es:datastart:;enable local interrupt input.386 cli mov ax,data mov ds,ax mov es,ax mov ax,stacks mov ss,axcallfindtpc;查找tpc卡资源并显示mov dx,word ptr i
18、o_base_address;初始化8253add dx,tim_ctlmov al,mode03out dx,almov dx,word ptr io_base_addressadd dx,timer0mov al,00hout dx,almov al,02hout dx,almov dx,word ptr io_base_addressadd dx,tim_ctlmov al,mode12out dx,almov dx,word ptr io_base_addressadd dx,timer1mov al,0ahout dx,almov al,00out dx,almov dx,offse
19、t messmov ah,09int 21hmov dx,offset mes;显示提示mov ah,09int 21hmov dx,word ptr io_9054base_addressadd dx,68h ;设置 tpc 卡中9054芯片io口,使能中断 in ax,dx or ax,0900h out dx,ax mov bx,word ptr interrupt_line;保存原中断向量mov al,byte ptr irq_vect+bxmov ah,35h int 21hmov ax,esmov csreg,axmov ipreg,bx mov bx,word ptr inter
20、rupt_line;设置新中断向量 mov al,byte ptr irq_vect+bx mov cx,cs mov ds,cxmov dx,offset int_procmov ah,25h int 21hmov ax,datamov ds,axmov es,ax in al, 21h ;设置中断掩码 mov bx,word ptr interrupt_linemov ah,byte ptr irq_mask_0_7_table+bxandal,ah out 21h, al in al, 0a1h mov bx,word ptr interrupt_linemov ah,byte ptr
21、irq_mask_8_15_table+bxandal,ah out 0a1h, alsti ;开中断 reset:;initialization lea bx,num1 call clearnum lea bx,num2 call clearnum mov byte ptr count,0 lea bx,num1 call ledshowfirstread: lea bx,num1 call readnum cmp byte ptr operator,4 jz reset cmp byte ptr operator,5 jz funexitloopread: mov dl,operator
22、lea bx,num2 call readnum cmp byte ptr operator,4 jz reset cmp byte ptr operator,5 jz funexit cmp dl,1 jz funadd cmp dl,2 jz funminusmidjmp2: jmp firstreadmidjmp3: jmp reset;several choice for the prior operatorfunadd: call addnum lea bx,num1 jmp ope2funminus: call minusnum lea bx,num1ope2: call leds
23、how lea bx,num2 call clearnum lea bx,num1 call clearnum jmp firstread funequal: jmp resetfunclear: jmp reset funexit: jmp exiterrorout:;output the error message mov word ptr num1,0a0ah mov word ptr num1+2,0a0ah mov word ptr num1+4,0a0ah lea bx,num1 call ledshowerrorget:;reset the error status;only r
24、 and e can pass call key cmp dl,'e' jz funexit cmp dl,'r' jz midjmp3 jmp errorgetjudge: cmp byte ptr operator,3 jz midjmp2exit: cli mov bx,word ptr interrupt_line;恢复中断掩码mov ah,byte ptr irq_mask_0_7_table+bxnot ahinal, 21horal, ahout21h, al mov bx,word ptr interrupt_linemov ah,byte pt
25、r irq_mask_8_15_table+bxnot ahinal, 0a1horal, ahout0a1h, al mov bx,word ptr interrupt_line;恢复原中断向量mov al,byte ptr irq_vect+bx mov dx,ipregmov cx,csregmov ds,cxmov ah,25h int 21hmov ax,data;设置 tpc 卡中9054芯片io口,关闭中断 mov ds,axmov dx,word ptr io_9054base_addressadd dx,68hin ax,dx and ax,0f7ffhout dx,axmo
26、v ax,4c00hint 21h;退出readnum proc;if you want to use this procedure;you must provide the number address to bx push ax push cx push dxreadin:;enter the first number push bx call key ;get a char in (dl) and display it pop bx mov al,dl;operator symbol;plus mov byte ptr operator,1 cmp al,'p' jz e
27、xitread ;minus mov byte ptr operator,2 cmp al,'m' jz exitread ;equal mov byte ptr operator,3 cmp al,'g' jz exitread;clear mov byte ptr operator,4 cmp al,'r' jz exitread;exit mov byte ptr operator,5 cmp al,'e' jz exitread;illegal symbol cmp al,'0' jb readin cmp
28、 al,'9' ja readin;number cmp byte ptr count,6 jz readinleftmove:;mov the number mov cx,5 mov si,0movedata: mov dl,bx+si+1 mov bx+si,dl inc si loop movedata ;insert the number and al,0fh mov bx+5,al call ledshow inc count jmp readinexitread: mov count,0 pop dx pop cx pop ax retreadnum endp mi
29、djmp: jmp erroroutaddnum proc;add num1 and num2 mov cx,6 lea bx,num1 dec bx and cx,cxaddloop: mov si,cx mov al,bx+si adc al,bx+si+6 aaa mov bxsi,al loop addloop jc midjmp retaddnum endpminusnum proc;minus num1 and num2 mov cx,6 lea bx,num1 dec bx and cx,cxminusloop: mov si,cx mov al,bx+si sbb al,bx+
30、si+6 aas mov bxsi,al loop minusloop jc midjmp retminusnum endpledshow proc;simulate led show;provide the number address to bx ;clear led segment push bx lea bx,lednum add bx,2 call clearnum pop bx ;move the data to led segment lea di,lednum mov cx,6 mov si,0showloop: mov al,bx+si push di add di,si m
31、ov di,al pop di inc si loop showloop retledshow endpclearnum proc;clear the number;provide number address to bx mov cx,6 dec bxclearzero: mov si,cx mov byte ptr bx+si,0 loop clearzero retclearnum endpkey proc nearkst:mov al,82hmov dx,word ptr io_base_addressadd dx,p55ctlout dx,al ;set command word o
32、f 8255a ;porta for output,portb for inputwait1:next:mov al,00mov dx,word ptr io_base_addressadd dx,pa55out dx,al ;porta output 00mov dx,word ptr io_base_addressadd dx,pb55in al,dx ;get col datacmp al,0ffhjz wait1 ;no key is closed ,waitpush ax ;save the col datapush ax call delaymov dx,word ptr io_b
33、ase_addressadd dx,p55ctlmov al,90h ;set command word of 8255aout dx,al ;porta for input,portb for outputmov dx,word ptr io_base_addressadd dx,pb55 pop axout dx,al ;output col data from portbmov dx,word ptr io_base_addressadd dx,pa55in al,dx ;(al) is row data pop bxmov ah,bl ;(ah) is col datanot axmo
34、v si,offset table1mov di,offset charmov cx,24tt:cmp ax,si ;cmp (col,row) with every wordjz nn ;in the tabledec cxjz kstadd si,2inc dijmp ttnn:mov dl,dimov ah,02int 21hpush dxmov al,82hmov dx,word ptr io_base_addressadd dx,p55ctlout dx,al ;set command word of 8255a ;porta for output,portb for inputwa
35、it2:mov al,00mov dx,word ptr io_base_addressadd dx,pa55out dx,al ;porta output 00mov dx,word ptr io_base_addressadd dx,pb55in al,dx ;get col datacmp al,0ffhjnz wait2 ;wait until the key is uppop dxretkey endpdelay proc near push ax ;delay 50ms-100ms push bx push cx push dx mov ah,0 int 1ah mov bx,dx
36、delay1:mov ah,0int 1ahcmp bx,dxjz delay1mov bx,dxdelay2:mov ah,0int 1ahcmp bx,dxjz delay2pop dxpop cxpop bxpop ax retdelay endp int_proc proc far cli push axpush cx push dxpush di push dsmov ax,datamov ds,axmov di,offset lednummov cl,01dis1: mov al,dimov bx,offset ledxlat mov dx,word ptr io_base_add
37、ress add dx,portseg out dx,al mov al,cl mov dx,word ptr io_base_address add dx,portbitout dx,alpush cx mov cx,8000h ;显示时间延迟timedelay: loop timedelaypop cxcmp cl,20h jz quitinc dishl cl,1 mov al,00out dx,aljmp dis1quit: mov dx,word ptr io_base_address add dx,portbit mov al,00 out dx,al mov al,20h ;se
38、nd eoi out 0a0h,al out 20h,al mov cx,0ffffhloopx: nop loop loopx ;延时 pop dspop di pop dxpop cx pop ax sti iretint_proc endpfindtpc proc near;查找tpc卡资源并显示pushadpushfdmovax,0b101hint1ahjcfindtpc_notfind;检查pci bios是否存在movax,0b102hmovcx,io_plx_device_idmovdx,io_plx_vendor_idmovsi,0int1ahjcfindtpc_notfind
39、;检查tpc卡是否安装,设备号、厂商号movax,0b10ahmovdi,02chint1ahjcfindtpc_notfindcmpecx,io_plx_sub_idjnzfindtpc_notfind;检查tpc卡是否安装,子设备号、厂商号movax,0b10ahmovdi,14hint1ahjcfindtpc_notfind;读tpc卡9054芯片i/o基址信息movdword ptr io_9054base_address,ecxandecx,1jzfindtpc_notfind;检查是否为i/o基址信息 movecx,dword ptr io_9054base_addressande
40、cx,0fffffffeh movdword ptr io_9054base_address,ecx ;去除i/o指示位并保存movax,0b10ahmovdi,18hint1ahjcfindtpc_notfind;读tpc卡i/o基址信息movdword ptr io_base_address,ecxandecx,1jzfindtpc_notfind;检查是否为i/o基址信息movecx,dword ptr io_base_addressandecx,0fffffffehmovdword ptr io_base_address,ecx;去除i/o指示位并保存movax,0b10ahmovdi
41、,3chint1ahjcfindtpc_notfind;读tpc卡中断信息andcx,0ffhmovword ptr interrupt_line,cx;去除interrupt其它指示位并保存 movdx,offset io9054baseaddress;显示i/o提示信息movah,09hint21h movax,word ptr io_9054base_addresscalldispword;显示i/o基地址movdx,offset iobaseaddress;显示i/o提示信息movah,09hint21hmovax,word ptr io_base_addresscalldispword;显示i/o基地址movdx,offset intnumber;显示interrupt提示信息movah,09
温馨提示
- 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
- 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
- 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
- 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
- 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
- 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
- 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- 体检录用合同范本
- 小班常规建立课题申报书
- 汉字课题申报书
- 和单位食堂合同范本
- 单方出资合作合同范例
- 合同范本中自动签字
- 叉车装卸出租合同范例
- 劳务分包合同范本全国
- 优化住房公积金政策 助力民生改善
- 合同范本模板采购方案
- 混凝土模板支撑工程专项施工方案(140页)
- 如何发挥好办公室协调、督导、服务职能
- 部队安全教育教案大全
- 方管、矩形管规格与理论重量参考表82835
- 肿瘤标志物检验(课堂PPT)
- HY∕T 0289-2020 海水淡化浓盐水排放要求
- 班组长管理能力提升培训(PPT96张)课件
- 法兰蝶阀螺栓配用表
- 垃圾中转站施工方案及施工方法
- 内蒙古自治区小额贷款公司试点管理实施细则
- 液化石油气站安全检查表
评论
0/150
提交评论