.nolist
.include "tn2313def.inc"
.list
	
.def 	temp   = R16
.def 	acc    = R17		
.def 	bcc    = R18
.def 	dcc    = R19	
.def 	ecc    = R20
.def 	fcc    = R21
.def 	gcc    = R22
.equ 	sclk	= PB7	
.equ 	data	= PB6	
.equ 	fsync	= PB5	;pre AD9835
.equ 	le  	= PB4	;pre LMX2316
.equ	le_lo	= PB3	;pre LMX2316 1GHz
.equ	ina_out	= PB2	;pre prepnutie signal/mixer ADG936		
;adresy v sram
.equ	freq_dds	= 0x0060
.equ 	frequency	= 0x006c;frekvencia vystupna
.equ 	doplnok		= 0x0072 
.equ	suma		= 0x007e
.equ 	delitel		= 0x0084	
.equ	LMX_ratio	= 0x008a			
.equ	LMX_ratzal 	= 0x008d
.equ	freq_rx1	= 0x0090;single
.equ	freq_rx2	= 0x0094;start
.equ	freq_rx3	= 0x0098;stop
.equ	freq_step	= 0x009C;step
.equ	flag		= 0x0064	;8 priznakov
.equ	rxbuf		= 0x00A0;bufer pre 5 bytov
.equ	inaf	= 0x07;ina flaf
.equ	rx_bol	= 0x06;flag ze bol rx a su data 	

.MACRO setflag                  ; Start macro definition 
        lds	temp,(flag)	;zober z adresy	
	set			;nastav T flag
	bld	temp,@0		;nastav bit podla flagu
	sts	(flag),temp     ; Subtract low byte
.ENDMACRO     

.MACRO clrflag                 ; Start macro definition 
        lds	temp,(flag)	;zober z adresy	
	clt			;nuluj T flag
	bld	temp,@0		;nastav bit podla flagu
	sts	(flag),temp     ; Subtract low byte
.ENDMACRO     

.MACRO tstflag                 ; Start macro definition 
        lds	temp,(flag)	;zober z adresy	
	bst	temp,@0		;presun bit do re T podla flagu
;mozem testovat ako na T
.ENDMACRO     


		.cseg
		.org	0x0000
		rjmp	main
		.org	0x0007
		rjmp	rx_prijem
		.org    0x0020	

;******** inicializace
;multiprocesorovy mod attiny2313 je slave rychlost je 38.4kbps aby vyslo 4byte do 1ms
;adresa 71h...SINGLE frequency mod...4 byte frequency..od 00 01 86 A0  do 3B 9A CA 00
;adresa 72h...START frequency mod....4 byte...END freq....4byte...STEP...3 byte
;MPCM bit >1 v UCSRA 
;38.4kbps	UBRR 25	 U2X=1 v ucsra
;76.8kbps	UBRR 12  U2X=1

;UCSRB	1 0 0 1 0 1 0 0 pre prijem
;UCSRC	0 0 0 0 0 1 1 0;nastaveny 9 bit rezim ak je 9 bit 1 tak je to adrres ak 0 su to data
;prijem dat z buffra
rx_prijem:
		push	temp
		push	acc
		in	temp,ucsrb
		in	temp,UDR
		cpi	temp,0xA5;je to moja adresa?
		brne	rx_end;	ak nie je tak odsok a pracuj dalej
		ldi	temp,(0<<MPCM)
		out	UCSRA,temp;priznak multiprocesora daj prec
		cli	;vypni prerusenie
		;budem cakat na dalsie data uz 8.bitove
rx_dat:
		ldi	acc,0x05
		ldi	xh,high(rxbuf)
		ldi	xl,low(rxbuf);adresa buffra
rx_zas:		sbis 	UCSRA,RXC
		rjmp	rx_zas;cakaj dokial nepridu data

		in	temp,UDR;uz prisli zober do tempu
		st	x+,temp;uloz do bufra
		dec	acc
		brne	rx_zas;zober 5 byte
		ldi	temp,(1<<MPCM);obnov multirezim
		setflag rx_bol	;nastav priznak
