微机原理课程设计 电子钟 汇编语言.docx

上传人:b****5 文档编号:6149080 上传时间:2023-01-04 格式:DOCX 页数:12 大小:18.66KB
下载 相关 举报
微机原理课程设计 电子钟 汇编语言.docx_第1页
第1页 / 共12页
微机原理课程设计 电子钟 汇编语言.docx_第2页
第2页 / 共12页
微机原理课程设计 电子钟 汇编语言.docx_第3页
第3页 / 共12页
微机原理课程设计 电子钟 汇编语言.docx_第4页
第4页 / 共12页
微机原理课程设计 电子钟 汇编语言.docx_第5页
第5页 / 共12页
点击查看更多>>
下载资源
资源描述

微机原理课程设计 电子钟 汇编语言.docx

《微机原理课程设计 电子钟 汇编语言.docx》由会员分享,可在线阅读,更多相关《微机原理课程设计 电子钟 汇编语言.docx(12页珍藏版)》请在冰豆网上搜索。

微机原理课程设计 电子钟 汇编语言.docx

微机原理课程设计电子钟汇编语言

;clock.asm

;386以上微机适用

;纯dos下才能使用

;tasm4.1或以上编译

;*********************;

;*clockin8255LED*;

;*********************;

io_plx_device_id

io_plx_vendor_id

IO_PLX_SUB_ID

--------------------------8253,8255,LED的端口地址---------------------------------------pa55equ218h-200H;8255端口地址

pb55equ219h-200H

p55ctlequ21bh-200H

PORTSEGEQU211H-200H

PORTBITEQU210H-200H

TIM_CTLEQU203H-200H

TIMER0EQU200H-200H

TIMER1EQU201H-200H

MODE03EQU36H

MODE12EQU74H

-------------------------------------------------------------------------------------------

datasegment

csreg

ipregdw?

dw?

;旧中断向量保存空间

db4DUP(0);TPC卡PCI接口芯片I/O基地址暂存空间

db4DUP(0)

db2DUP(0);TPC卡I/O基地址暂存空间;TPC卡中断号暂存空间;8253端口地址;led端口地址equ05406hequ010b5h;TPC卡设备ID;TPC卡厂商ID;TPC卡子设备及厂商IDEQU0905410B5Hio_9054base_addressio_base_addressinterrupt_line

pcicardnotfind

iobaseaddress

intnumber

MESSenter_returndb0dh,0ah,'TPCpcicardnotfindoraddress/interrupterror!

!

!

',0dh,0ah,'$'db0dh,0ah,'TPCpcicardI/OBaseAddress:

','$'db0dh,0ah,'TPCpcicardInterruptLine:

','$'db0dh,0ah,'$'io9054baseaddressdb0dh,0ah,'TPCpcicard9054ChipI/OBaseAddress:

','$'DB'8253ATIMER0INMODE3!

COUNT=0200H',0AH,0DH

db08h,09h,0ah,0bh,0ch,0dh,0eh,0fh,70h,71h,72h,73h,74h,75h,76h,77h;新的中断向量,中断0-7的向量为:

08h-0fh,中断8-15的向量为:

70h-77hdb011101111b,011011111b,010111111b,001111111b

db011111011b,011111011b,011111011b,011111011b

db011111011b,011111011b,011111011b,011111011bDB'8253ATIMER1INMODE2!

COUNT=0aHinfactitisbettertobe0003h',0AH,0DH,'$'irq_vectirq_mask_0_7_tabledb011111110b,011111101b,011111011b,011110111b

;新的中断掩码,中断0-7时从低至高相应位为零,中断8-15时第2位为零db0ffh,0ffh,0ffh,0ffh,0ffh,0ffh,0ffh,0ffhdb011111110b,011111101b,011111011b,011110111bdb011101111b,011011111b,010111111b,001111111b;新的中断掩码,中断0-7时全一,中断8-15时从低至高相应位为零

irq_mask_8_15_table;--------------------------与用户有关的数据寄存区域-------------------------------

COUNTDB50;jishu50times

TIME1DB00H,00H,00H,00H,00H,00H;TIMERDATAWAITNGTOBEPRINTED

CHAR1DB?

;savethecharthatuhaveinputedfromthekeybord

INTMASKDB?

