.nolist
.include "m8def.inc"
.list
	
.def temp   = R16
.def acc    = R17		
.def bcc    = R18
.def dcc    = R19	
.def ecc    = R20
.def fcc    = R21
.def gcc    = R22

.equ	lcdport_d	= portd
.equ	lcdport_b	= portb	
.equ 	lcde		= PB0
.equ 	lcdrs		= PD0
.equ 	lcdrw  		= PD1
;.equ 	int0	=	PD2
;.equ	int1	=	PD1	

.equ	cs		=	PB2 ;default 0..zapnuty io
.equ	sclk	=	PB5
.equ	sdo		=	PB4;pripojit na sdo fyzicky je to vstupny pin miso
.equ	sdi		=	PB3;pripojit na sdi fyzicky je to vystupny pin mosi		
.equ	osk		=	PC1 ;default 0
.equ	iosync	=	PC2 ;default 0
.equ	reset	=	PC3 ;default 0  reset je 0-1-0
.equ	pwdown	=	PC4 ;default 0
.equ	ioupdate=	PC5 ;default 0
.set	freq	=	0x007A
.set    counter	=	0x0083
.set	srampam	=	0x0084	;pre LCD
;-------------------------------
;slova pre LCD
.set kom_8b  =    0b00110000               ;komunikacny rezim 8 bit
.set kom_4b  =    0b00100000               ;komunikacny rezim 4 bit
.set rez_1r  =    0b00000000               ;rezim 1 riadkovy
.set rez_2r  =    0b00001000               ;rezim 2 riadkovy
.set fon_5x7 =    0b00000000               ;fonty 5x7 bodov
.set fon_5x10 =   0b00000100               ;fonty 5x10 bodov
.set dis_off  =   0b00001000               ;display nezobrazuje
.set dis_on   =   0b00001100               ;display zobrazuje
.set cur_off  =   0b00001000               ;cursor nezobrazit
.set cur_on   =   0b00001010               ;cursor zobrazit
.set blk_off  =   0b00001000               ;pismeno neblika
.set blk_on   =   0b00001001               ;pismeno blika
.set clr_dis  =   0b00000001               ;zmaz displej
.set ddr_inc  =   0b00000110               ;DDRAM increm. pri zapise (posuv vp)
.set ddr_dec  =   0b00000100               ;DDRAM decrem. pri zapise (posuv vl)
.set shf_off  =   0b00000100               ;posuv zn. ak dojde na kraj vypnuty
.set shf_on   =   0b00000101               ;posuv zn. ak dojde na kraj zapnuty
.set scrol    =   0b00011000               ;posuva cely riadok bez zmeny dat
.set cursor   =   0b00010000               ;posuva kurzor bez zmeny dat
.set right    =   0b00010100               ;do prava
.set left     =   0b00010000               ;do lava
.set home_cur =   0b00000010               ;navrat kur. vlavo hore DDRAM ostava
.set ddram    =   0b10000000               ;adresa DDRAM
.set cgram    =   0b01000000               ;adresa CGRAM
;--------------------------


		.cseg
		.org	0x0000
		rjmp	main
		.org	0x0001
		rjmp	up_enc


		.org    0x0020	
;-----------prerucenie int0------------
;ak prisliel impulz tu tak je increment hore
up_enc:
;		clt
;		clr	r0
;		nop
;		nop
;		nop
;		sbic	pind,pd2 ; je int1 v 1?
;		inc	r0
;		set	;nastav priznak
;		reti
;up_2:
;		set	
;		reti			

;		push	acc
;		push	temp
;		in	temp,pind
;		andi	temp,0b00001100
;		mov	acc,temp
;enc_zas:	in	temp,pind
;		andi	temp,0b00001100
;		cp	temp,acc
;		breq	enc_zas
;		andi	acc,0b00001000
;		andi	temp,0b00000100
;		lsl	temp
;		eor	temp,acc
;		brne	enc_0
;		inc	r0
;enc_0:		pop	temp
;		pop	temp
;		reti
;******** inicializace
main:
 
		ldi	temp, LOW(RAMEND) ;setup stack pointer
		out     SPL, temp
		ldi	temp, HIGH(RAMEND)
		out	SPH, temp
		clr	temp
		out	sfior,temp
		ser	temp	;nastav temp do FF
		out	ddrd,temp ;nastavi port D ako vystup
		out	ddrc,temp ;nastavi port C ako vystup
		out	ddrb,temp  ;ako vystup
		clr	temp
		out	portd,temp
		out	portb,temp
		out	portc,temp
		ldi	temp,0b11110011	
		out	ddrd,temp
