		LIST P=18F4523, r=HEX
    	errorlevel	-302
		#include <p18f4523.inc>
		
;Pozn.:Pre debugger je potrebné nechat volnú oblast vo flash-ke od 0x7DC0
;po 0x7FFF a RAM-ke (GPR) 0x5F4-0x5FF.
;
;Hodiny pouzivaju interny oscilator 8 MHz s PLL 4x; -> Fosc = 32 MHz; Tcy = 125 ns
;				
;*********************************************************************************
	;CONFIG OSC=INTIO67, WDT=OFF, PWRT=ON, BOREN=SBORDIS, BORV=0
	;CONFIG MCLRE=ON, LPT1OSC=OFF, STVREN=ON, LVP=OFF, XINST=OFF
	;CONFIG DEBUG=ON, PBADEN=OFF, CP0=OFF, CP1=OFF, CP2=OFF, CP3=OFF
	;CONFIG WRT0=OFF, WRT1=OFF, WRT2=OFF, WRT3=OFF
;********************************************************************************* 

	org	0x0000              ;start programu po resete
	goto Start
	org	0x0008              ;vysokourovnove prerusenie
	retfie
	org	0x0018
	retfie		            ;nizkourovnove prerusenie

Start:
	movlw	B'01110010'		;prepnutie multiplexera interneho oscilatora na 8 MHz (defaultne po resete je
	movwf	OSCCON			;zapnuty 1 MHz) + zapnutie PLL + kontrola stability oscilatora
	bsf		OSCTUNE,PLLEN
	btfss	OSCCON,	IOFS
	bra		$-2
;----------------
	clrf	PORTA
	clrf	PORTB
    clrf	PORTC
    clrf	PORTD
	clrf	PORTE
;Vyber banky 0
;	movlb	0x00
;----------------
	bcf		TRISC,2
	movlw	B'01000010'		;Timer0-8 bitov-povoleny, hodiny z instrukcného
	movwf	T0CON			;cyklu, preddelic 8 -> tik za 1 us
	bcf		INTCON,TMR0IF	;vynulovanie príznaku pretecenia TMR0
Pulz:
	bsf		LATC,2
	
;	movlw	0xF1			;nastavenie TMR0 na 20 ms
;	movwf	TMR0H
;	movlw	0xDF
;	movwf	TMR0L
	clrf	TMR0L
	bsf		T0CON,TMR0ON	;start TMR0
	btfss	INTCON,TMR0IF	;nastalo pretecenie TMR0?
	bra		$-2				;ak nie, skús znova, inác pokracuj dalej
	bcf		T0CON,TMR0ON	;stop TMR0
	bcf		INTCON,TMR0IF
	bcf		LATC,2			;koniec pulzu
;------------------------
;	movlw	0xF1			;nastavenie TMR0 na 20 ms
;	movwf	TMR0H
;	movlw	0xDF
;	movwf	TMR0L
	clrf	TMR0L
	bsf		T0CON,TMR0ON	;Start TMR0
	btfss	INTCON,TMR0IF	;nastalo pretecenie TMR0?
	bra		$-2				;ak nie, skús znova, inác pokracuj dalej
	bcf		T0CON,TMR0ON	;stop TMR0
	bcf		INTCON,TMR0IF
	bra		Pulz
	sleep
;
    end