Advertisement
everblut

function

Sep 19th, 2013
146
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.12 KB | None | 0 0
  1. void Timer0_Wait(uint32_t ms)
  2. {
  3.     TIM_TIMERCFG_Type TIM_ConfigStruct;
  4.     TIM_MATCHCFG_Type TIM_MatchConfigStruct ;
  5.  
  6.         // Initialize timer 0, prescale count time of 1ms
  7.     TIM_ConfigStruct.PrescaleOption = TIM_PRESCALE_USVAL;
  8.     TIM_ConfigStruct.PrescaleValue  = 1000;
  9.     // use channel 0, MR0
  10.     TIM_MatchConfigStruct.MatchChannel = 0;
  11.     // Enable interrupt when MR0 matches the value in TC register
  12.     TIM_MatchConfigStruct.IntOnMatch   = TRUE;
  13.     //Enable reset on MR0: TIMER will not reset if MR0 matches it
  14.     TIM_MatchConfigStruct.ResetOnMatch = FALSE;
  15.     //Stop on MR0 if MR0 matches it
  16.     TIM_MatchConfigStruct.StopOnMatch  = TRUE;
  17.     //do no thing for external output
  18.     TIM_MatchConfigStruct.ExtMatchOutputType =TIM_EXTMATCH_NOTHING;
  19.     // Set Match value, count value is ms (timer * 1000uS =timer mS )
  20.     TIM_MatchConfigStruct.MatchValue   = ms;
  21.  
  22.     // Set configuration for Tim_config and Tim_MatchConfig
  23.     TIM_Init(LPC_TIM0, TIM_TIMER_MODE,&TIM_ConfigStruct);
  24.     TIM_ConfigMatch(LPC_TIM0,&TIM_MatchConfigStruct);
  25.     // To start timer 0
  26.     TIM_Cmd(LPC_TIM0,ENABLE);
  27.     while ( !(TIM_GetIntStatus(LPC_TIM0,0)));
  28.         TIM_ClearIntPending(LPC_TIM0,0);
  29. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement