예제 #1
0
/*====================================================================================================*/
void System_Init( void )
{
  MPU_InitTypeDef MPU_InitStruct;

  CLOCK_SourceXTAL(NRF_CLOCK_XTALFREQ_16MHz);
  CLOCK_SourceLFCLK(NRF_CLOCK_LF_SRC_RC);
  CLOCK_CmdHFCLK(ENABLE);
  CLOCK_CmdLFCLK(ENABLE);

  GPIO_Config();
  Serial_Config();
  MPU9250_Config();

  Delay_100ms(1);
  printf("\r\nHello World!\r\n\r\n");

  MPU_InitStruct.MPU_Gyr_FullScale     = MPU_GyrFS_2000dps;
  MPU_InitStruct.MPU_Gyr_LowPassFilter = MPU_GyrLPS_41Hz;
  MPU_InitStruct.MPU_Acc_FullScale     = MPU_AccFS_4g;
  MPU_InitStruct.MPU_Acc_LowPassFilter = MPU_AccLPS_41Hz;
  printf("MPU9250 Init ...");
  if(MPU9250_Init(&MPU_InitStruct) != SUCCESS) {
    printf("ERROR\r\n");
    while(1) {
      LED2_Toggle();
      Delay_100ms(1);
    }
  }
  printf("SUCCESS\r\n");
  LED2_Set();
  Delay_100ms(1);
}
예제 #2
0
//void SysTick_Handler( void );
//void POWER_CLOCK_IRQHandler( void );
//void RADIO_IRQHandler( void );
//void UART0_IRQHandler( void );
//void SPI0_TWI0_IRQHandler( void );
//void SPI1_TWI1_IRQHandler( void );
//void GPIOTE_IRQHandler( void );
//void ADC_IRQHandler( void );
//void TIMER0_IRQHandler( void );
//void TIMER1_IRQHandler( void );
//void TIMER2_IRQHandler( void );
void RTC0_IRQHandler( void )
{
  if(RTC_TickEvenCheck(RTCx) == SUCCESS) {
    LED1_Toggle();
    RTC_TickEvenClear(RTCx);
  }
  if(RTC_CompEvenCheck(RTCx, RTCx_CH) == SUCCESS) {
    LED2_Toggle();
    RTC_CompEvenClear(RTCx, RTCx_CH);
    RTC_CntClear(RTCx);
  }
}
예제 #3
0
파일: rtc.c 프로젝트: tigerzhh/ADC_Test
/** @brief: Function for handling the RTC0 interrupts.
 * Triggered on TICK and COMPARE0 match.
 */
