#include <avr/io.h>							// Hlavickovy soubor popisujici microcontroler
#include <avr/interrupt.h>						// Soubor popisujici preruseni microcontroleru
#include <stdio.h>
#include <util/delay.h>	
#include "Transceiver.h"
#include "lcd_h.h"

#define F_CPU 16000000UL




int main (void){

	extern volatile N_ROTE_paket Paket_in;
	extern unsigned char ID_RX, my_ID;
	extern volatile unsigned char Receiv_int;
	
	MCUCR |= (1<<ISC11);						//nastaveni preruseni INT1 na tlacitko
	GICR |= (1<<INT1);

	Receiv_int = 0;							//nastaveni neprijatych dat

	lcd_init();							//inicializace lcd
	lcd_clrscr();							//smazani lcd
	Init_Transceiver();						//inicializace transceiveru

	Send_paket();							//odeslani zkusebniho prazdneho paketu

	ID_RX = 0xB0;							//nastaveni adresy prijimace
	my_ID = 0xA0;							//nastaveni vlastni adresy

	sei();								//povoleni preruseni
	while(1)
	{

		if(Receiv_int == 1)					//podminka prijatych dat
		{
			lcd_clrscr();					//smazani lcd
			lcd_gotoxy(0,0);				//nastaveni kurzoru do nuly	
			lcd_putc(Paket_in.Data_buf[1]);			//vypsani datoveho paketu
			lcd_putc(Paket_in.Data_buf[2]);
			lcd_putc(Paket_in.Data_buf[3]);
			lcd_putc(Paket_in.Data_buf[4]);
			lcd_putc(Paket_in.Data_buf[5]);
			lcd_putc(Paket_in.Data_buf[6]);
			lcd_putc(Paket_in.Data_buf[7]);
			lcd_putc(Paket_in.Data_buf[8]);
			lcd_putc(Paket_in.Data_buf[9]);
			lcd_putc(Paket_in.Data_buf[10]);
			Receiv_int = 0;					//nastaveni prazdnych dat
			REC_on;						//povoleni preruceni
		}	
	}

}

ISR(INT1_vect)
{
	extern volatile N_ROTE_paket Paket_out, Paket_in;

	LED_1;								//aktivace led
	delay(65000);
	delay(65000);
	sprintf(Paket_out.Data_buf,"Hello!!!:)");			//zapis dat do vysilaciho bufferu
	Send_paket();							//odeslani paketu
	
	delay(65000);
	delay(65000);
	LED_0;								//deaktivace led

}