;		rcall	wait2
		ldi	temp,0b11111111
		out	portd,temp
		

		ldi	temp,0b00111111
		out	ddrb,temp	;pb6,pb7 vstupy
		ldi	temp,0b11111000
		out	portb,temp	;pb0,pb1,pb2 do 0
		ldi	temp,0b11111110
		out	ddrc,temp
		ldi	temp,0b00000000
		out	portc,temp
		ldi	temp,1
		sts	counter,temp;uloz 1 do sram
;		inc	r0	;r0 = 0b00000001


		sbi		portc,reset;do 1
		rcall	wait
		cbi		portc,reset;do 0
		cbi	portb,pb7
		rcall	wait200
		rcall	SPI_init
		rcall	ADC_Init
		rcall	LCD_init
		rcall	wait200
		rcall	prenos_lcd_1
		rcall	prenos_lcd_singl
		rcall	line1
		rcall	line2
;		ldi	temp,(1<<int0 );| 1<<int1)
;		out	GICR,temp
;		ldi	temp,(0<<ISC00 | 1<<ISC01 );| 0<<ISC10 | 1<<ISC11)
;		out	MCUCR,temp 
		ldi	zh,high(ad9952_f2*2);1mhz dam do registrov r5-r8
		ldi	zl,low(ad9952_f2*2)
		ldi	xh,high(freq)
		ldi	xl,low(freq)
		lpm	r5,z+	;prenoz z program do reg
		st	x+,r5	;hned aj prenos z reg do sram
		lpm	r6,z+
		st	x+,r6
		lpm	r7,z+
		st	x+,r7
		lpm	r8,z
		st	x+,r8	;zaroven je to krok
		st	x+,r5
		st	x+,r6
		st	x+,r7
		st	x+,r8

	;	sei
;		rjmp	zmen_fr

;dfgh:	rjmp	dfgh


;		rjmp	AMM
;teraz naplnim ad9952 datami z pamati
		ldi	temp,0x00	;dam slovo registra a vyslem ho ako prve
		rcall	SPI_transmit
		ldi	zh,high(ad9952_0*2);adresa v mem- prve datove slovo
		ldi	zl,low(ad9952_0*2)
		ldi	acc,0x04	;kolko ma byte
		rcall	posli
		 
		ldi	temp,0x01	;dam slovo registra a vyslem ho ako prve
		rcall	SPI_transmit
		ldi	zh,high(ad9952_1*2);adresa v mem- prve datove slovo
		ldi	zl,low(ad9952_1*2)
		ldi	acc,0x03	;kolko ma byte
		rcall	posli

		ldi	temp,0x02	;dam slovo registra a vyslem ho ako prve
		rcall	SPI_transmit
		ldi	zh,high(ad9952_2*2);adresa v mem- druhe
		ldi	zl,low(ad9952_2*2)
		ldi	acc,0x02	;kolko ma byte
		rcall	posli

		ldi	temp,0x03	;dam slovo registra a vyslem ho ako prve
		rcall	SPI_transmit
		ldi	zh,high(ad9952_3*2);adresa v mem- arp
		ldi	zl,low(ad9952_3*2)
		ldi	acc,0x01	;kolko ma byte
		rcall	posli

		ldi	temp,0x04	;dam slovo registra 
		rcall	SPI_transmit
		ldi	zh,high(ad9952_f2*2);adresa v mem- freqv
		ldi	zl,low(ad9952_f2*2)
		ldi	acc,0x04	;kolko ma byte
		rcall	posli

		ldi	temp,0x05	;dam slovo registra a vyslem ho ako prve
		rcall	SPI_transmit
		ldi	zh,high(ad9952_5*2);adresa v mem- phase
		ldi	zl,low(ad9952_5*2)
		ldi	acc,0x02	;kolko ma byte
		rcall	posli

;teraz ioupdate
		rcall	io_update
