Excerpt from

The Intel Embedded Controllers: 80186, 80188, and 80386EX

© 1998 by Barry B. Brey

The Real Time Clock

The software for the real-time clock contains an interrupt service procedure that is called once per millisecond and a procedure that updates the time located in five memory locations. Example 12-17 lists both procedures. Note that in this example the time is stored at absolute memory locations 00400H - 00404H.

EXAMPLE 12-17
;Interrupt service procedure for the real-time clock
;
TIME	EQU	400H
CLOCK	PROC	FAR USES AX SI DS
	MOV	AX,0
	MOV	DS,AX		;address time segment = 0000H
	MOV	SI,OFFSET TIME
	
	MOV	AH,0		;modulus = 100
	CALL	UPDATE		;adjust 1/1000 second counter
	JNZ	DONE		;if NO rollover to 00
	MOV	AH,10H		;modulus = 10
	CALL	UPDATE		;adjust 1/10 second counter
	JNZ	DONE
	MOV	AH,60H		;modulus = 60
	CALL	UPDATE		;adjust seconds counter
	JNZ	DONE
	CALL	UPDATE		;adjust minutes counter
	JNZ	DONE
	MOV	AH,24H		;modulus = 24
	CALL	UPDATE		;adjust hours counter
DONE:
	MOV	DX,0FF02H	;address EOI register
	MOV	AX,8000H	;EOI instruction
	OUT	DX,AX
	IRET
CLOCK	ENDP

UPDATE	PROC	NEAR
	LODSB			;get a counter
	ADD	AL,1		;increment it
	DAA			;make it BCD
	CMP	AH,AL		;test for modulus
	JNZ	UPDATE1		;if no rollover
	MOV	AL,0
UPDATE1:
	MOV	[SI-1],AL	;save new count
	RET
UPDATE	ENDP	

return to publication list