Exemplo n.º 1
0
int main(void)
{
	unsigned char k;
	init();
	Buffer_USART_Tx_String("End Init \r");
	while(1)
	{		
		if(Need_Receiving==ON)
		{
			if( ((PINC)&(1<<PINC0))==0 )
			{
				if(Receiving==OFF && Compteur_Data_Received!=10)
				{
					Receiving = ON;	// indique que la récéption est en cour
					Compteur_Timer = 0;
					TIMER0_START();	// Lance le timer0 
				}
				else asm("nop");
			}
			else asm("nop");	
			Need_Receiving=OFF;	
		}
		if(RX600INTREQUEST==ON)
		{
			Received_600_baud(); // permet de gérer le nombre d'incrémentation du timer 0 en mode de réception de donnée
			RX600INTREQUEST=OFF;
		}
		if(TX600INTREQUEST==ON)
		{
			Send_600_baud(); // permet de gérer le nombre d'incrémentation du timer 0 en mode d'envoi de donnée
			TX600INTREQUEST=OFF;
		}
		if(Compteur_Data_Received != 0) 
		{
			putchar_Buffer(Data_Received[0]);
			for(k=0;k<=10;k++) 
			{
				Data_Received[k]=Data_Received[k+1];
			}
			Data_Received[10]=0x00;
			Compteur_Data_Received--;
		}
		if (Rx_Counter != 0 && Sending == 0)
		{
			c = getchar_Buffer ();
			chartobit (c, tableau);
			
			Sending = ON;
			TCNT2 = 0;

			OCR1A = valeurf2;
			TIMER2_START();
			Index = 0;
			cbiBF (PORTB, PINB0);
		}
	}
}
Exemplo n.º 2
0
uint16_t hcsr04_read(void)
{
    uint16_t t;

    TRIG = 1;
    DELAY_US(10);
    TRIG = 0;

    TIMER0_INIT16();
    TIMER0_START();

    while (!ECHO);
    t = timer0_get16();

    while (ECHO);
    t = timer0_get16() - t;

    return t;
}
Exemplo n.º 3
0
void main(void) {
    welcome();

    {
        unsigned int t0, t1;
        TIMER0_INIT16();
        TIMER0_SET16(0);
        TIMER0_START();

        delay_ms(100);

        t0 = TIMER0_GET16();
        DELAY_US(10000);
        t1 = TIMER0_GET16();

        UARTUINT(t1 - t0);
        UARTCHAR('\n');

        delay_ms(100);
        
        t0 = TIMER0_GET16();
        delay_ms(10);
        t1 = TIMER0_GET16();

        UARTUINT(t1 - t0);
        UARTCHAR('\n');

        delay_ms(100);
        
        t0 = TIMER0_GET16();
        delay_ms(50);
        t1 = TIMER0_GET16();

        UARTUINT(t1 - t0);
        UARTCHAR('\n');
    }

    {
        unsigned long t0, t1;
        TIMER0_INIT32();
        TIMER0_SET32(0);
        TIMER0_START();

        delay_ms(100);

        t0 = TIMER0_GET32();
        DELAY_US(10000);
        t1 = TIMER0_GET32();

        UARTUINT((t1 - t0) >> 16);
        UARTCHAR(' ');
        UARTUINT(t1 - t0);
        UARTCHAR('\n');

        delay_ms(100);
        
        t0 = TIMER0_GET32();
        delay_ms(10);
        t1 = TIMER0_GET32();

        UARTUINT((t1 - t0) >> 16);
        UARTCHAR(' ');
        UARTUINT(t1 - t0);
        UARTCHAR('\n');
    }

    {
        unsigned long t0, t1, t2;

        ET0 = 0;
        t0 = TIMER0_GET32();
        TF0 = 1;
        t1 = TIMER0_GET32();

        UARTCHAR(TF0 ? '1' : '0');
        UARTCHAR('\n');

        ET0 = 1;
        t2 = TIMER0_GET32();

        UARTUINT(t0 >> 16);
        UARTCHAR('.');
        UARTUINT(t0);
        UARTCHAR(' ');
        UARTUINT(t1 >> 16);
        UARTCHAR('.');
        UARTUINT(t1);
        UARTCHAR('\n ');

        UARTCHAR(TF0 ? '1' : '0');
        UARTCHAR('\n');

        UARTUINT(t2 >> 16);
        UARTCHAR('.');
        UARTUINT(t2);
        UARTCHAR('\n ');
    }

    while (1);
}