; Timer0 - LED blikanie

; pre 1MHz plati clock: 1/1000000s = 0,000001s (1us)
; 8-bit overflow: 0,000256s (0,256ms)
; 8-bit overflow s prescalerom 1024: 0,262144s, do 1 sekundy: 3,81x overflow

; ATmega8 ma Timer0 jednoduchy, ziadne PWM, CTC, nema ani vyvedenu nozicku OC0

.nolist
.include "m8def.inc"
.list ; Project - Assembler Options - Create List File (.lst)

.equ F_CPU    = 1000000
.def TEMP     = R16

.equ DDR_LED  = DDRB
.equ PORT_LED = PORTB
.equ PIN_LED  = PINB
.equ BIT_LED  = PB1

.cseg
.org 0x0000
	rjmp RESET
.org OVF0addr
	rjmp TIMER0_OVF_vect

RESET:
	ldi TEMP, high(ramend)
	out SPH, TEMP
	ldi TEMP, low(ramend)
	out SPL, TEMP

	sbi DDR_LED, BIT_LED
	sbi PORT_LED, BIT_LED

	; nastavenie Timer0 Prescaler 1024
	ldi TEMP, 1<<CS02 | 1<<CS00
	out TCCR0, TEMP
	; povolenie Timer0 Overflow Interrupt Enable
	ldi TEMP, 1<<TOIE0
	out TIMSK, TEMP
	; globalne povolenie Interrupt (v SREG)
	sei

FURT:
	rjmp FURT

TIMER0_OVF_vect:
;	in TEMP, PIN_LED
;	ldi R17, 1<<BIT_LED
;	eor TEMP, R17
;	out PORT_LED, TEMP

IF:	sbis PIN_LED, BIT_LED
	rjmp ELSE
	cbi PORT_LED, BIT_LED
	rjmp ENDIF
ELSE:
	sbi PORT_LED, BIT_LED
ENDIF:
	
	reti
