读取CMOS时钟并显示
读取年月日及当前时间
ESCAPE EQU 1BH
CMOS_PORT EQU 70H
CMOS_REGA EQU 0AH
UPDATE_FLAG EQU 80H
CMOS_SEC EQU 00H
CMOS_MIN EQU 02H
CMOS_HOUR EQU 04H
CMOS_DAY EQU 07H
CMOS_MONTH EQU 08H
CMOS_YEAR EQU 09H
DATA SEGMENT
DATETIME DB 'YY-MM-DD HH:MI:SS'
DT_LEN = $ - OFFSET DATETIME
DATA ENDS
STACK SEGMENT
DB 16 DUP(?)
STACK ENDS
CODE SEGMENT
ASSUME CS:CODE,DS:DATA,SS:STACK
START:
MOV AX,DATA
MOV DS,AX
MOV AX,STACK
MOV SS,AX
ADD SP,-16
@@:
MOV SI,OFFSET DATETIME
MOV AL,CMOS_REGA
OUT CMOS_PORT,AL
JMP $+2
IN AL,CMOS_PORT+1
TEST AL,UPDATE_FLAG
JNZ @B
;GET YEAR
MOV AL,CMOS_YEAR
OUT CMOS_PORT,AL
JMP $+2
IN AL,CMOS_PORT+1
MOV AH,AL
MOV CL,4
SHR AH,CL
AND AL,00001111B
ADD AH,30H
ADD AL,30H
MOV [SI],AH
MOV [SI+1],AL
ADD SI,3
;GET MONTH
MOV AL,CMOS_MONTH
OUT CMOS_PORT,AL
JMP $+2
IN AL,CMOS_PORT+1
MOV AH,AL
MOV CL,4
SHR AH,CL
AND AL,00001111B
ADD AH,30H
ADD AL,30H
MOV [SI],AH
MOV [SI+1],AL
ADD SI,3
;GET DAY
MOV AL,CMOS_DAY
OUT CMOS_PORT,AL
JMP $+2
IN AL,CMOS_PORT+1
MOV AH,AL
MOV CL,4
SHR AH,CL
AND AL,00001111B
ADD AH,30H
ADD AL,30H
MOV [SI],AH
MOV [SI+1],AL
ADD SI,3
;GET HOUR
MOV AL,CMOS_HOUR
OUT CMOS_PORT,AL
JMP $+2
IN AL,CMOS_PORT+1
MOV AH,AL
MOV CL,4
SHR AH,CL
AND AL,00001111B
ADD AH,30H
ADD AL,30H
MOV [SI],AH
MOV [SI+1],AL
ADD SI,3
;GET MINUTE
MOV AL,CMOS_MIN
OUT CMOS_PORT,AL
JMP $+2
IN AL,CMOS_PORT+1
MOV AH,AL
MOV CL,4
SHR AH,CL
AND AL,00001111B
ADD AH,30H
ADD AL,30H
MOV [SI],AH
MOV [SI+1],AL
ADD SI,3
;GET SECOND
MOV AL,CMOS_SEC
OUT CMOS_PORT,AL
JMP $+2
IN AL,CMOS_PORT+1
MOV AH,AL
MOV CL,4
SHR AH,CL
AND AL,00001111B
ADD AH,30H
ADD AL,30H
MOV [SI],AH
MOV [SI+1],AL
ADD SI,3
;
MOV SI,OFFSET DATETIME
CALL DISPLAY
;
MOV AH,1
INT 16H
CMP AL,ESCAPE
JZ _EXIT
CALL CLEANKBBUF
JMP @B
_EXIT:
MOV AH,4CH
INT 21H
CLEANKBBUF PROC
_AGAIN:
MOV AH,1
INT 16H
JZ _OVER
MOV AH,0
INT 16H
JMP _AGAIN
_OVER:
RET
CLEANKBBUF ENDP
DISPLAY PROC
MOV AX,0B800H
MOV ES,AX
MOV AH,0F4H;087H ;此处设置显示的属性即颜色IRGB
MOV DI,(80*12+28)*2;(80列*25行)12表示显示的行(中间)/28表示显示起始列
MOV CX,DT_LEN
S:
MOV AL,[SI]
MOV ES:[DI],AX ;AX中AH保存颜色,AL保存输出值/此处可以用AX或AL
INC SI
ADD DI,2
LOOP S
RET
DISPLAY ENDP
CODE ENDS
END START
CMOS内容对照
地址 内容 地址 内容 地址 内容 地址 内容
00h Time - Seconds 20h Reserved 40h Extended CMOS 60h User Password
01h Alarm - Seconds 21h Reserved 41h Extended CMOS 61h User Password
02h Time - Minutes 22h Reserved 42h Extended CMOS 62h Extended CMOS
03h Alarm - Minutes 23h Reserved 43h Extended CMOS 63h Extended CMOS
04h Time - Hours 24h Reserved 44h Extended CMOS 64h Extended CMOS
05h Alarm - Hours 25h Reserved 45h Extended CMOS 65h Extended CMOS
06h Date - Day of the week 26h Reserved 46h Extended CMOS 66h Extended CMOS
07h Date - Day 27h Reserved 47h Extended CMOS 67h Extended CMOS
08h Date - Month 28h Reserved 48h Extended CMOS 68h Extended CMOS
09h Date - Year 29h Reserved 49h Extended CMOS 69h Extended CMOS
0Ah Status Register A 2Ah Reserved 4Ah Extended CMOS 6Ah Extended CMOS