#include <avr/io.h>
#include <util/delay.h>

#define testport PORTB0


typedef struct                                 // Deklaration einer Struktur vom Datentyp RTC
{
	unsigned char second;             // struct member second 0...59
	unsigned char minute;             // struct member minute 0...59
	unsigned char hour;               // struct member hour 0...24
	unsigned char day;                // struct member monthDay 1...31
	unsigned char month;              // struct member month 1...12
	unsigned int year;                // struct member year
}RTC;                                          // Datatype of this structure = RTC

/*** Funktion Schaltjahr berechnen. (Parameterübergabe call by value) ***/
int check_leapyear (int year)
{
	if ( (year % 4 == 0 && year % 100 != 0) || (year % 400 == 0) )
	return 29;
	else
	return 28;
}

RTC time, date;                                // Deklaration der Variablen time und date vom Datentyp RTC
unsigned char days_february;

int main(void)
{
	time.second         = 0;         // Initialisierungswert = 0
	time.minute         = 0;         // Initialisierungswert = 0
	time.hour           = 0;         // Initialisierungswert = 0
	date.day            = 1;         // Initialisierungswert = 1 (1 = Montag)
	date.month          = 1;         // Initialisierungswert = 1 (1 = Jänner)
	date.year           = 2016;             // Initialisierungswert = 2014
	
	while(1)
	{
		//_delay_ms(1000);  // Simuliere einen Sekundentakt
		
		if (time.second <= 5)
		time.second ++;
		if (time.second == 6)
		{
			time.second = 0;
			time.minute ++;
		}
		
		if (time.minute == 6)
		{
			time.minute = 0;
			time.hour ++;
		}
		
		if (time.hour == 24)
		{
			time.hour = 0;
			date.day ++;
		}
		
		
		days_february = check_leapyear(date.year);    // Parameterübergabe = Strukturelement year
	}
}