微机原理实时时钟课程设计报告书.docx
《微机原理实时时钟课程设计报告书.docx》由会员分享,可在线阅读,更多相关《微机原理实时时钟课程设计报告书.docx(25页珍藏版)》请在冰豆网上搜索。
微机原理实时时钟课程设计报告书
西南科技大学微机原理课程设计
题目电子实时时钟软件设计
1任务
实现如图所示电子日历时钟功能。
2基本要求
1)可通过M键切换显示模式:
日期(年、月、日)、时间(小时、分、秒)、秒表(小时、分、秒、1/100秒)、闹钟(小时、分)。
2)在秒表显示模式.可通过I键切换(启动/暂停)计时.当暂停计时时可通过A键复位。
3)在闹钟显示模式.有两种输入方式
方式一:
直接按格式输入时间
方式二:
可通过A键依次使On/Off标志、小时、分、秒闪烁或变色.这时可通过I键切换On/Off标志或加1调整。
4)可通过esc键结束程序。
3扩展要求
1)在日期显示模式.可通过A键依次使年、月、日闪烁或变色.这时可通过I键加1调整。
2)在时间显示模式.可通过A键依次使小时、分、秒闪烁或变色.这时可通过I键加1调整。
3)调整和秒表操作不影响日期和时间的准确性。
4)自定义的其它扩展功能
说明:
本程序为西科微机原理课程设计题目.下面的代码只实现了基本要求部分.并且秒表还存在部分问题(秒表模式修改了定时器0.结束后对时间略有影响.测试闹钟时可以直接在秒表模式下.按q键跳过秒表模式).代码仅供参考.欢迎对其繁琐处进行修改.调试。
各部分程序流程图:
该过程与代码略有不同.处理on/off位是后来添加的代码.流程图没有加入
DATASEGMENT
UISDB0DH,0AH,10dup(0),50DUP('*'),'$'
UIEDB0DH,0AH,10dup(0),50DUP('*'),'$';界面字符
MSG1DB"THEDATAIS$"
MSG2DB"THETIMEIS$"
MSGINDB"PLEASECHOOSEINPUTMETHODS:
",0DH,0AH
DB21DUP(""),"PRESSAFORA/IMETHOD,ORFORDIRECTMETHOD$"
MSGDIRDB"PLEASEINPUTLIKETHIS:
OO:
00",0DH,0AH
DB21DUP(""),"PRESSENTERTOCONFIRM$"
MSGWARNDB"ERROR!
PLEASEENTERAGAIN$"
MSGAIDB"PRESSaTOCHANGEPOSITION",0DH,0AH
DB21DUP(""),"iTOCHANGEVALUE,ENTERTOCONFIRM$"
MSGSECDB"PRESSiTOSTARTANDSTOP",0DH,0AH
DB21DUP(""),"qTOQUIT,aTOCLEARIFITHASSTOPED$"
NULINEDB25DUP(?
),'$';清空行
KSBUFDB6,0,6DUP(?
)
KEYNUMDB?
MODEDB?
DAYDB?
MONDB?
YEARDW?
SECDB?
MSECDB?
MINDB?
HOURDB?
BEEPHOURDB0,0
BEEPMINDB0,0
SWIOFFDB"FF$"
SWIONDB"N$"
SETSTRDB"00:
00OFF/ON",'$'
WSTRDB"00:
00:
00",'$'
BFLAGDB0
SFLAGDB0
INISEGDW0
INIOFFDW0
DATAENDS
CODESEGMENT
ASSUMECS:
CODE,DS:
DATA
START:
MOVAX,DATA
MOVDS,AX
CALLCLEAR
CALLCREATUI
MOVMODE,0
CALLSOUND
AGAIN:
CALLREFRESH;刷新时间日期
;******BFALG为闹钟与秒表标志位。
下面为处理闹钟
CMPBFLAG,0
JESETMOU
CMPBFLAG,1
JNECRING
CALLCHESTART
JMPSETMOU
CRING:
CALLCHESTOP
JMPSETMOU
JMAGAN:
JMPAGAIN;二级跳转
SETMOU:
MOVDX,0815H
MOVAH,02
MOVBH,0
INT10H;设置光标
;模式判断***********
CMPMODE,0
JEMODE0
CMPMODE,1
JEMODE1
CMPMODE,2
JEMODE2
CMPMODE,3
JEMODE3
MODE0:
CALLTIMESHOW
JMPKEYSCAN
MODE1:
CALLDATESHOW
JMPKEYSCAN
MODE2:
CALLBEEP
MOVMODE,03H
JMPKEYSCAN
MODE3:
CALLSEDWHATCH
MOVMODE,0H
;键盘扫描*********
KEYSCAN:
MOVAH,0BH
INT21H
CMPAL,00
JEAGAIN
MOVAH,08H
INT21H
CMPAL,1BH
JZSTOP
CMPAL,'m'
JNEAGAIN
INCMODE
CMPMODE,4
JNEJMAGAN
MOVMODE,0
JMPJMAGAN
STOP:
MOVAH,4CH
INT21H
;*******时间日期刷新*****
REFRESHPROC
PUSHAX
PUSHCX
PUSHDX
MOVAH,2AH
INT21H
MOVDAY,DL
MOVMON,DH
MOVYEAR,CX
MOVAH,2CH
INT21H
MOVHOUR,CH
MOVMIN,CL
MOVSEC,DH
MOVMSEC,DL
POPDX
POPCX
POPAX
RET
REFRESHENDP
;********年月日显示
DATESHOWPROC
PUSHAX
PUSHCX
PUSHDX
MOVDX,OFFSETMSG1
MOVAH,09
INT21H
MOVAX,YEAR;取年
CALLBTOBCD
MOVDL,'/'
MOVAH,02H
INT21H
MOVAH,0
MOVAl,MON;月
CALLBTOBCD
MOVDL,'/'
MOVAH,02H
INT21H
MOVAH,0
MOVAL,DAY;日
CALLBTOBCD
MOVDX,OFFSETNULINE
MOVAH,09
INT21H
POPDX
POPCX
POPAX
RET
DATESHOWENDP
;*********时间显示
TIMESHOWPROC
PUSHAX
PUSHBX
PUSHCX
PUSHDX
MOVDX,OFFSETMSG2
MOVAH,09
INT21H
MOVAH,0
MOVAL,HOUR;取时
CALLBTOBCD
MOVDL,':
'
MOVAH,02H
INT21H
MOVAH,0
MOVAL,MIN;分
CALLBTOBCD
MOVDL,':
'
MOVAH,02H
INT21H
MOVAH,0
MOVAL,SEC;秒
CALLBTOBCD
CMPSFLAG,0
JETOCLR
MOVDL,':
'
MOVAH,02H
INT21H
MOVAH,0
MOVAL,MSEC;10M秒
CALLBTOBCD
TOCLR:
MOVDX,OFFSETNULINE
MOVAH,09
INT21H
POPDX
POPCX
POPBX
POPAX
RET
TIMESHOWENDP
;将二进制转化为BCD码并显示
BTOBCDPROC
PUSHDX
PUSHBX
PUSHCX
MOVCX,0
MOVBX,10
BTOD:
MOVDX,0
DIVBX
PUSHDX
INCCL
CMPAX,0
JABTOD
SHOW:
POPDX
ADDDL,30h
MOVAH,02h
INT21h
LOOPSHOW
POPCX
POPBX
POPDX
RET
BTOBCDENDP
;*****闹钟设定******
BEEPPROC
MOVDX,0715H
MOVAH,02
MOVBH,0
INT10H
MOVDX,OFFSETMSGIN
MOVAH,09
INT21H
CMPBFLAG,2;设定时还在响.那么关闭
JNESETM
INAL,61H
ANDAL,0FDH
OUT61H,AL
SETM:
MOVDX,0715H
MOVAH,02
MOVBH,0
INT10H
MOVAH,07H
INT21H
CMPAL,'a'
JEINA;选择输入方式.a为切换输入.其他键为键盘直接输入
MOVDX,OFFSETMSGDIR
MOVAH,09
INT21H
MOVDX,0915H
MOVAH,02
MOVBH,0
INT10H
MOVDX,OFFSETKSBUF
MOVAH,10
INT21H;键盘输入字符存入缓存区
MOVBFLAG,1
MOVSI,OFFSETKSBUF+1
MOVCL,BYTEPTR[SI]
MOVBX,10
INCSI
ANDBYTEPTR[SI],0FH
MOVAL,BYTEPTR[SI]
MULBL
INCSI
ANDBYTEPTR[SI],0FH
ADDAL,BYTEPTR[SI]
MOVBEEPHOUR,AL
ADDSI,2
ANDBYTEPTR[SI],0FH
MOVAL,BYTEPTR[SI]
MULBL
INCSI
ANDBYTEPTR[SI],0FH
ADDAL,BYTEPTR[SI]
MOVBEEPMIN,AL
JMPTOEND
INA:
MOVDX,OFFSETMSGAI;A/I切换输入方式
MOVAH,09
INT21H
MOVDX,0915H
MOVAH,02
MOVBH,0
INT10H
MOVDX,OFFSETSETSTR
MOVAH,09
INT21H
MOVDX,0915H
MOVAH,02
MOVBH,0
INT10H
MOVSI,OFFSETBEEPHOUR
;*****a键切换光标位置*********
KASCAN:
MOVAH,0BH
INT21H
CMPAL,00
JEKASCAN
MOVAH,08H
INT21H
MOVKEYNUM,AL
CMPAL,'a'
JNEKISCAN
MOVBH,0
MOVAH,03H
INT10H
INCDL
INCSI
CMPDL,17H
JETOMI
CMPDL,1AH
JETOSW
CMPDL,22H
JETOHO
JMPSETF
TOMI:
INCDL
JMPSETF
TOSW:
MOVDL,21H
JMPSETF
TOHO:
MOVDL,15H
MOVSI,OFFSETBEEPHOUR
SETF:
MOVAH,02H
INT10H
KAJMP:
JMPKASCAN
;*****i键改变光标处字符*****
KISCAN:
CMPKEYNUM,'i'
JNEJKCR0
MOVAH,08H;读光标处字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VCL,SEC
CMPCL,3
JBESCP
INAL,61H
ANDAL,0FDH
OUT61H,AL
ANDBFLAG,0
ESCP:
RET
CHESTOPENDP
SOUNDPROC
MOVAL,10110110B
OUT43H,AL
MOVDX,0012H
MOVAX,34DEH
MOVDI,1000
DIVDI
OUT42H,AL
MOVAL,AH
OUT42H,AL
INAL,61H
ANDAL,0FDH
OUT61H,AL
INAL,61H
ORAL,1
OUT61H,AL
RET
SOUNDENDP
;*********以下为秒表部分************
SEDWHATCHPROC
MOVDX,0715H
MOVAH,02
MOVBH,0
INT10H
MOVDX,OFFSETMSGSEC
MOVAH,09
INT21H
MOVDX,0915H
MOVAH,02
MOVBH,0
INT10H
CLI
MOVAL,1CH
MOVAH,35H
INT21H
MOVINISEG,ES
MOVINIOFF,BX
SHOWINI:
MOVDX,0915H
MOVAH,02
MOVBH,0
INT10H
MOVDX,OFFSETWSTR
MOVAH,09
INT21H
KSCANW:
MOVAH,0BH
INT21H
CMPAL,00
JEKSCANW
MOVAH,08H
INT21H
CMPAL,'q'
JEQTIME
CMPAL,'i'
JETOI
CMPAL,'a'
JNEKSCANW
CMPSFLAG,1
JEKSCANW
JMPSHOWINI
TOI:
MOVSFLAG,1
MOVHOUR,0
MOVMIN,0
MOVSEC,0
MOVMSEC,0
CALLINITIR
WSTART:
MOVDX,0915H
MOVAH,02
MOVBH,0
INT10H
CALLTIMESHOW
WSTOP:
MOVAH,0BH
INT21H
CMPAL,00
JEWSTART
MOVAH,08H
INT21H
CMPAL,'i'
JNEWSTART
MOVSFLAG,0
JMPKSCANW
QTIME:
CLI
PUSHDS
MOVDX,INIOFF
MOVDS,INISEG
MOVAL,1CH
MOVAH,25H
INT21H
STI
POPDS
MOVAL,00110100B
OUT43H,AL
MOVAL,0FFH
OUT40H,AL
OUT40H,AL
MOVDX,0715H
MOVAH,02
MOVBH,0
INT10H
MOVDX,OFFSETNULINE
MOVAH,09
INT21H
MOVDX,0915H
MOVAH,02
MOVBH,0
INT10H
MOVDX,OFFSETNULINE
MOVAH,09
INT21H
RET
SEDWHATCHENDP
INITIRPROC
CLI
;初始化8253计时器0.先送低八位.再送高八位.工作方式3.二进制计数方式
MOVAL,00110110B
OUT43H,AL
MOVAX,11932;计数初值送AX
OUT40H,AL
MOVAL,AH
OUT40H,AL
PUSHDS
MOVDX,OFFSETTIMER
MOVAX,SEGTIMER
MOVDS,AX
MOVAX,251CH
INT21H
POPDS
RET
INITIRENDP
TIMERPROC
PUSHAX
PUSHDS
MOVAX,DATA
MOVDS,AX
INCMSEC
CMPMSEC,100
JNEQUIT
MOVMSEC,0
INCSEC
CMPSEC,60
JNEQUIT
ANDSEC,0H
INCMIN
CMPMIN,60
JNEQUIT
INCHOUR
ANDMIN,0H
QUIT:
POPAX
MOVDS,AX
POPAX
STI
IRET
TIMERENDP
CREATUIPROC
PUSHAX
PUSHBX
PUSHDX
MOVDX,OFFSETUIS
MOVAH,09
INT21H
MOVDX,1000H
MOVAH,02
MOVBH,0
INT10H
MOVDX,OFFSETUIE
MOVAH,09
INT21H
POPDX
POPBX
POPAX
RET
CREATUIENDP
CLEARPROC
MOVAX,0002H
INT10H
RET
CLEARENDP
CODEENDS
ENDSTART