rx_en1:		sei	;zasa povol prerusenie
rx_end:
		pop	acc
		pop	temp
		reti
			

main:
 
		ldi	temp, RAMEND ;setup stack pointer
		out     SPL, temp
		clr	temp
		out	sfior,temp
		ser	temp	;nastav temp do FF
		out	ddra,temp ;nastavi port D ako vystup
		out	ddrb,temp ;nastavi port C ako vystup
		out	ddrd,temp  ;ako vystup
		clr	temp
		out	porta,temp
		out	portb,temp
		out	portd,temp
		sts	flag,temp
		rcall	wait
		rcall	LO_inic	;nastavim 1GHz osc
;presun z data eprom do sram a inicializacia VCO		
		rcall	wait
		rcall	AD_Inic;inic dds
		rcall	LMX_Inic;inic VCO		
		rcall	usart_init
		rcall	wait
		sei	;povol interupt

sdfgh:		tstflag	rx_bol
		brts	bol1
		rjmp	sdfgh			

bol1:
		lds	temp,rxbuf
		cpi	temp,0x10
		breq	frsing
		cpi	temp,0x20
		breq	frstart
		cpi	temp,0x40
		breq	frstop
		cpi	temp,0x80
		breq	step
		clrflag	rx_bol
		rjmp	sdfgh

;tu mam nastaveny LO,VCO a DDS
;*******************************************
;zoberiem data a dam na adresy kam patria 
;prevediem premenu a vyslanie do PLL a DDS
frsing:
		ldi	yh,high(rxbuf+1)
		ldi	yl,low(rxbuf+1)	
		ldi	xh,high(freq_rx1)
		ldi	xl,low(freq_rx1)
		ldi	acc,0x04
cykl_1:		ld	temp,y+
		st	x+,temp
		dec	acc
		brne	cykl_1
		rcall	freq_daj
		rjmp	sdfgh;cakaj na rx
;----------------------------------------
frstart:
		ret
frstop:
		ret
step:
		ret
		


freq_daj:	
		rcall	freq_rozsah_1
		rcall	prepocet
		tstflag	inaf
		brts	ina_on	;ak je 1 tak sa ma zapnt inak vypni
		cbi	portb,ina_out	;vypni ina...prepni zmiesavanie--->out	
		rjmp	dalej_1
ina_on:		sbi	portb,ina_out	;zapni ina...signal na priamo
dalej_1:		
		ret





;-------------------------------------------
;zistim z prijmanej frekvencie co treba robit
;ak bude menej ako 490.000.000Hz 1D 34 CE 80 je nutne ist cez 
;zmiesavanie...ak bude viac mozem ist na priamo s VCO
freq_rozsah_1:
		lds	temp,(freq_rx1)
		cpi	temp,0x1D
		breq	roz_1	;ak je rovny skok
		brlo	roz_lo	;ak je mensi		
		rjmp	roz_hg	;inak je vacsi

roz_1:		lds	temp,(freq_rx1+1)
		cpi	temp,0x34
		breq	roz_2	;ak je rovny skok
		brlo	roz_lo	;ak je mensi		
		rjmp	roz_hg	;inak je vacsi

roz_2:		lds	temp,(freq_rx1+2)
		cpi	temp,0xCE
		breq	roz_3	;ak je rovny skok
		brlo	roz_lo	;ak je mensi		
		rjmp	roz_hg	;inak je vacsi

roz_3:		lds	temp,(freq_rx1+3)
		cpi	temp,0x80
		breq	roz_hg	;ak je rovny skok
		brlo	roz_lo	;ak je mensi		
		rjmp	roz_hg	;inak je vacsi
roz_lo:;musim odpocitat od 1000.000.000Hz..idem cez zmiesavac
		rcall	odpocet_1G
		ret