void RTC0_IRQHandler()
{
    if ((NRF_RTC0->EVENTS_TICK != 0) && 
        ((NRF_RTC0->INTENSET & RTC_INTENSET_TICK_Msk) != 0))
    {
        NRF_RTC0->EVENTS_TICK = 0;
        LED1_Toggle();
    }
    
    if ((NRF_RTC0->EVENTS_COMPARE[0] != 0) && 
        ((NRF_RTC0->INTENSET & RTC_INTENSET_COMPARE0_Msk) != 0))
    {
        NRF_RTC0->EVENTS_COMPARE[0] = 0;
        LED2_Toggle();
    }
}
예제 #4
0
void DemoAutomata(void)
{
    TDateTime DT;
    
    switch (DemoState)
    {
        case DEMO_RED_BRIGHT:
        {
            if (DemoState != DemoStatePrev)
            {
                DemoStatePrev = DemoState;

                secCounter   = 0;
                DemoCounter  = 0;
                Demo_sec     = 0;

                Demo_DigG    = -1;
                
                Demo_DigR = DemoBrightTable[DemoCounter];
                SetBright_Prc(Demo_DigR);

                DigMask   = 0;
                
                RedManVar    = RMAN_MASK;
                GreenManVar  = 0;
            }

            secCounter++;
            if (secCounter>=1000)
            {
                secCounter = 0;
    
                Demo_sec++;
                if (Demo_sec >= DEMO_DEF_TIME)
                {
                    Demo_sec = 0;
                    
                    DemoCounter++;
                    if (DemoCounter < sizeof(DemoBrightTable))
                    {
                        Demo_DigR = DemoBrightTable[DemoCounter];
                        SetBright_Prc(Demo_DigR);
                    }
                    else
                    {
                        DemoState++;
                        LED2_Toggle();
                    }
                } 
            }        
            break;
        };
        
        
        case DEMO_GREEN_BRIGHT:
        {
            if (DemoState != DemoStatePrev)
            {
                DemoStatePrev = DemoState;

                secCounter   = 0;
                DemoCounter  = 0;
                Demo_sec     = 0;

                Demo_DigR    = -1;
                
                Demo_DigG = DemoBrightTable[DemoCounter];

                SetBright_Prc(Demo_DigG);
                SetVolume_Prc(Demo_DigG);

                DigMask   = CalcNumberMask(Demo_DigG, GREEN_MAX_COUNT);
                
                RedManVar   = 0;
                GreenManVar = GMAN0_MASK|GMAN1_MASK;
                GManPhase = 0;

                ManStepCounter     = 0;
                SoundRepeatCounter = 0;
                ManStepPeriod      = MAN_STEP_PERIOD;

                Config.SampleNum = 0;

                StartSound();
            }

            secCounter++;
            if (secCounter>=1000)
            {
                secCounter = 0;
    
                Demo_sec++;
                if (Demo_sec >= DEMO_DEF_TIME)
                {
                    Demo_sec = 0;
                    
                    DemoCounter++;
                    if (DemoCounter < sizeof(DemoBrightTable))
                    {
                        Demo_DigG = DemoBrightTable[DemoCounter];

                        SetBright_Prc(Demo_DigG);
                        SetVolume_Prc(Demo_DigG);
                        
                        DigMask   = CalcNumberMask(Demo_DigG, GREEN_MAX_COUNT);
                    }
                    else
                    {
                        if (Config.SampleNum<3)
                        {
                            Config.SampleNum++;
            
                            secCounter   = 0;
                            DemoCounter  = 0;
                            Demo_sec     = 0;

                            Demo_DigR    = -1;
                            
                            Demo_DigG = DemoBrightTable[DemoCounter];
                        
                            SetBright_Prc(Demo_DigG);
                            SetVolume_Prc(Demo_DigG);

                            DigMask   = CalcNumberMask(Demo_DigG, GREEN_MAX_COUNT);
                            
                            RedManVar   = 0;
                            GreenManVar = GMAN0_MASK|GMAN1_MASK;
                            GManPhase   = 0;

                            ManStepCounter     = 0;
                            SoundRepeatCounter = 0;
                            ManStepPeriod      = MAN_STEP_PERIOD;

                            StartSound();
                        }
                        else
                        {
                            DemoState++;
                            LED2_Toggle();
                            break;
                        }
                    }
                } 
            }

            ManStepCounter++;
            if (ManStepCounter >= ManStepPeriod)
            {
                GreenManVar ^= GMAN1_MASK|GMAN2_MASK;
                GManPhase = !GManPhase;
                ManStepCounter = 0;
            }

            SoundRepeatCounter++;
            if (SoundRepeatCounter >= (ManStepPeriod*2))
            {
                StartSound();
                SoundRepeatCounter = 0;
            }

            break;
        };

        case DEMO_TIME:
        {
            if (DemoState != DemoStatePrev)
            {
                DemoStatePrev = DemoState;

                if (!RTC_GetTime(&DT))
                {
                    DemoState++;
                }
                else
                {
                    secCounter   = 0;
                    DemoCounter  = 0;
                    Demo_sec     = 0;

                    Demo_DigG    = DT.min;
                    Demo_DigR    = DT.hour;
                    DigMask      = CalcNumberMask(Demo_DigG, GREEN_MAX_COUNT);

                    RedManVar    = 0;
                    GreenManVar  = GMAN0_MASK|GMAN1_MASK;
                    GManPhase    = -1;
                }
            }

            secCounter++;
            if (secCounter>=1000)
            {
                secCounter = 0;
    
                Demo_sec++;
                if (Demo_sec >= DEMO_DEF_TIME*2)
                {
                    Demo_sec = 0;
                    DemoState++;
                    LED2_Toggle();
                }            
            }
            
            break;
        };
/*
        case DEMO_FADE_BRIGHT:
        {
            if (DemoState != DemoStatePrev)
            {
                DemoStatePrev = DemoState;

                secCounter   = 0;
                DemoCounter  = 0;
                Demo_sec     = 0;

                Demo_DigG    = -1;
                
                Demo_DigR = 100;
                SetBright_Prc(Demo_DigR);

                DigMask   = 0;
                
                RedManVar    = RMAN_MASK;
                GreenManVar  = 0;
            }
            
            secCounter++;
            if (secCounter>=1000)
            {
                secCounter = 0;
    
                Demo_sec++;
                if (Demo_sec >= DEMO_DEF_TIME)
                {
                    Demo_sec = 0;
                    
                    DemoCounter++;
                    if (DemoCounter < sizeof(DemoBrightTable))
                    {
                        Demo_DigR = DemoBrightTable[DemoCounter];
                        SetBright_Prc(Demo_DigR);
                    }
                    else
                    {
                        DemoState++;
                    }
                } 
            }        
            break;
        };

*/        
        default:
        case DEMO_END:
        {
            DemoState = (TDemoState)0;
            break;
        };
    };
    
    if (DemoState >= DEMO_END)
        DemoState = (TDemoState)0;
}