;------------------------------------------
;teraz budem cakat na button , zmenim frekvenciu po kazdom stlaceni


zas:
		in	temp,pind
		andi	temp,0b00001100
		mov	acc,temp	
enc_zas:	sbis	pinb,pb7
		rjmp	tx_fm
		sbis	pinb,pb6
		rjmp	tx_am

		in	temp,pind
		andi	temp,0b00001100
		cp	temp,acc
		breq	enc_zas
		andi	acc,0b00001000
		andi	temp,0b00000100
		lsl	temp
		eor	temp,acc
		breq	zmen_fr
		inc	r0
zmen_fr:
	;	cli		;zastav prerusenie
		ldi	xh,high(freq)
		ldi	xl,low(freq)
		ld	r1,x+
		ld	r2,x+
		ld	r3,x+
		ld	r4,x+	;prenes krok
		ld	r5,x+
		ld	r6,x+
		ld	r7,x+
		ld	r8,x+	;prenes frekvenciu
	
		sbrs	r0,0
		rjmp	mins_fr
		add	r8,r4
		adc	r7,r3
		adc	r6,r2
		adc	r5,r1	;pripocitaj 00 a3 d7 0a 1MHz
		mov	temp,r5
		cpi	temp,0x67	;je r1 = 0x67?
		breq	end_fr		;tak nevysli data max 160MHz
		st	-x,r8
		st	-x,r7
		st	-x,r6
		st	-x,r5
		lds	temp,counter	;zober z pocitadla
		inc	temp		;+1
		sts	counter,temp	;uloz naspat
		rcall	vysli
		rjmp	end_fr
mins_fr:
		sub	r8,r4
		sbc	r7,r3
		sbc	r6,r2
		sbc	r5,r1	;odpocitaj 00 a3 d7 0a 1MHz
		mov	temp,r5
		cpi	temp,0x00 ;je to 0x00?
		brne	min_dalej	;ak nie pokracuj
		mov	temp,r6
		cpi	temp,0x00	;je aj r2 0x00?
		breq	end_fr		;nevysli 0x00 0x00 0x00 0x00!!
min_dalej:	st	-x,r8
		st	-x,r7
		st	-x,r6
		st	-x,r5
		lds	temp,counter
		dec	temp
		sts	counter,temp
		rcall	vysli
end_fr:		rcall	wait2
		clt
		clr	r0
		rjmp	zas
tx_fm:
		push	acc
		push	temp
		rcall	FM_mod	;ak je 0 tak vysialaj FM
		pop	temp
		pop	acc
		clr	r0
		rjmp	zas
tx_am:
		push	acc
		push	temp
		rcall	AMM	;ak je 0 tak vysialaj FM
		pop	temp
		pop	acc
		clr	r0
		rjmp	zas

							
		
					
vysli:		ldi	temp,0x04	;dam slovo registra a vyslem ho ako prve
		rcall	SPI_transmit
		ldi	zh,high(freq+4);adresa v sram
		ldi	zl,low(freq+4)
		ldi	acc,0x04	;kolko ma byte
nx_send:	rcall	posli_sram
		rcall	io_update
;		rcall	wait200
		rcall	prepoc_fr
		rcall	line1
		rcall	line2

		ret
;------------------------------------------------------------------------
posli_sram:
		ld	temp,z+ 	;a nasledne presun do temp
		rcall	SPI_transmit
		dec	acc
		brne	posli_sram		;opakuj dokial acc=0
		ret
;------------------------------------------

;------------------------------------------------------------------------
posli:
		lpm	temp,z+ 	;a nasledne presun do temp
		rcall	SPI_transmit
		dec	acc
		brne	posli		;opakuj dokial acc=0
		ret
;------------------------------------------
SPI_Init:
; Enable SPI, Master, fck/128
		ldi temp,(1<<SPE)|(1<<MSTR)|(0<<SPR0 | 0<<SPR1);fclk/2
		out SPCR,temp
		ret

SPI_transmit:
; Start transmission of data (r16)
		out SPDR,temp
Wait_Transmit:
	; Wait for transmission complete
		sbis SPSR,SPIF
		rjmp Wait_Transmit
		ret
;-----------------------------------------------------
io_update:
;urobim impulz na prepis s buffra do registra AD9952
;pri 8MHz  trva 125ns
		sbi	portc,ioupdate
		cbi	portc,ioupdate
		ret
