Sunteți pe pagina 1din 3

//4.Calculati si transmiteti pe seriala in formatul XX.

XX secunde timpul de la u
ltima apasare a butonului reset de pe placa.
#include<iom16.h>
#include<inavr.h>
#include "usart.h"
#include "print.h"
#include "crc.h"
__no_init unsigned int Timer1_currentValue;
__no_init unsigned int Timer1_numberOverflows;
__no_init unsigned int j;
#pragma vector = TIMER1_OVF_vect
__interrupt void T1_OVF()
{
Timer1_numberOverflows++;
}
void print(unsigned long period)
{
unsigned int nr=period;
unsigned char sir[15] ;
int index = 0;
while(nr)
{
sir[index++] = nr%10 + '0';
nr/=10;
}
int i;
if(index == 2)
{
USART_transmit('0');
USART_transmit(',');
USART_transmit(sir[1]);
USART_transmit(sir[0]);
}
else
{
if(index == 3)
{
USART_transmit('0');
USART_transmit(',');
USART_transmit(sir[2]);
USART_transmit(sir[1]);
}
else
{
for(i=index-1;i>0;--i)
{
if(i==2)
{
USART_transmit(',');

}
USART_transmit(sir[i]);
}
}
}

USART_transmit('s');
USART_transmit(0x0d);
}
void main( void )
{
/*iniializare usart*/
USART_initialize(BAUD_RATE);
/*iniializare Timer 1*/
/*Mod de funcionare Normal*/
/*Setare prescaler */
TCCR1B|=(1<<CS10);
/*Activare ntrerupere*/
TIMSK|=(1<<TOIE1);
__enable_interrupt();
TCNT1=0;
if( MCUCSR & (1<<EXTRF) )
{
unsigned long perioada = Timer1_currentValue + Timer1_numberOverflows * 6553
5;
perioada*=0.00025;
//USART_transmit('a');
Timer1_numberOverflows = 0;
Timer1_currentValue = 0;
//myPrint(1,10,(void*)&perioada);
print(perioada);

while(1)
{
Timer1_currentValue = TCNT1;
}
}