roz_hg:;len nastavim priamo frequenciu a prepnem ADG936
		lds	temp,(freq_rx1)
		sts	(frequency),temp
		lds	temp,(freq_rx1+1)
		sts	(frequency+1),temp
		lds	temp,(freq_rx1+2)
		sts	(frequency+2),temp
		lds	temp,(freq_rx1+3)
		sts	(frequency+3),temp
		setflag	inaf	;uzivatelsky priznak
		ret
		;stade skoci na rcall prepocet
;-----------------------------------
odpocet_1G:
		lds	acc,(freq_rx1+3)
		ldi	temp,0x00
		sub	temp,acc
		sts	(frequency+3),temp
		lds	acc,(freq_rx1+2)
		ldi	temp,0xCA
		sbc	temp,acc
		sts	(frequency+2),temp
		lds	acc,(freq_rx1+1)
		ldi	temp,0x9A
		sbc	temp,acc
		sts	(frequency+1),temp
		lds	acc,(freq_rx1)
		ldi	temp,0x3B
		sbc	temp,acc
		sts	(frequency),temp
		ret
;*******************************************
Prepocet:
		rcall	prenos_pll_slovo
		rcall	del_posuv_hladaj
		ldi	ecc,26	;korekcia pre 128.000
		rcall	sucet
		rcall	pll_slovo_ake
		rcall	del_posuv_hladaj
		ldi	ecc,22	;korekcia pre pll slovo
		rcall	sucet
		rcall	nasobenie
		rcall	pre_LMX_ratio	;uprav ratio pre vysielanie
;vysielaj
		rcall	Data_AD	;poslem DDS slovo
		
		lds	temp,(LMX_ratio+1)
		lds	acc,(LMX_ratzal+1)
		cp	temp,acc
		brne	pres_lm	;ak sa nerovnaju presun LMX_ratio na zalohu
		lds	temp,(LMX_ratio);ak sa rovnaju skus este MSB byte
		lds	acc,(LMX_ratzal)
		cp	temp,acc
		brne	pres_lm	;ak sa nerovnaju presun na zalohu a vysli
		
		ret	;koniec rutiny slov dds a pll

pres_lm:	lds	temp,(LMX_ratio+1)
		sts	(LMX_ratzal+1),temp
		lds	temp,(LMX_ratio)
		sts	(LMX_ratzal),temp
		;posli data do LMX
		ldi	zh,high(LMX_ratio);data v sram
		ldi	zl,low(LMX_ratio)	;delicka  N  freq VCO
		ldi	temp,0b10000000
		rcall	LMX_TX_sram



		ret	;koniec rutiny slov pre pll a dds
;***********************************************************
;najprv najst kde je prva 1 v delenci a posunut prvu 1 delitela na jeho uroven
;vysledok posunutia dava na 74h-77h...musi byt vyplneny 0x00, delitel je na 90h-93h
;doplnok je na 78h-7eh..nie je univerzalne!!!
del_posuv_hladaj:
		ldi	xh,high(frequency)
		ldi	xl,low(frequency)
		ld	r1,x
		ldi	acc,0b10000000
		mov	r4,acc
del_zas_1:	
		rol	r1	;rotuj;u mna stale najde v prvom byte!!!minimum33.500.000
		brcs	pos_naslo;ak je 1 tak naslo 1 a mam cislo o kolko posunut
		lsr	r4
		rjmp	del_zas_1;a zacni znovu hladat!!pozor nekonecna smycka!!!
pos_naslo:			
;teraz presuniem byte na adrsu a potom poposuvam o
		ldi	zh,high(delitel)
		ldi	zl,low(delitel)	;tu je ulozeny delitel 3byte
		ld	r1,z+
		ld	r2,z+
		ld	r3,z+
		clr	acc
pos_zas_1:	inc	acc		;pocitadlo pre delenie
		lsl	r3	;posun do c
		rol	r2	;daj do c a posun do c
		rol	r1	;daj do c a posun do c
		mov	r5,r1
		and	r5,r4	;hladaj kde je bit ak je nula nenaslo
		breq	pos_zas_1 ;a posunie vsetko zas o 1 bit