;-------------------------------------------------------


FM_mod:
;		brtc	WFM	;len raz zobrazim na LCD
		rcall	prenos_lcd_FM;prenes do sram FM
		rcall	line2
WFM:		
		ldi	bcc,0x00	
		ldi	xl,0xA8	;adresa v SRAM
		ldi	xh,0x00
		ldi	zh,high(freq)
		ldi	zl,low(freq)
		ldi	acc,0x04
wfm_1:		ld	r1,z+
		st	x+,r1
		dec	acc
		brne	wfm_1
		sbi	ADCSRA,ADSC;spust ad prevod

wfm_zas:	ldi	xl,0xA8	;adresa v SRAM
		ldi	xh,0x00
		clc
wfm_prev:	sbis	ADCSRA,ADIF;ak je koniec prevodu skoc
		rjmp	wfm_prev
		in	temp,ADCH;vyber hodnotu
		sbi	ADCSRA,ADSC
;		lsl	temp	;/2
		lsl	temp	;*2
		clc
		mov	acc,temp
		lsl	acc
		lsl	acc
		lsl	acc
		lsr	temp
		lsr	temp
		lsr	temp
		lsr	temp
		lsr	temp
		ld	r4,x+
		ld	r3,x+
		ld	r2,x+
		ld	r1,x
		clc
		adc	r2,acc;aj s priznakom
		adc	r3,temp;acc =0 len pre prenos scitanie
		adc	r4,bcc
;		adc	r5,acc;teraz mam pricitanu hodnotu 

		ldi	temp,0x04	;dam slovo registra a vyslem ho ako prve
		rcall	SPI_transmit
		ldi	yh,0x00          ;adresa v mem-registre prve datove slovo
		ldi	yl,0x05		;nova frekvencia
		ldi	acc,0x04	;kolko ma byte
prv_1:		ld	temp,-y
		rcall	SPI_transmit
		dec	acc
		brne	prv_1
		rcall	io_update
		set
		sbis	pinb,pb7;preskoc ak je pb7 zasa v 1... koniec X
		rjmp	WFM; rutinka-prenos do DDS trva 33.5 us pri 8MHz
		rcall	prenos_lcd_singl
		rcall	line2
		ret


AMM:
;		brtc	AM_mod	;len raz zobrazim na LCD
		rcall	prenos_lcd_AM;prenes do sram FM
		rcall	line2
		
AM_mod:			
		ldi	temp,0x04	;dam slovo registra a vyslem ho ako prve
		rcall	SPI_transmit
		ldi	zh,high(freq);poslem 8MHz
		ldi	zl,low(freq)
		ldi	acc,0x04	;kolko ma byte
		rcall	posli_sram
		rcall	io_update

		ldi	dcc,0x40; nasobok
		ldi	bcc,0x00 
		ldi	xl,0xAE	;adresa v SRAM
		ldi	xh,0x00
		ldi	zh,high(AD9952_f12*2);vystup na polovicu
		ldi	zl,low(AD9952_f12*2)
		ldi	acc,0x02
amm_1:		lpm	r1,z+
		st	x+,r1
		dec	acc
		brne	amm_1
		sbi	ADCSRA,ADSC;spust ad prevod

amm_zas:	ldi	xl,0xAE	;adresa v SRAM
		ldi	xh,0x00
amm_prev:	sbis	ADCSRA,ADIF;ak je koniec prevodu skoc
		rjmp	amm_prev
		in	temp,ADCH;vyber hodnotu
		sbi	ADCSRA,ADSC
;		clc	
;		lsl	temp	;*2
		clc
		mul	temp,dcc	;temp x 20h vysledok v r0,r1
		ld	r3,x+
		ld	r2,x
		clc
		adc	r0,r2
		adc	r1,r3;aj s priznakom


		ldi	temp,0x02	;dam slovo registra a vyslem ho ako prve
		rcall	SPI_transmit
		ldi	yh,0x00          ;adresa v mem-registre prve datove slovo
		ldi	yl,0x02		;nova frekvencia
		ldi	acc,0x02	;kolko ma byte
