.include "m88def.inc"

; Interrupt Vectore Table
.CSEG
.ORG 0x0
	rjmp start                      ; jump to start

.ORG OVF0addr			; Timer/Counter0 Overflow
	rjmp	ISR_TOV0

init_Ex1:
	ldi r16,(1<<CS02)|(1<<CS00)
	out TCCR0B,r16 ; Timer clock = system clock / 1024
	;timer overflow interrupt
	ldi r16,1<<TOV0
	out TIFR0,r16
	ldi r16,1<<OCIE0B
	ldi ZL,LOW(TIMSK0)
	ldi ZH,HIGH(TIMSK0)
	st  Z,r16
	ser r16
	out DDRC,r16 ; Set Port B as output
	out PORTC,r16
	ret

ISR_TOV0:
	push r16
	in r16,SREG
	push r16
	in r16,PORTC ; Read Port B
	com r16 ; Invert bits of r16 register
	out PORTC,r16 ; Write Port B
	pop r16
	out SREG,r16
	pop r16
	reti

; *** Begin of Program Execution ***
start:
; Initialization of the Stack Pointer
	ldi	r16,low(RAMEND)
	out	SPL,r16
	ldi	r16,high(RAMEND)
	out SPH,r16

; Enable the next line for Example 1 disable for other Examples
	rcall	init_Ex1
; (CL_2.2) 
	sei				; Global Interrupts enabled

; Endlessloop
loopforever:
rjmp	loopforever