;		dec	acc;acc-1
;ulozim zrotovane spat a znegovane-doplnok tiez
		clr	r4
		clr	xh
		ldi	xl,low(doplnok)
		st	x+,r1
		st	x+,r2
		st	x+,r3	;ulozim vysledok
		st	x+,r4	;ulozim aj 0x00 aby bolo 4byte
		com	r1
		com	r2
		com	r3
		com	r4
		st	x+,r1
		st	x+,r2
		st	x+,r3	;ulozim doplnok zaporny by mal byt
		st	x,r4
		ret
;-------------------------------------------------------
sucet:			
		clr	r15	;vynuluj registre
		clr	r14 
		add	ecc,acc
		clr	dcc
		clr	acc
		ldi	zh,high(frequency)
		ldi	zl,low(frequency);delenec
		ld	r0,z+
		ld	r1,z+
		ld	r2,z+
		ld	r3,z
		ldi	xh,high(doplnok)
		ldi	xl,low(doplnok);delitel doplnok zaporny
		ld	r4,x+
		ld	r5,x+
		ld	r6,x+
		ld	r7,x+
		ld	r8,x+ ;tu je uz dolnok
		ld	r9,x+
		ld	r10,x+
		ld	r11,x

sucet_zas:	inc	dcc
		cp	dcc,ecc
		brne	sucet_dal
		ret
sucet_dal:	sec
		rol	r15
		rol	r14
		rol	r13
		rol	r12
		clc
		add	r3,r11
		adc	r2,r10
		adc	r1,r9
		adc	r0,r8
		
		brmi	korekcia;ak je nastaveny N zaporny
;ak nie je korekcia tak je prenos treba pricitat
priznak:	adc	r3,acc	;pripocitaj priznak
		adc	r2,acc
		adc	r1,acc
		adc	r0,acc
		rcall	roll
		rjmp	sucet_zas
korekcia:
		rcall	nula_o
		brts	koniec	;ak je T=1 koniec delenia
		rcall	zapis
		
		add	r3,r7	;delitel
		adc	r2,r6
		adc	r1,r5
		adc	r0,r4
		rjmp	priznak
		
zapis:
		lsr	r12
		ror	r13
		ror	r14
		ror	r15
		lsl	r15
		rol	r14
		rol	r13
		rol	r12
		ret
roll:
		mov	bcc,r0
		rol	bcc
		rol	r3
		rol	r2
		rol	r1
		rol	r0
		ret
;zistim ci je vsetkych 4byte ffh ak ano delenie je bezo zvysku
nula_o:
		mov	bcc,r0
		com	bcc
		brne	nula_nie
		mov	bcc,r1
		com	bcc
		brne	nula_nie
		mov	bcc,r2
		com	bcc
		brne	nula_nie
		mov	bcc,r3
		com	bcc
		brne	nula_nie
		set	;nastav priznakovy bit T
		ret
nula_nie:
		clt	;vymaz priznak T
		ret
koniec:
;upravim na 4 byty posuvom do 32x
		inc	dcc
kon_zas:
		inc	dcc
		lsl	r15 ;na prve miesto 0
		rol	r14
		rol	r13
		rol	r12
		cp	dcc,ecc
		brne	kon_zas
		ret
;----------------------------------------------
;ak je desatinna cast viac ako 0.5d teda viac alebo rovne ako xx xx 8x xx
;tak pripocitam k pll slovu +1...budem teda pouzivat frek. mensiu ako 128.000  
;desatinna cast je v r14
pll_slovo_ake:
		mov	temp,r14	;prenes do temp		
		cpi	temp,0x80	;porovnaj je x80?
		brsh	slovo_plus	;ak je vacsi alebo rovny skoc
		rjmp	slovo_1
slovo_plus:
		inc	r13	
slovo_1:
		clr	temp
		sts	delitel,temp
		sts	delitel+1,r12
		sts	delitel+2,r13
		ret
;-------------------------------------------------
;prenesiem zakladny krok pll 128.00 pre delenie
prenos_pll_slovo:
		ldi	zh,high(pll_krok*2)
		ldi	zl,low(pll_krok*2)
		ldi	xh,high(delitel)
		ldi	xl,low(delitel)
		ldi	temp,3