prv_3:		ld	temp,-y
		rcall	SPI_transmit
		dec	acc
		brne	prv_3
		rcall	io_update
		sbis	pinb,pb6	;ak je uz v 1 preskoc
		rjmp	AM_mod ; rutinka-prenos do DDS trva 33.5 us pri 8MHz
		rcall	prenos_lcd_singl
		rcall	line2
		ret

;-------------------------------------------------------
;ADPrevod
;pri 8MHz, a deleni /64 bude doba prevodu 104us(13 clk)..cca fs 9.6kHz
;citam len MSB 8 bitov....zarovnanie do lava...free runing sample
ADC_Init:
		ldi	temp,(1<< REFS1 | 1<<REFS0 | 1<<ADLAR );ref 2.56, zarovnavanie do lava
		out	ADMUX,temp
;zapnuty adc,free runing sample,fclk/64
		ldi	temp,(1<<ADEN | 1<<ADFR | 1<<ADPS2 | 1<<ADPS1)
		out	ADCSRA,temp
		ret
;------------------------
;============ pre LCD ======================
;inicializacia LCD	
LCD_init:	rcall	wait15
		cbi	LCDport_d,lcdrs	;daj RS do 0	
		ldi	temp,kom_8b
		rcall	zapis_nBF	;zapis instrukciu be cakania na BF
		rcall	wait15
		ldi	temp,kom_8b
		rcall	zapis_nBF	;opakuj 3 x
		rcall	wait15
		ldi	temp,kom_8b
		rcall	zapis_BF
		ldi	temp,kom_4b
		rcall	zapis_BF
;nastavenie rezimu modulu 2riadky, znak 5 x 7
       		ldi     temp,(kom_4b | rez_2r | fon_5x7) ; | je za OR
       		rcall   zapis_4BF
;vypnutie displeja,kurzora,blikania
       		ldi      temp,(dis_off | cur_off | blk_off)
       		rcall   zapis_4BF
;zapnutie displeja
       		ldi	temp,(dis_on | cur_off | blk_off)
       		rcall   zapis_4BF
;zmazanie displeja
       		ldi	temp,(clr_dis)
       		rcall   zapis_4BF
;nastavenie vstupneho rezimu,kurzor vpravo,DDRAM na 0
       		ldi     temp,(ddr_inc | shf_off)
       		rcall   zapis_4BF
		rcall	wait15
		ret
		
;toto je kompletna inicializacia modulu			
;*********
;posuv dat zo SRAM do LCD po riadkoch
line1:
        ldi     temp,(0x00 | ddram)
        rcall   zapis_4BF
        ldi     xh,high(srampam)	;adresa v pamati SRAM
	ldi	xl,low(srampam)
        ldi     bcc,16		;pocet znakov na riadku
li_1:   ld	temp,x+		;zober udaj zo sram potom adresu+1
	rcall	wait2
	rcall   zapis_dat
	dec	bcc
        brne	li_1	;skoc ak sa nerovna 0
	rcall	wait2
	ret
line2:
        ldi	temp,(0x40 | ddram)
        rcall   zapis_4BF
        ldi	xh,high(srampam+16)	;offset 16 znakov
	ldi	xl,low(srampam+16)
        ldi	bcc,16
li_2:   ld	temp,x+
	rcall	wait2
	rcall 	zapis_dat
        dec	bcc
        brne	li_2
        rcall	wait2
	ret
;zapis dat do LCD
zapis_dat:
       sbi	LCDport_d,lcdrs ;zapisujem data 
       rcall     zapis_4bf
       cbi      LCDport_d,lcdrs
       ret
;zapis instrukcie do LCD
zapis_BF:
	cbi		LCDport_d,lcdrw	;nuluj RS
    	out		LCDport_d,temp
        rcall   clk_e
        rcall	busy
	ret
zapis_nBF:
	cbi		LCDport_d,lcdrw	;nuluj RS
    	out		LCDport_d,temp
        rcall   clk_e
        ret

zapis_4BF:
       cbi      LCDport_d,lcdrw      ;nuluj R/W
 	in	acc,pind	;zober co je na vystupoch
       andi	acc,0b00001111	;vymaskuj
       push	temp		;uloz temp
       andi     temp,0xf0	;vymaskuj temp
       or       acc,temp        ;zluc ich
       out	LCDport_d,acc	;posli na port
       rcall    clk_e
       pop	temp
       swap	temp		;pre druhu polku dat
	in	acc,pind	;zober co je na vystupoch
       andi	acc,0b00001111	;vymaskuj
       andi     temp,0xf0	;vymaskuj temp
       or       acc,temp        ;zluc ich
       out	LCDport_d,acc	;posli na port
       rcall    clk_e
       rcall    busy
       ret	
