
#include "opora.h"
#include "config.h"
#include "LCD.h"
#include "LCD_b.h"

DataStructTypeDef	Data={0,0,0,0};

int main()
{
	ClockCfg();
	Timer1Cfg();	
	LCDInit();
	NVIC_EnableIRQ(TIMER1_IRQn);

	PrintConstText("Timer 00:00:00",0,0,0);
	while(1)
	{
		if(Data.Refresh==1)
		{	
			Data.Refresh=0;
			if(Data.Hours<10)	PrintText("0%:",Data.Hours,0,36,0,dec);
			else				PrintText("%:",Data.Hours,0,36,0,dec);
			if(Data.Minutes<10)	PrintText("0%:",Data.Minutes,0,54,0,dec);
			else				PrintText("%:",Data.Minutes,0,54,0,dec);
			if(Data.Seconds<10)	PrintText("0%",Data.Seconds,0,72,0,dec);
			else				PrintText("%",Data.Seconds,0,72,0,dec);
		}
	}
}

void TIMER1_Handler()
{
	Data.Refresh=1;
	TIMER1->STATUS&=0xFFFD;	//сброс события прерывания
	if(++Data.Seconds==60)
	{
		Data.Seconds=0;
		if(++Data.Minutes==60)
		{
			Data.Minutes=0;
			if(++Data.Hours==24) Data.Hours=0;
		}
	}
}