pll_slovo_zas:
		lpm	r0,z+
		st	x+,r0
		dec	temp
		brne	pll_slovo_zas
		ret
;-----------------------------------------------
;nasobenie cisla okolo 128.000 x 4000...vznika rovno cislo pouzitelne 
;pre DDS, okolo 5.120.000 MHz
nasobenie:
		ldi	acc,11						
		clr	temp
		ldi	xh,0x00
		ldi	xl,0x00
nas_zas:
		st	x+,temp	;nuluj sram
		dec	acc
		brne	nas_zas
		
		ldi	zh,0xa0	;nasobenec
		ldi	zl,0x0f	; 4000 dec
		movw	r6,z
		ldi	temp,36	;opakuj 36x teda 5 byte
nas_zas_2:
		rcall	nas_posun	;posun bity
		rcall	nas_posun_2	;posun nasbitela do cary
		brcs	scit		;ak je carry 1 tak pricitaj nasobenca
nas_zas_3:
		dec	temp
		brne	nas_zas_2
		ldi	xh,high(freq_dds)
		ldi	xl,low(freq_dds)
		st	x+,r0	;presuniem do SRAM
		st	x+,r1
		st	x+,r2
		st	x+,r3
		ret
scit:
		rcall	nas_suma	;pricitaj 4000
		rjmp	nas_zas_3
nas_suma:
		add	r5,r7	;pricitaj nasobenec
		adc	r4,r6
		adc	r3,r10	;stacia nuly r10=0
		adc	r2,r10
		adc	r1,r10
		adc	r0,r10
		ret
nas_posun:
		lsl	r5 ;na prve miesto 0
		rol	r4
		rol	r3
		rol	r2
		rol	r1
		rol	r0
		clc
		ret
nas_posun_2:
		lsl	r15 ;na prve miesto 0
		rol	r14
		rol	r13
		rol	r12
		ret
;-----------------------------------------------
;uprava pre format vhodny na vysielanie
pre_LMX_ratio:
		clr	r6;nuluj r6
		clr	r7
		ldi	xh,high(delitel)
		ldi	xl,low(delitel)
		ld	r8,x+
		ld	r8,x+
		ld	r9,x
		lsl	r9
		rol	r8
		lsl	r9	
		rol	r8
		
		ldi	temp,0b00000001;dodaj c1 c2 bity
		or	r9,temp
		ldi	xh,high(LMX_ratio)
		ldi	xl,low(LMX_ratio)
		st	x+,r8
		st	x,r9
		ret

;---------------------------------------------------------------------
AD_Inic:
;inicializujem AD9835
		ldi	acc,0b11111000	;sleep-1 reset-1 clr-1 
		clr	bcc
		rcall	SPI_trans
		ldi	acc,0b10110000	;sync-1 selsrc-1
		clr	bcc
		rcall	SPI_trans
		rcall	Data_AD			;poslem freq
		rcall	Phase_AD		;poslem fazy
		ldi	acc,0b01100000	;freq0 je vybrana 
		clr	bcc
		rcall	SPI_trans
		ldi	acc,0b11000000	;sleep-0 reset-0 clr-0
		clr	bcc
		rcall   SPI_trans
		ret

Data_AD:
		ldi	xh,0x00
		ldi	xl,0x64			;adresa v SRAM
		ldi	acc,0b00110000	;zapis do freq0 registra nasledujuci byte
    		ld	bcc,-x			;vyber zo sram 
		rcall	SPI_trans		;a zapis
		ldi	acc,0b00100001	;zapis do freq0 registra nasledujuci byte
	    	ld	bcc,-x			;vyber zo sram 
		rcall	SPI_trans		;a zapis
		ldi	acc,0b00110010	;zapis do freq0 registra nasledujuci byte
    		ld	bcc,-x			;vyber zo sram 
		rcall	SPI_trans		;a zapis
		ldi	acc,0b00100011	;zapis do freq0 registra nasledujuci byte
    		ld	bcc,-x			;vyber zo sram 
		rcall	SPI_trans		;a zapis
		ret