;je modul busy
busy:
        sbi	LCDport_d,7		;nastav DB7 do 1
	nop
	cbi	ddrd,7		;nastav db7 ako vstupny
        nop
	sbi     LCDport_d,lcdrw  ;zistim ci je busy ak ho stiahne tak je ok
	nop
q1:     sbi	LCDport_b,lcde	;nastav E do 1
        nop
	cbi	LCDport_b,lcde
        nop
	sbis	pind,7 ;preskoc nasledujucu ak je 1
	rjmp	nobusy		;ak je 0 tak uz nie je busy
	sbi	LCDport_b,lcde	;nastav E do 1
        nop
	cbi	LCDport_b,lcde
       rjmp	q1
nobusy:
	sbi	ddrd,7	;nastav zasa ako vystupny
        nop
	cbi	LCDport_b,lcde
        nop
	cbi	LCDport_d,lcdrw
	ret
clk_e:
	sbi	LCDport_b,lcde      ;nastav E do 1
	nop
	cbi     LCDport_b,lcde      ;nastav E do 0
        nop
	ret
;koniec pre LCD   
;************************************************
prenos_lcd_1:
		ldi	zh,high(lcd_zac1*2)
		ldi	zl,low(lcd_zac1*2)
		ldi	bcc,16
		ldi	xh,high(srampam)
		ldi	xl,low(srampam)
prenos_zas:
		lpm	temp,z+
		st	x+,temp
		dec	bcc
		brne	prenos_zas
		ret
;-------------
prenos_lcd_singl:
		ldi	zh,high(lcd_singl*2)
		ldi	zl,low(lcd_singl*2)
		ldi	bcc,16
		ldi	xh,high(srampam+16)
		ldi	xl,low(srampam+16)
prenos_zas1:
		lpm	temp,z+
		st	x+,temp
		dec	bcc
		brne	prenos_zas1
		ret
;-------------
prenos_lcd_FM:
		ldi	zh,high(lcd_fm*2)
		ldi	zl,low(lcd_fm*2)
		ldi	bcc,16
		ldi	xh,high(srampam+16)
		ldi	xl,low(srampam+16)
prenos_zas2:
		lpm	temp,z+
		st	x+,temp
		dec	bcc
		brne	prenos_zas2
		ret
;-------------
prenos_lcd_AM:
		ldi	zh,high(lcd_am*2)
		ldi	zl,low(lcd_am*2)
		ldi	bcc,16
		ldi	xh,high(srampam+16)
		ldi	xl,low(srampam+16)
prenos_zas3:
		lpm	temp,z+
		st	x+,temp
		dec	bcc
		brne	prenos_zas3
		ret
;-------------
;*************************************
prepoc_fr:
		ldi	xh,high(counter)
		ldi	xl,low(counter)
		ld	temp,x
		ld	acc,x	;zaloha
		ldi	bcc,0x60
		mov	r12,bcc
		swap	bcc
		clr	r11

		ldi	zh,high(dec_tab*2)
		ldi	zl,low(dec_tab*2)

		andi	temp,0xf0	;len msb potrebujem
		swap	temp		;premen msb>lsb
		lsl	temp	;vynasob x2
		add	zl,temp	;ziskaj adresu
		adc	zh,r11	;pre prenos scitam s 0x00
		lpm	r9,z+
		lpm	r10,z
		andi	acc,0x0f
		add	r10,acc
		brhc	neprip	;ak je H 0 nepripocitaj 6
		adc	r9,r11
		add	r10,bcc	;pripociat 6
neprip:		mov	temp,r10
		andi	temp,0x0f	;vymaskuj
		cpi	temp,0x0A	;je < 0x0A?
		brlo	neprip_2	;ak je menej ako 0x0a netreba pripocitat
		add	r10,bcc	;pripocita 0x06
