int main(void)
{
	stdout = &mystdout;
	general_init();
	UART_INIT();
	PWM_Init();
	ADC_Init();
	
	_delay_ms(250);
	Interrupt_Init();
	
	//beep();
	printf("Initialization Complete\n");
	
	for(;;){
		if(Serial_Finish){
			serialDecodify();
			
			actuateMotors();
			//sonarRead();
			//if( (sonarReading0 < 1000) | (sonarReading1 < 1000) | (sonarReading2 < 1000)) sonarReading0 = sonarReading1 = sonarReading2 = 1000;
			//printf("%u%u%u", sonarReading0, sonarReading1, sonarReading2);		//might get an error here because needs interrupts to send data through UART
			ledCounter--;
			if(!ledCounter){
				toggle_leds();
				ledCounter = 5;
			}
		}
	}
}
Exemple #2
0
int
main(int argc, char* argv[])
{
  // At this stage the system clock should have already been configured
  // at high speed.
  GPIO_InitTypeDef GPIO_InitStruct;

  //Initialize the System
  SystemInit();

  RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOC,ENABLE);

  //SET GPIOC To Ouptut Port
  GPIO_InitStruct.GPIO_Mode = GPIO_Mode_Out_PP;
  GPIO_InitStruct.GPIO_Pin = GPIO_Pin_4;
  GPIO_InitStruct.GPIO_Speed = GPIO_Speed_50MHz;
  GPIO_Init(GPIOC, &GPIO_InitStruct);

  //SET GPIOD To Input Port
  GPIO_InitStruct.GPIO_Mode = GPIO_Mode_IN_FLOATING;
    GPIO_InitStruct.GPIO_Pin = GPIO_Pin_3;
    GPIO_InitStruct.GPIO_Speed = GPIO_Speed_50MHz;
    GPIO_Init(GPIOD, &GPIO_InitStruct);

    Interrupt_Init();
    EXTI_GenerateSWInterrupt(EXTI_Line3);
  // Infinite loop
  while (1)
    {
       // Add your code here.
    }
}
Exemple #3
0
void main(void) {
    // initialize board
    Sys_Init();
    putchar(' '); //the quotes in this line may not format correctly
    Port_Init();
    PCA_Init();
    SMB_Init();
    Interrupt_Init();
    printf("Starting\n\r");

    //print beginning message
    printf("Embedded Control Drive Motor Control\r\n");
    // Initialize motor in neutral and wait for 1 second
    MOTOR_PW = PW_NEUT;
	motorPW = 0xFFFF-MOTOR_PW;
    PCA0CPL2 = motorPW;
    PCA0CPH2 = motorPW>>8;
	printf("Pulse Width = %d\r\n",MOTOR_PW);
    c = 0;
    while (c < 50);								//wait 1 second in neutral
	printf("end wait \r\n");
    
    
    
    //Main Functionality
    while (1) {
        if (!SS1) { // If the slide switch is active, set PW to center
            PW = PWCENTER;
            PCA0CP0 = 0xFFFF - PW; // Update comparator with new PW value
            while (!SS1); // Wait...
        } else if (take_heading) { // Otherwise take a new heading
            reading = Read_Compass(); // Get current heading
            printf("%d\n\r", reading);
            Steering_Servo(reading); // Change PW based on current heading
            PCA0CP0 = 0xFFFF - PW; // Update comparator with new PW value
        }


        if (getRange) {
            getRange = 0; // Reset 80 ms flag
            range_val = read_ranger(); // Read the distance from the ranger
            printf("Range:			%d cm \r\n", range_val);
            printf("Pulse Width:	%d \r\n", MOTOR_PW);

            // Start a new ping
            Data[0] = 0x51; // write 0x51 to reg 0 of the ranger:
            i2c_write_data(addr, 0, Data, 1); // write one byte of data to reg 0 at addr
        }

        if (SS0) Drive_Motor(range_val);
        else Drive_Motor(45); // Hold the motor in neutral if the slide switch is off
    }
}
int main(void)
{
	
		//initialize the GPIO ports	
		PortFunctionInit();
		
	//configure the GPIOF interrupt
		Interrupt_Init();
	
    //
    // Loop forever.
    //
    while(1)
    {

    }
}
//******************************************************************************************
//main program function
//******************************************************************************************
void main(void) {
	Sys_Init();      			// System Initialization
	Port_Init();     			// Initialize ports 2 and 3
	Interrupt_Init();			//Initialize Interrupts
	Timer_Init();				//Initialize timer 0
	putchar(' ');    		
	printf("\r\nStart\r\n");
	while(1) {	
		BILED0=1;	//Turn OFF the BILED
		BILED1=1;
		printf("\rHow To Play:\r\nIf Red Led is on the player must Push button 0\r\nIf Green Led is on the player must Push button 1\r\nIf both Leds are on the player must push both Buttons\r\nKeep in mind you will only have 1 sec push the corresponding button/s\r\nA correct input will make the Clear Led flash green, while an incorrect input will make it flash red\r\nTo begin press any key\r\n");	

		keyinput=getchar();
		
		previousnum=keyinput%3;
		i=0;
		numC=0;
		while (i<=9) {
			StopAndResetTimer();
			if(!SS) {
				StartTimer();
				randomnum = random();					//create a random number. where randomnum is a 
				while (randomnum==previousnum) {
					randomnum = random();
				}							//check to see if the random number was used before
	
				if (randomnum==0) {						
					LED0=0;					//turn it on
					debounce(); 			
					LED0=1; 				//turn it off
					if (PB0==0 && PB1==1) {
						correct();		//store correct answer;
					} else {
						incorrect();
					}
				} else if (randomnum==1) {						
					LED1=0; 				//turn it on
					debounce(); 			
					LED1=1; 				//turn it off
					if (PB0==1 && PB1==0) {
						correct();
					} else {
						incorrect();
					}	
				} else{						//rand num is 2, light LED0 and LED1 for 1 second
					LED0=0;
					LED1=0;
					debounce();
					LED0=1;
					LED1=1;
					if (PB0==0 && PB1==0){
						correct();
					} else 	{
						incorrect();
					}
				}
				
				previousnum=randomnum;
				i++;									//increment i
			} else 	{
				PauseTimer();
			}

		}// end while < 9
		printf("\r\n Number of correct answers = %d\r\n", numC);		//display results
		ending();
		TR0 = 0;								//turn off timer
		BILED1=1;
		BILED0=1;
		while (!SS);							//wait until the switch is turned off and back on again to loop
		while (SS);								
	}	
}//end main
//-----------------------------------------------------------------------------
// Main Function
//-----------------------------------------------------------------------------
void main(void)
{
  desired_range = 150;
  // initialize board
  Sys_Init();
  putchar(' '); //the quotes in this line may not format correctly
  PCA_Init();
  ADC_Init();
  Interrupt_Init();
  Port_Init();
  XBR0_Init();
  SMB_Init();
  putchar('\r');

  //print beginning message
  printf("En taro Adun, Executor!\r\n");

  // set the PCA output to a neutral setting
  steering_neutral();
  ranger_neutral();

  wait();                                       /* Let stuff warm up */

  // Get the PD constants and target heading from the keypad
  compass_kp              = read_gain()/10.;
  desired_heading         = read_heading();
  compass_kd              = read_gain_high();

  ranger_kp		           = read_gain_thrust()/10.;
  ranger_kd		           = read_gain_thrust_high();

  //Write the settings to the record
  printf ( "Compass KP = %d, Compass KD = %d, Desired Heading = %d, Ranger KP = %d, Ranger KD = %d, Desired Range = %d\r\n", 
      compass_kp,
      compass_kd, 
      desired_heading, 
      ranger_kp, 
      ranger_kd, 
      desired_range );

  printf ( "Time, heading, range\r\n ");

  PCA0CPL1 =   0xFFFF - 3200;
  PCA0CPH1 = ( 0xFFFF - 3200 ) >> 8 ;

  // Start at time 0.
  time = 0;

  while(1)                                      /* Infinite loop is go */
  {	
    if ( nCounts == 50 )
    {
      // Update the LCD loop
      lcd_clear();
      lcd_print( "Batt level: %d\n", get_battery_voltage() );
      lcd_print("Heading :%d\n", heading/10);
      lcd_print("Alt: %d", range );
      if (SS)
        lcd_print("PAUSED\n");
      else
        lcd_print("\n");
      lcd_print("# forHead, * forGain");
      
      }
    if ( read_keypad() != -1 )
    {
      // Check the keypad
      pause();
      if ( getKey() == '#' )
      {
        // If # was pressed, get a new heading
        steering_neutral();
        ranger_neutral();				
        desired_heading = read_heading();
        time = 0;
        printf ( "Compass KP = %d, Compass KD = %d, Desired Heading = %d, Ranger KP = %d, Ranger KD = %d, Desired Range = %d\r\n", 
            compass_kp,
            compass_kd, 
            desired_heading, 
            ranger_kp, 
            ranger_kd, 
            desired_range );

        printf ( "Time, heading, range\r\n ");
      }
      else if( getKey() == '*' )
      {
        // If * was pressed, get new gain contants
        steering_neutral();
        ranger_neutral();	
        compass_kp = read_gain()/10.;
        compass_kd = read_gain_high();
        ranger_kp  = read_gain_thrust()/10.;
        ranger_kd  = read_gain_thrust_high();
        time = 0;
        printf ( "Compass KP = %d, Compass KD = %d, Desired Heading = %d, Ranger KP = %d, Ranger KD = %d, Desired Range = %d\r\n", 
            compass_kp,
            compass_kd, 
            desired_heading, 
            ranger_kp, 
            ranger_kd, 
            desired_range );

        printf ( "Time, heading, range\r\n ");
      }
    }
    else
      pause();
    if(SS)			//while the SS is off
    {
      //printf("The slide switch is OFF \r\n");
      steering_neutral();
      ranger_neutral();
    }
    if(!SS)		//SS is On
    {
      //printf("The Slide switch is On \r\n");
      if ( new_heading )
        printf("%lu,%d,%d\r\n",
            time,
            compass_old_error, 
            ranger_old_error );
      if (new_heading)    //wait for 40ms
      {	
        heading=read_compass();
        //printf("The heading result is %d\r\n", heading);
        new_heading=0;
        Steering_Servo(  );
      }
      if (new_range)
      {
        ReadRanger(  );
        Speed_Cont(  );		//adjust motor speed
        new_range=0;		//reset ranger flag
      }
    }	
  }
}
void main(void)
{
	Sys_Init();      			// System Initialization
	Port_Init();     			// Initialize ports 2 and 3
	Interrupt_Init();			//Initialize Interrupts
	Timer_Init();				//Initialize timer 0
	putchar(' ');    			// the quote fonts may not copy correctly into SiLabs IDE


		
 		BILED0=0;	//Turn OFF the BILED
		BILED1=0;
		printf("\r\nStart");
		while(1)	
		{	

			printf("\r\n\n Press any key to begin");	//get a number to randomize the random number even more
			keyinput=getchar();
			
			previous_num=keyinput%3;
			
			
			printf("\r\n This game will light 1 or both leds. Press the corresponding button to win.");	
			while (i<=9)
			{
					if(!SS)
					{
						TR0 = 1;			//start timer0
						TL0 = 0;			//clear low bits
						TH0 = 0;			//clear high bits
						Counts = 0;			//set the counts to 0
					random_num = random();					//create a random number. where random_num is a 
					while (random_num==previous_num)
					{
						random_num = random();
					}							//check to see if the random number was used before
					
						if (random_num==0)
						{						//light LED0 for 1 second
							Counts=0;
							LED0=0;					//turn it on
							while (Counts<338); 			//wait 1 second
							LED0=1; 				//turn it off
							if (PB1==0 && PB2==1)
							{
								correct_answer();		//store correct answer;
							}
							else
							{
								incorrect_answer();
							}
						}
						else if (random_num==1)
						{						//light LED1 for 1 second
							Counts=0;
							LED1=0; 				//turn it on
							while (Counts<338); 			//wait 1 second
							LED1=1; 				//turn it off
							if (PB1==1 && PB2==0)
							{
								correct_answer();
							}
							else
							{
								incorrect_answer();
							}	
						}
						else 						//this means that the random number is 2
						{						//light LED0 and LED1 for 1 second
							Counts=0;
							LED0=0;
							LED1=0;
							
							while (Counts<338);
							LED0=1;
							LED1=1;
							if (PB1==0 && PB2==0)
							{
								correct_answer();
							}
							else
							{
								incorrect_answer();
							}
						}
						

						previous_num=random_num;
						i++;									//increment i
					}
					else
					{
						TR0=0; //END
					}

			}
		
			TR0 = 0;								//turn off timer
			printf("\r\n Number of correct answers = %d", number_correct);		//display results
			while (!SS);							//wait until the switch is turned off and back on again to loop
		}	
}