Phase_AD:
		ldi	acc,0b00011000	;zapis do phase registra nasledujuci byte
		clr	bcc			    ;bcc daj do 0 
		rcall	SPI_trans		;a zapis
		ldi	acc,0b00001000	;zapis do phase registra nasledujuci byte
		clr	bcc			    ;bcc daj do 0 
		rcall	SPI_trans		;a zapis
		ret

SPI_trans:;posielam 16 bit   data v acc a bcc
		ldi	fcc,8
		sbi	portb,sclk
		cbi	portb,fsync
		rcall	spi_1
		mov	acc,bcc
		rcall	spi_1
		sbi	portb,fsync
		ret
spi_1:		rol	acc
		brcs	d_one
		cbi	portb,data
		rjmp	spi_s1
d_one:	 	sbi	portb,data
spi_s1: 	rcall	sck_01
		dec	fcc
		brne	spi_1
		ldi	fcc,8
		ret


sck_01:			
		cbi	portb,sclk
		nop
		sbi	portb,sclk
		ret
				
LMX_Inic:
;pre vysielanie potrebujem 21 bitov...MSB first ale prvych 5 bit je stale 0
;teda mozem ukladat a pracovat len so 16 bitmi, tie vyslem hned za 5 bitmi
;LE musi byt v 1 ked vysielam musi byt v 0 a potvrdi sa hranou z 0 do 1		
;		ldi		xh,0x00	;
;		ldi		xl,0x60	;adresa v SRAM

		ldi		zh,high(LMX_I*2);data v eprom
		ldi		zl,low(LMX_I*2)	;pre inicializaciu
		clr		temp	;tu su tie 5 bitov keby bolo treba nieco ine ako 0
		rcall	LMX_TX

		ldi		zh,high(LMX_R*2);data v eprom
		ldi		zl,low(LMX_R*2)	;delicka R...referencie
		clr		temp
		rcall	LMX_TX

		ldi		zh,high(LMX_N*2);data v eprom
		ldi		zl,low(LMX_N*2)	;delicka  N  freq VCO
		ldi		temp,0b10000000
		rcall	LMX_TX

		ldi		zh,high(LMX_F*2);data v eprom
		ldi		zl,low(LMX_F*2)	;pre inicializaciu
		clr		temp
		rcall	LMX_TX

		ret
;----------------------------------------------------
;z pamati sram
LMX_TX_sram:
		ldi	fcc,5
		cbi	portb,sclk	;do 0
		cbi	portb,le	;do 0		
		rcall	LMX_trans_5
		ldi	bcc,0x02		 
zass_2:		ld	acc,z+			
		rcall	LMX_trans_8
		dec	bcc				
		brne	zass_2
		sbi	portb,le	;potvrd prenos
		ret

;z pamati programu
LO_TX:
		ldi	fcc,5
		cbi	portb,sclk	;do 0
		cbi	portb,le_lo	;do 0
		rcall	LMX_trans_5
		ldi	bcc,0x02		 
zaslo_2:	lpm	acc,z+			
		rcall	LMX_trans_8
		dec	bcc				
		brne	zaslo_2
		sbi	portb,le_lo	;potvrd prenos
		ret


LMX_TX:
		ldi	fcc,5
		cbi	portb,sclk	;do 0
		cbi	portb,le	;do 0
		rcall	LMX_trans_5
		ldi	bcc,0x02		 
zas_2:		lpm	acc,z+			
		rcall	LMX_trans_8
		dec	bcc				
		brne	zas_2
		sbi	portb,le	;potvrd prenos
		ret

LMX_trans_5:
;vyslem len 5 bitov 0
spi_l4:		rol	temp
		brcs	d_onel2
		cbi	portb,data
		rjmp	spi_l5
d_onel2:	sbi	portb,data
spi_l5: 	rcall	sck_lmx
		dec	fcc
		brne	spi_l4
		ret		