neprip_2:
		mov	temp,r10
		andi	temp,0xF0	;vymaskuj
		cpi	temp,0xA0	;nechce sa mi otacat
		brlo	neprip_3	;tak porovnava priamo
		add	r10,r12	;pripocitaj 0x60
		adc	r9,r11
neprip_3:
		clt
		ldi	xh,0x00
		ldi	xl,0x87	;adresa v ram pre LCD miesta pre MHz
		mov	temp,r9
		rcall	pr_asc	;premen na ascii kod
		mov	temp,r10
		swap	temp	;otoc
		rcall	pr_asc
		mov	temp,r10
		rcall	pr_asc
		clt
		ret
;-------------------------------
				
pr_asc:	
		brts	pr_asc_1	;ak je T preskoc 0x20 zobrazi aj 0 
		andi	temp,0x0f
		ori	temp,0x00	;je tam nula?
		brne	pr_asc_1	;ak nie premen na ascii
		ori	temp,0x20
		st	x+,temp	;uloz prazdne miesto SPACE
		clt	;vynuluj ze je prazdne miesto
		ret
pr_asc_1:	
		andi	temp,0x0f
		ori	temp,0x30	
		st	x+,temp
		set	;nastav T, je tu cislo
		ret
;*****************************************

wait:
		nop
		nop
		nop
		nop
		nop
		nop
		nop
		nop
		nop
		ret
wait2:
		ldi	yh,0x12
		ldi	yl,0xff
w_4:		nop
		sbiw	y,0x01
		brne	w_4
		ret
wait15:
		ldi	yh,0x5d
		ldi	yl,0xff
w_3:		nop
		sbiw	y,0x01
		brne	w_3
		ret		
wait200:
		ldi	bcc,0x05
w_1:		ldi	yh,0xff
		ldi	yl,0xff
w_2:		nop
		sbiw	y,0x01
		brne	w_2
		dec	bcc;
		brne	w_1
;		dec	gcc
		ret

;data pre AD9952_nastavenia
;			.org 0x0200
ad9952_0:
		.db 0x02,0x00,0x02,0x42 ;adresa 0x00 bity 0-7,osk enabled
ad9952_1:
		.db 0x00,0x00,0xA4,0x00 ;adresa 0x01 bity 16-0
ad9952_2:
		.db 0x3f,0xff ;adresa 0x02 bity 7-0 asf amplituda full
ad9952_3:		
		.db 0x00,0x00 ;adresa 0x03 bity 7-0   ARR register
ad9952_4:		
		.db 0x03,0x33,0x33,0x34 ;adresa 0x04 bity 0-31 freq.register
ad9952_5:		
		.db 0x00,0x00 ;adresa 0x05 bity 15-0	 POW register
ad9952_f2:
		.db 0x00,0xa3,0xd7,0x0a;1MHz
ad9952_f3:
		.db 0x09,0x99,0x99,0x9A;15MHz
ad9952_f4:
		.db 0x0C,0xCC,0xCC,0xCD;20MHz
ad9952_f5:
		.db 0x2C,0xCC,0xCC,0xCD;70MHz
ad9952_f6:
		.db 0x05,0x1E,0xB8,0x52;8MHz
ad9952_f7:
		.db 0x45,0x1E,0xB8,0x52;108MHz 
ad9952_f8:
		.db 0x5C,0xCB,0xFB,0x16;145MHz
ad9952_f12:
		.db 0x01,0xFF ;adresa 0x02 bity 7-0 asf 1000 0000 0000 00..polovica 320mV amplituda
ad9952_f13:
		.db 0x10,0x00 ;adresa 0x02 bity 7-0 asf 1000 0000 0000 00..stvrtina 160mV
ad9952_f14:
		.db 0x3f,0xff ;adresa 0x02 bity 7-0 asf 1000 0000 0000 00..full 640mV
		
lcd_zac1:
		.db "Fr:  1.000000MHz"
lcd_AM:		.db "  AM modulacia  "
lcd_FM:		.db "  FM modulacia  "
lcd_singl:	.db "  Single freq   "

dec_tab:
		.db	0x00,0x00,0x00,0x16,0x00,0x32,0x00,0x48,0x00,0x64,0x00,0x80
		.db	0x00,0x96,0x01,0x12,0x01,0x28,0x01,0x44,0x01,0x60	
