void main(void)
{
  WDTCTL = WDTPW + WDTHOLD;                 // Stop WDT
  
  UART_Initialization();                    // Initialize UART
  SPI_Initialization();                     // Initialize SPI

  while (1)
  {
    __bis_SR_register(CPUOFF + GIE);        // Enter LPM0 w/ interrupts
                                            // Remain in LPM0 until all data
                                            // is TX'd
    _NOP();                                 // Set breakpoint >>here<< and read
                                            // read out the UART_Data and 
                                            // SPI_Data variables
  }
}
Пример #2
0
int main(void)
{
  PWM_Initialization();
  TIM1->CCR2 = 1000;
  TIM1->CCR3 = 1000;
  Delay_1us(500000);

  RCC_Configuration();
  PushButton_Initialization();
  LED_Initialization();
  //LCD_Initialization();
  //terminalBufferInitilization();

  Delay_1us(100000);
  SPI_Initialization();
  Delay_1us(100000);
  IMU_Initialization();
  Delay_1us(100000);
  Timer5_Initialization(); //Filter
  Timer2_Initialization(); //Print
  Timer4_Initialization(); //Read IMU

  USART3_Configuration();
  USART3_puts("\r\nHello World!\r\n");
    
  while(1)
  {
    if(PushButton_Read()){
      if(f.arm == 0){ 
        f.arm = 1;
        Delay_1us(500000);
      }
      else if(f.arm == 1){
        f.arm = 0;
        Delay_1us(500000);
      }
    }

    if(f.imu == 1){
      //LED3_Toggle();
      readIMU(gyroRaw, GYRO_DATA_REGISTER);
      gyro_remove_offset(gyroRaw);
      readIMU(accRaw, ACC_DATA_REGISTER);
      f.imu = 0;
    // }  

    // if(f.filter == 1){
      //LED4_Toggle();
      Filter(gyroRaw, gyroAngle, accRaw, accAngle, Angle);
      if(f.arm == 1){
        PID_control(Angle);
      }
      else{
        TIM1->CCR2 = 1000;
        TIM1->CCR3 = 1000;

        errorI = 0;
        errorD = 0;
        previous_error = 0;
      }

      //f.filter = 0;
    }

    strcmd_main();      

    //if(f.print == 1){
      
      // sprintf(lcd_text_main,"%.4f %.4f %d", Angle[0], Angle[1], f.arm);
      // //sprintf(lcd_text_main,"G: %.3f %.3f %.3f", EstV.G.X, EstV.G.Y, EstV.G.Z);
      // LCD_DisplayStringLine(LINE(1), lcd_text_main);
      // //sprintf(lcd_text_main,"A: %.3f %.3f %.3f", EstV.A.X, EstV.A.Y, EstV.A.Z);
      // //sprintf(lcd_text_main,"A: %.3f %.3f", sqX_sqZ, EstV.GA.X*EstV.GA.X + EstV.GA.Z*EstV.GA.Z);
      // // sprintf(lcd_text_main,"%.4f %.4f %.4f \n", gyroAngle[0], gyroAngle[1], gyroAngle[2]);
      // sprintf(lcd_text_main,"%d     ", gyroRaw[2]);
      // LCD_DisplayStringLine(LINE(2), lcd_text_main);
      // sprintf(lcd_text_main,"GA: %.3f %.3f %.3f", EstV.GA.X, EstV.GA.Y, EstV.GA.Z);
      // LCD_DisplayStringLine(LINE(3), lcd_text_main);
      //sprintf(lcd_text_main,"%.3f %.3f %.3f\n", EstV.G.Z, EstV.A.Z, EstV.GA.Z);
      
      //LCD_DisplayStringLine(LINE(2), (uint8_t*)" Ming6842 @ github");
      //terminalWrite(lcd_text_main);
      //PRINT_USART();
      //f.print = 0;
    //}
  }

  while(1); // Don't want to exit
}