sck_lmx:			
		sbi	portb,sclk;do 1 lmx prima data na vzostup
		nop
		cbi	portb,sclk
		ret

LMX_trans_8:
;vysielam 8 bit
		ldi	fcc,8
spi_l2:		rol	acc
		brcs	d_onel
		cbi	portb,data
		rjmp	spi_l3
d_onel:		sbi	portb,data
spi_l3: 	rcall	sck_lmx
		dec	fcc
		brne	spi_l2
		ret
;-------------------------------------------
;inicializacia a vyslanie slova pre lock 1000MHz, fref 5MHz/5...1MHz...LMX2316
;P=32 B=992 A=8 N=1000
LO_Inic:
		ldi		zh,high(LO_I*2);data v eprom
		ldi		zl,low(LO_I*2)	;pre inicializaciu
		clr		temp	;tu su tie 5 bitov keby bolo treba nieco ine ako 0
		rcall	LO_TX

		ldi		zh,high(LO_R*2);data v eprom
		ldi		zl,low(LO_R*2)	;delicka R...referencie
		clr		temp
		rcall	LO_TX

		ldi		zh,high(LO_N*2);data v eprom
		ldi		zl,low(LO_N*2)	;delicka  N  freq VCO
		ldi		temp,0b10000000
		rcall	LO_TX

		ldi		zh,high(LO_F*2);data v eprom
		ldi		zl,low(LO_F*2)	;pre inicializaciu
		clr		temp
		rcall	LO_TX
		ret
;===============usart inicializacia=============
;adresa je 0xA5
usart_init:
		clr	temp
		out	UBRRH,temp;0x00
		ldi	temp,25
		out	UBRRL,temp;19200

		ldi	temp,(1<<MPCM )	;multi procesor teda prepusti
		out	UCSRA,temp	;do bufferu len 9 bitove slovo
		ldi	temp,(1<<RXCIE | 1<<RXEN | 0<<TXEN | 1<<UCSZ2)
		out	UCSRB,temp;povol prerusenie, prijem aj vysielanie
		ldi	temp,(1<<UCSZ1 | 1<<UCSZ0)
		out	UCSRC,temp;nastav 9.bitovu komunikaciu
		ret
;-------------------------------------------

;TX_adresa:;adresa je v temp
;		sbis	UCSRA,UDRE	
;		rjmp	tx_adresa	;cakaj dokial buffer je empty
;
;		sbi	UCSRB,TXB8
;		out	UDR,temp
;		ret
;TX_data:;data v temp
;		sbis	UCSRA,UDRE	
;		rjmp	tx_data		;cakaj dokial buffer je empty
;
;		cbi	UCSRB,TXB8	;posialm len 8 bit
;		out	UDR,temp
;		ret


;wait:	ret

wait200:
		ldi	bcc,0x15
w_1:		ldi	yh,0xff
		ldi	yl,0xff
w_2:		nop
		sbiw	y,0x01
		brne	w_2
		dec	bcc;
		brne	w_1
		ret

wait:
		ser		dcc
wa_2:		ser		ecc
wa_1:		nop
		dec		ecc
		brne	wa_1
		dec		dcc
		brne	wa_2
		ret
		.org	0x0300		
	



LMX_R:
		.db		0x00,0xA0;R=40
LMX_N:
		.db		0x61,0x8d;0x3d,0x09;0x42,0x8D;0x3D,0x0D;B=122 A=3   delicka=3907
LMX_I:
		.db		0x00,0x27;inicializacia zacinat s 0x27,negativ CP lebo je OZ!!
LMX_F:
		.db		0x00,0x22	
pll_krok:
		.db		0x01,0xF4,0x00,0x00
LO_R:
		.db		0x00,0x14;R=5
LO_N:
		.db		0x0f,0xA1;N=1000 32 x 31+8...1000
LO_F:
		.db		0x00,0xc2;mux=N  inac 82
LO_I:
		.db		0x00,0xc7;0x03,0x00 vdd

freqw1:
		.db	0x20,0xc8,0x55,0x80;550 000 000
