1 #include "lpc18xx_utils.h"
\r
2 #include "lpc18xx_timer.h"
\r
5 TIM_TIMERCFG_Type TIM_ConfigStruct;
\r
6 TIM_MATCHCFG_Type TIM_MatchConfigStruct;
\r
9 /*********************************************************************//**
\r
10 * @brief Main TIMER program body
\r
13 **********************************************************************/
\r
14 int timer_delay_us( int cnt)
\r
17 // Initialize timer 0, prescale count time of 1uS
\r
18 TIM_ConfigStruct.PrescaleOption = TIM_PRESCALE_USVAL;
\r
19 TIM_ConfigStruct.PrescaleValue = 20;
\r
21 // use channel 0, MR0
\r
22 TIM_MatchConfigStruct.MatchChannel = 0;
\r
23 // Disable interrupt when MR0 matches the value in TC register
\r
24 TIM_MatchConfigStruct.IntOnMatch = TRUE;
\r
25 //Enable reset on MR0: TIMER will reset if MR0 matches it
\r
26 TIM_MatchConfigStruct.ResetOnMatch = TRUE;
\r
27 //Stop on MR0 if MR0 matches it
\r
28 TIM_MatchConfigStruct.StopOnMatch = TRUE;
\r
30 TIM_MatchConfigStruct.ExtMatchOutputType =TIM_EXTMATCH_NOTHING;
\r
32 TIM_MatchConfigStruct.MatchValue = cnt;
\r
34 // Set configuration for Tim_config and Tim_MatchConfig
\r
35 TIM_Init(LPC_TIMER0, TIM_TIMER_MODE,&TIM_ConfigStruct);
\r
36 TIM_ConfigMatch(LPC_TIMER0,&TIM_MatchConfigStruct);
\r
37 TIM_Cmd(LPC_TIMER0,ENABLE);
\r
39 while ( !(TIM_GetIntStatus(LPC_TIMER0,TIM_MR0_INT)));
\r
40 TIM_ClearIntPending(LPC_TIMER0,(TIM_INT_TYPE)0);
\r
45 /*********************************************************************//**
\r
46 * @brief Main TIMER program body
\r
49 **********************************************************************/
\r
50 int timer_delay_ms( int cnt)
\r
53 // Initialize timer 0, prescale count time of 1uS
\r
54 TIM_ConfigStruct.PrescaleOption = TIM_PRESCALE_USVAL;
\r
55 TIM_ConfigStruct.PrescaleValue = 1000;
\r
57 // use channel 0, MR0
\r
58 TIM_MatchConfigStruct.MatchChannel = 1;
\r
59 // Disable interrupt when MR0 matches the value in TC register
\r
60 TIM_MatchConfigStruct.IntOnMatch = TRUE;
\r
61 //Enable reset on MR0: TIMER will reset if MR0 matches it
\r
62 TIM_MatchConfigStruct.ResetOnMatch = TRUE;
\r
63 //Stop on MR0 if MR0 matches it
\r
64 TIM_MatchConfigStruct.StopOnMatch = TRUE;
\r
66 TIM_MatchConfigStruct.ExtMatchOutputType =TIM_EXTMATCH_NOTHING;
\r
68 TIM_MatchConfigStruct.MatchValue = cnt;
\r
70 // Set configuration for Tim_config and Tim_MatchConfig
\r
71 TIM_Init(LPC_TIMER1, TIM_TIMER_MODE,&TIM_ConfigStruct);
\r
72 TIM_ConfigMatch(LPC_TIMER1,&TIM_MatchConfigStruct);
\r
73 TIM_Cmd(LPC_TIMER1,ENABLE);
\r
75 while ( !(TIM_GetIntStatus(LPC_TIMER1,TIM_MR1_INT)));
\r
76 TIM_ClearIntPending(LPC_TIMER1,(TIM_INT_TYPE)1);
\r