CONST1DW?

LEDDB3FH,06H,5BH,4FH,66H,6DH,7DH,07H,7FH,6FH,40H,79H,00H

TABLE1DW0101H,0201H,0401H,0801H,1001H,2001H,4001H,8001H

DW0102H,0202H,0402H,0802H,1002H,2002H,4002H,8002H

DW0104H,0204H,0404H,0804H,1004H,2004H,4004H,8004H

CHARDB'CDEFBA9845673210RPMG'

MESDB'------------------INSMALLKEYBORD----------------',0AH,0DH

DB'C--DISPLAY00,00,00;G--GOONSHOWTHETIME',0AH,0DHDB'D--STOPTODISPLAY;E--EXITTODOS',0AH,0DH

;DB'P--POSITIONTHETHERIGHTTIME',0AH,0DH,'$'

DB'P--POSITIONTHETHERIGHTTIME',0AH,0DH

DB'------------------JUSTHAVEATRY------------------',0AH,0DH,'$'

dataends

stackssegment

db100dup(?

STADW512DUP(?

TOPEQULENGTHSTA

stacksends

codesegment

assumecs:

code,ds:

data,ss:

stacks,es:

data

start:

;EnableLocalInterruptInput

.386

cli

movax,data

movds,ax

moves,ax

movax,stacks

movss,ax

;---------------------------------主程序开始时的初始化工作-------------------------------

movdx,wordptrio_9054base_addressadddx,68h;;;;设置tpc卡中9054芯片io口,使能中断MOVDX,wordptrio_base_address;初始化8253adddx,TIM_CTLMOVAL,MODE03;计数器0工作在模式三00110110;OUTDX,ALMOVDX,wordptrio_base_addressadddx,TIMER0MOVAL,00hOUTDX,ALOUTDX,ALMOVDX,wordptrio_base_addressadddx,TIM_CTLMOVAL,MODE12OUTDX,ALMOVDX,wordptrio_base_addressadddx,TIMER1OUTDX,ALOUTDX,ALMOVDX,OFFSETMESMOVAH,09INT21Hcallfindtpc;查找TPC卡资源并显示MOVAL,02HMOVAL,03H;本来是000ah但程序中有很多延时。

MOVAL,00hinax,dx

orax,0900h

outdx,ax

movbx,wordptrinterrupt_line

moval,byteptr[irq_vect+bx]movah,35hmovax,esmovcsreg,ax;保存原中断向量int21h

movipreg,bx

;设置新中断向量movbx,wordptrinterrupt_line

moval,byteptr[irq_vect+bx]

movcx,cs

movds,cx

movax,datamovds,axmoves,axmovdx,offsetint_procmovah,25hint21h

inal,21h;设置中断掩码movbx,wordptrinterrupt_line

movah,byteptr[irq_mask_0_7_table+bx]andal,ah

out21h,al

inal,0a1h

movbx,wordptrinterrupt_line

LKEY:

CALLKEY

MOVDL,[CHAR1]

CMPDL,'C'

JNZLGY

CALLCPRO

JMPLKEY

LGY:

CMPDL,'G'

JNZLDY

CALLGPRO

JMPLKEY

LDY:

CMPDL,'D'

JNZLPY

CALLDPRO

JMPLKEY

LPY:

CMPDL,'P'

JNZLEY

CALLPPRO

JMPLKEYsti;开中断movah,byteptr[irq_mask_8_15_table+bx]andal,ahout0a1h,al

LEY:

CMPDL,'E'

JNZLKEY

exit:

cli

movbx,wordptrinterrupt_line

movbx,wordptrinterrupt_line

movax,4c00hint21h;退出movax,data;设置tpc卡中9054芯片io口,关闭中断movds,axmovdx,wordptrio_9054base_addressadddx,68hinax,dxoutdx,axmoval,byteptr[irq_vect+bx]movcx,csregmovds,cxmovah,25hmovdx,ipreg;恢复原中断向量notahinoral,21hal,ah;恢复中断掩码movah,byteptr[irq_mask_0_7_table+bx]out21h,almovah,byteptr[irq_mask_8_15_table+bx]notahinoral,0a1hal,ahmovbx,wordptrinterrupt_lineout0a1h,alint21handax,0f7ffh

;--------------------------------中断服务程序;每秒钟将会进入50次-----------------------int_procprocfar

cli

pushax

PUSHBXPUSHCXPUSHSIPUSHDIpushdx

pushds

movax,data;Interrupttodo

movds,ax

DEC[COUNT]

JNZDDD;;SMALLERTHAN50JUMPTONEXTGENERATIONMOV[COUNT],50;;NEWINTRRUPTISBEGIN

DDD:

moval,20h;SendEOI

out0a0h,al

out20h,al

movcx,0ffffh

loopx:

nop

looploopx;延时MOVDI,OFFSETTIME1CMPBYTEPTR[DI+5],09HJEDDD1;先进性比较如果是9则跳到ddd1产生进位否则加一INCBYTEPTR[DI+5];50TIMESTOMAKEANINCOFsecondhighJMPDDDINCBYTEPTR[DI+4];产生进位:

CMP[DI+4],06HJNZDDDmovbyteptr[DI+4],00HINCBYTEPTR[DI+3];产生进位:

CMP[DI+3],0AHJNZDDDmovbyteptr[DI+3],00HINCBYTEPTR[DI+2];产生进位:

CMP[DI+2],06hJNZDDDmovbyteptr[DI+2],00HINCBYTEPTR[DI+1];产生进位:

CMP[DI+1],04hJNZDDDmovbyteptr[DI+1],00HINCBYTEPTR[DI];产生进位:

CMP[DI],03hJNZDDDmovbyteptr[DI],00HDDD1:

movbyteptr[DI+5],00H

popds

POPDIPOPSIPOPCXPOPBXpopdx

popax

sti

iret

int_procendp

;-----------------------------键盘扫描的程序主程序中被调用------------------------KEYPROCNEAR

PUSHCX

KST:

MOVAL,82H

MOVDX,wordptrio_base_addressadddx,P55CTL

OUTDX,AL

MOVAL,00H

MOVDX,wordptrio_base_addressadddx,PA55MOVDX,wordptrio_base_addressadddx,PB55OUTDX,AL

INAL,DX

ORAL,0F8H

CMPAL,0FFH

JZDELAY

PUSHAX

MOVCX,0a00H

DLY:

MOVAX,wordptrCONST1

DLY1:

DECAX

JNZDLY1

DECCX

JNZDLY

POPAX

MOVCL,08H

MOVAH,0FEH

SCAN1:

MOVDX,wordptrio_base_addressadddx,PA55

MOVAL,AH

OUTDX,AL

MOVDX,wordptrio_base_address

adddx,PB55

INAL,DX

ORAL,0F8H

CMPAL,0FFH

JNZKEYN

ROLAH,1

DECCL

JNZSCAN1

JMPKST

KEYN:

PUSHAX

MOVDX,wordptrio_base_addressadddx,PB55

RELEA:

INAL,DX

ORAL,0F8H

CMPAL,0FFH

JNZRELEA

POPAX

NOTAX

MOVSI,OFFSETTABLE1

MOVDI,OFFSETCHAR

MOVCX,24

TT:

CMPAX,[SI]

JZNN

DECCX

JZKST

ADDSI,02

INCDI

JMPTT

NN:

MOVDL,[DI]

MOV[CHAR1],DL

MOVAH,02H

INT21H

POPCX

JMPYANG

DELAY:

CALLDISPLY

JMPKST

YANG:

RET

KEYENDP

;--------------------------------------------LED数码管显示------------------------------DISPLYPROCNEAR

PUSHCX

MOVBX,OFFSETLED

MOVCX,0006;STANDSFOR6LEDS

MOVSI,OFFSETTIME1

MOVAH,01H

DISPLY1:

CLD;LEDDB3FH,06H,5BH,4FH,66H,6DH,7DH,07H,7FH,6FH,40H,79H,00H

LODSB;AL=[BX+AL]

XLAT;AL=

MOVDX,wordptrio_base_addressadddx,PORTSEG

OUTDX,AL

MOVAL,AH

MOVDX,wordptrio_base_addressadddx,PORTBIT

OUTDX,AL

SHLAH,1;ZUOYI

MOVAL,00;EVERYTIMEWEINISIATITWITH00WHENFINISHED

OUTDX,AL

LOOPDISPLY1

POPCX

RET

DISPLYENDP

;------------------------------------按下各种键盘时相应的操作---------------------------

CPROPROCNEAR

CLI

MOVWORDPTRWORDPTR[TIME1],0000H;PRINTLED00:

00:

00

MOVWORDPTR[TIME1+2],0000H

MOVWORDPTR[TIME1+4],0000H

RET

CPROENDP

;---------------------------------------------------------------

GPROPROCNEAR;STARTTHECLOCK;

STI

RET

GPROENDP

;----------------------------------------------------------------

DPROPROCNEAR;STOPTODISPLAY

CLI

RET

DPROENDP

;---------------------------------------------------------------

PPROPROCNEAR

CLI

PUSHAX

PUSHBX

MOVWORDPTR[TIME1],0C0CH;ledoff

MOVWORDPTR[TIME1+2],0C0CH

MOVWORDPTR[TIME1+4],0C0CH

CALLDISPLY

CALLKEY

MOVDL,[CHAR1]

CMPDL,'2'

JNGNEXT1;SMALLERTHAN9hh<=2

JMPERR1

NEXT1:

SUBDL,30H

;MOV[YEAR1],DL

MOV[TIME1],DL

CALLDISPLY

CALLKEY

MOVDL,[CHAR1]

CMPDL,'3'

JNGNEXT2;notgreaterthanto->exit2SMALLERTHAN9hh<=4

JMPERR1

NEXT2:

SUBDL,30H

;;;;MOV[YEAR1+1],DL

MOV[TIME1+1],DL

CALLDISPLY

CALLKEY

MOVDL,[CHAR1]

CMPDL,'6'

JNGNEXT3;;SMALLERTHAN9mh<=6

JMPERR1

NEXT3:

SUBDL,30H

MOV[TIME1+2],DL

CALLDISPLY

CALLKEY

MOVDL,[CHAR1]

CMPDL,'9'

JNGNEXT4;SMALLERTHAN9ml<=9

JMPERR1

NEXT4:

SUBDL,30H

mov[TIME1+3],DL

CALLDISPLY

CALLKEY

MOVDL,[CHAR1]

CMPDL,'6'

JNGNEXT5;SMALLERTHAN9ml<=9SH<=5

JMPERR1

NEXT5:

SUBDL,30H

MOV[TIME1+4],DL

CALLDISPLY

CALLKEY

MOVDL,[CHAR1]

CMPDL,'9'

JGERR1

SUBDL,30H

MOV[TIME1+5],DL

CALLDISPLY

JMPWW

ERR1:

MOVWORDPTR[TIME1],0A0BHMOVWORDPTR[TIME1+2],0A0AHMOVWORDPTR[TIME1+4],0A0AH

CALLDISPLY

WW:

POPBX

POPAX

RET

PPROENDP

;---------------------------tpccard------------------------------------

findtpcprocnear

MOVAX,0B102HMOVCX,io_plx_device_idMOVDX,io_plx_vendor_idMOVSI,0INT1AHpushadpushfdMOVAX,0B101HINT1AHJCfindtpc_notfind;检查PCIBIOS是否存在;查找TPC卡资源并显示

JCfindtpc_notfind;检查TPC卡是否安装,设备号、厂商号MOVAX,0B10AHMOVDI,02CHINT1AHJCfindtpc_notfind;检查TPC卡是否安装,子设备号、厂商号CMPECX,IO_PLX_SUB_IDJNZfindtpc_notfindMOVAX,0B10AHMOVDI,14HINT1AHJCfindtpc_notfind;读TPC卡9054芯片I/O基址信息movdwordptrio_9054base_address,ecxandecx,1jzfindtpc_notfind;检查是否为i/o基址信息movecx,dwordptrio_9054base_addressandecx,0fffffffehmovdwordptrio_9054base_address,ecx;去除i/o指示位并保存MOVAX,0B10AHMOVDI,18HINT1AHJCfindtpc_notfind;读TPC卡I/O基址信息movdwordptrio_base_address,ecxandecx,1jzfindtpc_notfind;检

展开阅读全文
相关资源
猜你喜欢
相关搜索

当前位置:首页 > 农林牧渔 > 农学

copyright@ 2008-2022 冰豆网网站版权所有

经营许可证编号:鄂ICP备2022015515号-1