.INCLUDE "m8DEF.INC"

.equ	Fo=1000000
.equ	N=Fo/65536

.cseg
.org   0
	RJMP	START
.org	$06
	RET
.org	$08
	DEC	R20
	BRNE	T1_OVER_OUT
	ldi	R16,1<<OCIE1A
	out	TIMSK,R16
	LDI	R22,(1<<WGM12)|(1<<CS10)	;נוזטל CTC Fo/1
	OUT	TCCR1B,R22
;*************
	OUT	TIFR,R16
;*************
T1_OVER_OUT:
	RETI
;*************************************************
START:
   ldi      ZL,Low(RAMEND)
   out      SPL,ZL
   ldi      ZH,High(RAMEND)
   out      SPH,ZH
GO:
	LDI	R20,N
	LDI	XH,HIGH(Fo-N*65536-1)
	LDI	XL,LOW(Fo-N*65536-1)
	OUT      OCR1AH,XH         ;to count in CTC mode           ;1
	OUT      OCR1AL,XL

	LDI	R22,(1<<SE)
	OUT	MCUCR,R22		; נוזטל SLEEP IDLE

	LDI	R22,1<<TOIE1
	OUT	TIMSK,R22
	OUT	TIFR,R22

	ldi      R22,1<<CS10
	out      TCCR1B,R22

	SEI
main:
	SLEEP
	NOP
	BRIE	main
	RJMP	GO
.EXIT
