From: yoshimi@etl.go.jp (Takashi Yoshimi)
Subject: Q. on using timer IC
Content-Type: text/plain; charset=ISO-2022-JP
Reply-To: yoshimi@etl.go.jp (Shikaku ex5958)
Organization: Electrotechnical Laboratory, Tsukuba Science City
Mime-Version: 1.0
Distribution: fj
Date: Wed, 26 Aug 1992 04:54:26 GMT

$@5H8+!wEEAm8&$G$9!#(J

$@8=:_!"(JPC-98 $@>e$G%9%H%C%W%&%)%C%A$N%W%m%0%i%`$r:n$m$&$H$7$F$$$^$9!#(J

$@%?%$%^(JIC $@$+$i$N3d$j9~$_$G30ItJQ?t$rA}2C$9$k$h$&$K$7$F$*$$$F!"%-!<F~NO(J
$@$,$"$k$H$=$NCM$rFI$_$K9T$+$;$k%W%m%0%i%`$r=q$-$^$7$?$,!"$&$^$/F0:n$7$^(J
$@$;$s!#%"%;%s%V%i$G$$$/$D$+$N4X?t$r=q$$$F$*$-!"$=$l$r(J C $@$G8F$V$h$&$K$7(J
$@$F$$$^$9!#%?%$%^(JIC$@$r;H$&$N$O!"#1IC0J2<!J$3$N%W%m%0%i%`$G$O(J10ms$@!K$N@:EY(J
$@$r=P$7$?$$$+$i$G$9!#%?%$%^3d$j9~$_$,$+$i$`$N$G!"%G%P%C%,$G$b2r@O$,$7$K(J
$@$/$$!#!#(J

$@0JA0!"JL$N%W%m%0%i%`$G%?%$%^(JIC $@$NJL$N5!G=$r;H$C$F(J40ms $@$N%G%#%l%$$r:n$k(J
$@4X?t$r:n$C$?$3$H$,$"$C$F$=$N$H$-$K$O$&$^$/F0$$$?$N$G$9$,!":#2s$O$J$<$+(J
$@$&$^$/$$$+$:$K:$$C$F$$$^$9!#$J$K$+!"$*$^$8$J$$$,B-$i$J$$$N$+$b!#4m81$J(J
$@$3$H$K!"%O!<%I%G%#%9%/$r%"%/%;%9$7$?>uBV$G5"$C$F$3$J$$$3$H$,$"$j$^$9!#(J
$@2u$7$F$O$$$J$$$h$&$G$9$,!#!#(J

$@$$$/$D$+(J8086 $@$d(J PC-98 $@$N%"%;%s%V%i$K4X$9$kK\$rC5$7$F$_$^$7$?$,!"$^$@NI(J
$@$$J88%$K$?$I$j$D$$$F$$$^$;$s!#(J

$@<!$N$h$&$J>pJs$,$$$?$@$1$k$H$"$j$,$?$$$G$9!#(J

$@#1!'$=$N$h$&$J4X?t$,$9$G$K$"$k!#;THN!"(JPDS etc..
$@#2!'$3$NK\$K>\$7$$!#(J

$@0l1~!"%W%m%0%i%`$r:\$;$F$*$-$^$9!#CQ$:$+$7$$E@$K$OL\$r$D$V$C$F$/$@$5$$!#(J

$@!d!d!d!d$3$3$+$i(J
$@#C%W%m%0%i%`(J
extern unsigned long outcount;
extern unsigned short loopc0, loopc1;
unsigned long d[256];

main()
{
	int	n, cont, c, i;
	unsigned long oldd, tmpd, diff;
	
	printf("\f");
	printf("## Stop-Watch Program ##\n");
	printf("* SPACE : Record Time\n");
	printf("* q     : Quit\n\n");
	printf("* type CR to start > ");
	
	loopc0 = 0x6000;
	loopc1 = 1;
	outcount = 0;
	n = 0;
	oldd = 0;
	
	getche();
	laptime();
	
	do{
		c = getch();
		if(c == 'q'){
			cont = 0;
		}else{
			tmpd = d[n] = outcount;
			if(n){
				diff = tmpd-oldd;
			}
			oldd = tmpd;
			n++;
			cont = 1;
		}
	}while(cont);
	qtimer();
	for(i = 0; i < n; i++){
		printf("%d %ld.%02ld\n", i, d[i]/100, d[i]%100);
	}
}

$@%"%;%s%V%i4X?t(J
;*********hardware interrupt routine ********* 
;	written by T.Yoshimi
;
.286c
INT_ADR	equ	20H	;addres for interrupt vector of timer
C8253	equ	01110111B
MODE0_SET equ	00110000B
MODE2_SET equ	00110100B
COUNT0	equ	01110001B
IMR	equ	2
;
	include dos.mac
;
DSEG
	outcount	dd	?
	incount dw	?
	loopc0	dw	?
	loopc1	dw	?
	intoff	dw	?
	intseg	dw	?
ENDDS

PSEG
;
public laptime, outcount, loopc0, loopc1, qtimer
laptime proc near
	pusha
	push ds
	push es
	push ss
	mov bp, sp
	;
	;set intterupt vector address in SI
	;
	mov si, INT_ADR
	mov ax, loopc1
	mov incount, ax
	;
	;set interrupt routine address in ax
	;
	mov ax, offset hard_int_routine
	mov bx, cs
	;
	;exchange interrupt vector
	;
	push ds
	push ax
	xor ax, ax
	mov ds, ax
	pop ax
	;
	cli
	xchg ax, [si]
	inc si
	inc si
	xchg bx, [si]
	sti
	pop ds
	;
	;store old interrupt routine address
	;
	mov intoff, ax
	mov intseg, bx
	;
	; set 8253
	;
	mov al, MODE2_SET
	out C8253, al
	jmp $+2
	jmp $+2
	;
	mov ax, loopc0
	out COUNT0, al
	jmp $+2
	jmp $+2
	mov al, ah
	out COUNT0, al
	;
	; SET 8259
	;
	cli
	in al, IMR
	and al, 11111110B
	out IMR, al
	sti
	;
	pop ss
	pop es
	pop ds
	popa
	ret
	;
hard_int_routine:
	cli
	;
	pusha
	push ds
	push es
	push ss
	mov ax, incount
	dec ax
	mov incount, ax
	cmp ax, 0000H
	jne recover
	;
	; inc_out
	;
	mov ax, loopc1
	mov incount, ax
	mov bx,offset ds:outcount
	mov ax, [bx]
	inc ax
	mov [bx], ax
	jnz recover
	mov ax, [bx+2]
	inc ax
	mov [bx+2], ax
recover:
	mov al, 20H
	out 00H, al
	pop ss
	pop es
	pop ds
	popa
	sti
	iret
	;
laptime endp
;
qtimer proc near
	pusha
	push ds
	push es
	push ss
	;
	; reset 8259
	;
	cli
	in al, IMR
	or al, 00000001B
	out IMR, al
	sti
	;
	; reset interrupt vector
	;
	mov si, INT_ADR
	mov ax, intoff
	mov bx, intseg
	;
	push ds
	push ax
	xor ax, ax
	mov ds, ax
	pop ax
	;
	cli
	xchg ax, [si]
	inc si
	inc si
	xchg bx, [si]
	sti
	pop ds
	pop ss
	pop es
	pop ds
	popa
	ret
	;
qtimer endp
;
ENDPS

end

$@!c!c!c!c$3$3$^$G(J

----------
$@5H8+(J $@N4(J($@$h$7$_(J $@$?$+$7(J)0x21$@:P(J $@:J#1?M(J(1959.Jun.19) yoshimi@etl.go.jp
[$@=jB0(J]$@EE;R5;=QAm9g8&5f=jCNG=%7%9%F%`It;k3P>pJs8&5f<<(J[$@;E;v(J]$@%3%s%T%e!<%?%S%8%g%s(J,
[$@9%(J]$@H~OB$A$c$s(J,SF,$@L!2h(J,$@<V(J,$@%P%$%/(J,$@$P$+OC(J,$@%2!<%`(J,$@1G2h(J,$@%S%G%*(J,$@%F%K%9(J,$@%9%-!<(J,
$@6d6LE4K$(J,AlanParsonsProject,$@Ea:,KcM};R(J[$@7y(J]$@$?$P$3(J($@$N$_(J,$@2q<R(J,$@9-9p(J,etc.),mohta

                          $@#6#1#9(J
                          $@!!!A(J    Copyright 1988-1992 Takashi YOSHIMI
Newsgroups: fj.sys.pc98,fj.sys.ibmpc