예제 #1
0
// main
int main(void)
{
    USART_init();
    DDRD = LED_MASK;
    char buf;
    char tmp[] = "blubjes\r\n";
    unsigned int l1 = 0;
    unsigned int l2 = 0;
    unsigned int l3 = 0;
    for (;;) {
        buf = USART_receive();
        l1++;
        l2++;
        l3++;
        if (l1 >= 20)
        {
            PORTD ^= (1 << 5);
            l1 = 0;
        }
        if (l2 >= 10)
        {
            PORTD ^= (1 << 6);
            l2 = 0;
        }
        if (l3 >= 5)
        {
            PORTD ^= (1 << 7);
            l3 = 0;
        }
        USART_putstring(tmp);
    }
    return 0;
}
예제 #2
0
unsigned char * receiveString(){

unsigned char * result;


int i = 0;
while(1) {


	unsigned char dataread = USART_receive();

	result[i] =  dataread;


	if(dataread == 10) {

		//USART_putstring(String);
		break;

	}


	i ++;



}

result[i] = '\0'; 

return result;

}
예제 #3
0
static uint8_t are_sides_stored(void)
{
  static uint8_t ct = 0;
ct++;
    uint8_t i, k, res, st;

    res = 0;
    for (k = 0; k < 2; k++)
    {
//res = 0;
        for (i = 0; i < /*SIDE_CB*/ 2; i++)
        {
            if ((res & _BV(i)) == 0)
            { // Confirmation not received yet
                DISABLE_GLOBAL_INTERRUPTS;
//_delay_ms(10);
                send_no_data_command(GET_MCU_ADDRESS_FROM_SIDE_NUM(i), USART_STORE_CONFIRM);
//_delay_ms(10);
                st = USART_receive(100000 /*TODO 1 million is equal ~1 sec */);
                if (st == USART_STATE_STORED)
                    res |= _BV(i);

                ENABLE_GLOBAL_INTERRUPTS;
            }
        }
        if (res == /*0x7F*/0x3)
        {
            //USART_transmit(0, 0x5A);
            send_side_colors(1, colors_2);
            
            return TRUE;
        }
        _delay_ms(100);
            send_side_colors(0, colors_1);
    }
            send_side_colors(0, colors_1);
//            USART_transmit(0, 0xb4);
            //USART_transmit(0, (ct << 4) + k);
//            USART_transmit(0, 0xB4);
    return FALSE;
}
/////////////////////////////////////////////////////////////////////////////////
// function definitions
int user_waypoint_test (WayPoint wps[],int numwps) {
	int i;
	int uj = numwps + 1;
	int uloop1 = 1;
	int userchk1;
	int userchk2;

	float ulat;
	float ulon;
	float ulat_d;
	float ulat_dist;
	float ulon_dist;
	float ulon_d;
		
	char entwp[3];
	char *ptr_entwp = entwp;
	
	char entlat[ULAT_TYPE];
	char *ptr_entlat = entlat;
	char entlat_dist[ULAT_TYPE];
	char *ptr_entlat_dist = entlat_dist;
	char entlon[ULONG_TYPE];
	char *ptr_entlon = entlon;
	char entlon_dist[ULONG_TYPE];
	char *ptr_entlon_dist = entlon_dist;
	char entlon_d[ULONG_TYPE];
	char *ptr_e_d = entlon_d;
	
	char yes[3] = "y";
	char *ptr_yes = yes;
	char no[3] = "n";
	char *ptr_no = no;
	
	char *ptr_1 = "Please enter Latitude ";
	char *ptr_2 = ":";
	char *ptr_3 = "Please enter Longitude ";
	char *ptr_4 = "Would you like to enter another way point? (y or n):";
	char *ptr_6 = "Finished entering way points";
	char *ptr_7 = "Invalid, please try again";
	char *ptr_8 = " ";
	
	// user enter first lat
	USART_putstring(USART_PC,"\n\r"); debug_print(ptr_1); debug_printi(uj); debug_print(ptr_2);USART_putstring(USART_PC,"\n\r");
	for (i = 0; i < UENTLAT; i++) {
		entlat[i] = USART_receive(USART_PC);
	}
	/*entlat_dist[0]=entlat[0];
	entlat_dist[1]=entlat[1];
	entlat_dist[2]=entlat[3];
	entlat_dist[3]=entlat[4];
	entlat_dist[4]=entlat[5];
	entlat_dist[5]=entlat[6];
	entlat_dist[6]=entlat[7];
	entlat_dist[7]=0x00;*/
	
	ulat = atof (ptr_entlat);
	//ulat_dist = atof (ptr_entlat_dist);
	ulat_d = ulat;

	debug_printf(ulat);debug_print(ptr_8);debug_printf(ulat_d);
	wps[numwps].latitude = ulat;
	//wps[numwps].latitude_dist = ulat_dist;
	wps[numwps].latitude_deg = ulat_d;
	
	// user enter first long
	USART_putstring(USART_PC,"\n\r"); debug_print(ptr_3); debug_printi(uj); debug_print(ptr_2);USART_putstring(USART_PC,"\n\r");
	for (i = 0; i < UENTLON; i++) {
		entlon[i] = USART_receive(USART_PC);
	}
	/*entlon_dist[0]=entlon[0];
	entlon_dist[1]=entlon[1];
	entlon_dist[2]=entlon[2];
	entlon_dist[3]=entlon[4];
	entlon_dist[4]=entlon[5];
	entlon_dist[5]=entlon[6];
	entlon_dist[6]=entlon[7];
	entlon_dist[7]=entlon[8];
	entlon_dist[8]=0x00;*/
	
	entlon_d[0]=entlon[1];
	entlon_d[1]=entlon[2];
	entlon_d[2]=entlon[3];
	entlon_d[3]=entlon[4];
	entlon_d[4]=entlon[5];
	entlon_d[5]=entlon[6];
	entlon_d[6]=entlon[7];
	entlon_d[7]=entlon[8];
	entlon_d[8]=0x00;
		
	ulon = atof (ptr_entlon);
	//ulon_dist = atof (ptr_entlon_dist);
	ulon_d = atof (ptr_e_d);
	
	debug_printf(ulon);debug_print(ptr_8);debug_printf(ulon_d);
	wps[numwps].longitude = ulon;
	//wps[numwps].longitude_dist = ulon_dist;
	wps[numwps].longitude_deg = ulon_d;
	//-----------------------------------------------------------
	
	numwps = numwps + 1;
	
	// prompt if user wants to enter another way point
	USART_putstring(USART_PC,"\n\r"); debug_println(ptr_4);
	for (i = 0; i < 1; i++) {
		entwp[i] = USART_receive(USART_PC);
	}
	entwp[1]=0x00;
	debug_println(ptr_entwp);

	while (uloop1 == 1) {
		
		userchk1 = strcmp(ptr_entwp,ptr_yes);
		userchk2 = strcmp(ptr_entwp,ptr_no);
		
		if(userchk1 == 0) {
			numwps = userwaypoint(wps,numwps);
			USART_putstring(USART_PC,"\n\r");debug_println(ptr_4);
			for (i = 0; i < 1; i++) {
				entwp[i] = USART_receive(USART_PC);
			}
			debug_println(ptr_entwp);
		}
		else if (userchk2 == 0) {
			debug_println(ptr_6);
			uloop1 = 0;
		}
		else {
			debug_println(ptr_7); USART_putstring(USART_PC,"\n\r");debug_println(ptr_4);
			for (i = 0; i < 1; i++) {
				entwp[i] = USART_receive(USART_PC);
			}
			debug_println(ptr_entwp);
		}
	}
return(numwps);
}
int userwaypoint(WayPoint wps[],int nwps) {
	int i = nwps;
	int j;
	int k;

	float uulat;
	float uulat_dist;
	float uulat_d;
	float uulon;
	float uulon_dist;
	float uulon_d;
	
	char entlat[ULAT_TYPE];
	char *ptr_entlat = entlat;
	char entlat_dist[ULAT_TYPE];
	char *ptr_entlat_dist = entlat_dist;
	char entlon[ULONG_TYPE];
	char *ptr_entlon = entlon;
	char entlon_dist[ULONG_TYPE];
	char *ptr_entlon_dist = entlon_dist;
	char entlon_d[ULONG_TYPE];
	char *ptr_e_d = entlon_d;
	
	char *ptr_1 = "Please enter Latitude ";
	char *ptr_2 = ":";
	char *ptr_3 = "Please enter Longitude ";
	char *ptr_4 = " ";
	
	j = i + 1;
	
	USART_putstring(USART_PC,"\n\r"); debug_print(ptr_1); debug_printi(j); debug_print(ptr_2);USART_putstring(USART_PC,"\n\r");
	for (k = 0; k < UENTLAT; k++) {
		entlat[k] = USART_receive(USART_PC);
	}
	//-----------------------------------------------------------
	/*entlat_dist[0]=entlat[0];
	entlat_dist[1]=entlat[1];
	entlat_dist[2]=entlat[3];
	entlat_dist[3]=entlat[4];
	entlat_dist[4]=entlat[5];
	entlat_dist[5]=entlat[6];
	entlat_dist[6]=entlat[7];
	entlat_dist[7]=0x00;*/
	
	uulat = atof (ptr_entlat);
	//uulat_dist = atof (ptr_entlat_dist);
	uulat_d = uulat;
	
	debug_printf(uulat);debug_print(ptr_4);debug_printf(uulat_d);
	wps[i].latitude = uulat;	
	//wps[i].latitude_dist = uulat_dist;
	wps[i].latitude_deg = uulat;
	//-----------------------------------------------------------
		
	USART_putstring(USART_PC,"\n\r"); debug_print(ptr_3); debug_printi(j); debug_print(ptr_2);USART_putstring(USART_PC,"\n\r");
	for (k = 0; k < UENTLON; k++) {
		entlon[k] = USART_receive(USART_PC);
	}
	//-----------------------------------------------------------
	/*entlon_dist[0]=entlon[0];
	entlon_dist[1]=entlon[1];
	entlon_dist[2]=entlon[2];
	entlon_dist[3]=entlon[4];
	entlon_dist[4]=entlon[5];
	entlon_dist[5]=entlon[6];
	entlon_dist[6]=entlon[7];
	entlon_dist[7]=entlon[8];
	entlon_dist[8]=0x00;*/
	
	entlon_d[0]=entlon[1];
	entlon_d[1]=entlon[2];
	entlon_d[2]=entlon[3];
	entlon_d[3]=entlon[4];
	entlon_d[4]=entlon[5];
	entlon_d[5]=entlon[6];
	entlon_d[6]=entlon[7];
	entlon_d[7]=entlon[8];
	entlon_d[8]=0x00;
		
	uulon = atof (ptr_entlon);
	//uulon_dist = atof (ptr_entlon_dist);
	uulon_d = atof (ptr_e_d);
	
	debug_printf(uulon);debug_print(ptr_4);debug_printf(uulon_d);
	wps[i].longitude = uulon;
	//wps[i].longitude_dist = uulon_dist;
	wps[i].longitude_deg = uulon_d;
	//-----------------------------------------------------------
	i = i + 1;

return(i);
}