timer.c LPC17xx library

September 23, 2017 | Author: Gurudatta Palankar | Category: N/A
Share Embed Donate


Short Description

Descripción: timer.c LPC17xx library...

Description

/**************************************************************************** * $Id:: timer.c 5823 2010-12-07 19:01:00Z usb00423 $ * Project: NXP LPC17xx Timer for PWM example * * Description: * This file contains timer code example which include timer * initialization, timer interrupt handler, and APIs for timer access. * **************************************************************************** * Software that is described herein is for illustrative purposes only * which provides customers with programming information regarding the * products. This software is supplied "AS IS" without any warranties. * NXP Semiconductors assumes no responsibility or liability for the * use of the software, conveys no license or title under any patent, * copyright, or mask work right to the product. NXP Semiconductors * reserves the right to make changes in the software without * notification. NXP Semiconductors also make no representation or * warranty that such application will be suitable for the specified * use without further testing or modification. ****************************************************************************/ #include "lpc17xx.h" #include "lpc_types.h" #include "timer.h" volatile volatile volatile volatile volatile volatile volatile volatile

uint32_t uint32_t uint32_t uint32_t uint32_t uint32_t uint32_t uint32_t

timer0_m0_counter timer1_m0_counter timer2_m0_counter timer3_m0_counter timer0_m1_counter timer1_m1_counter timer2_m1_counter timer3_m1_counter

= = = = = = = =

volatile volatile volatile volatile volatile volatile volatile volatile

uint32_t uint32_t uint32_t uint32_t uint32_t uint32_t uint32_t uint32_t

timer0_capture0 timer1_capture0 timer2_capture0 timer3_capture0 timer0_capture1 timer1_capture1 timer2_capture1 timer3_capture1

0; 0; 0; 0; 0; 0; 0; 0;

= = = = = = = =

0; 0; 0; 0; 0; 0; 0; 0;

/***************************************************************************** ** Function name: delayMs ** ** Descriptions: Start the timer delay in milo seconds ** until elapsed ** ** parameters: timer number, Delay value in milo second ** ** Returned value: None ** *****************************************************************************/ void delayMs(uint8_t timer_num, uint32_t delayInMs) { if ( timer_num == 0 ) { LPC_TIM0->TCR = 0x02; /* reset timer */ LPC_TIM0->PR = 0x00; /* set prescaler to zero */

LPC_TIM0->MR0 = (SystemCoreClock / 4) / (1000/delayInMs); //enter delay time LPC_TIM0->IR = 0xff; LPC_TIM0->MCR = 0x04; LPC_TIM0->TCR = 0x01;

/* reset all interrrupts */ /* stop timer on match */ /* start timer */

/* wait until delay time has elapsed */ while (LPC_TIM0->TCR & 0x01); } else if ( timer_num { LPC_TIM1->TCR LPC_TIM1->PR LPC_TIM0->MR0 time LPC_TIM1->IR LPC_TIM1->MCR LPC_TIM1->TCR

== 1 ) = 0x02; /* reset timer */ = 0x00; /* set prescaler to zero */ = (SystemCoreClock / 4) / (1000/delayInMs); //enter delay = 0xff; = 0x04; = 0x01;

/* reset all interrrupts */ /* stop timer on match */ /* start timer */

/* wait until delay time has elapsed */ while (LPC_TIM1->TCR & 0x01); } else if ( timer_num { LPC_TIM2->TCR LPC_TIM2->PR LPC_TIM0->MR0 time LPC_TIM2->IR LPC_TIM2->MCR LPC_TIM2->TCR

== 2 ) = 0x02; /* reset timer */ = 0x00; /* set prescaler to zero */ = (SystemCoreClock / 4) / (1000/delayInMs); //enter delay = 0xff; = 0x04; = 0x01;

/* reset all interrrupts */ /* stop timer on match */ /* start timer */

/* wait until delay time has elapsed */ while (LPC_TIM2->TCR & 0x01); } else if ( timer_num { LPC_TIM3->TCR LPC_TIM3->PR LPC_TIM0->MR0 time LPC_TIM3->IR LPC_TIM3->MCR LPC_TIM3->TCR

== 3 ) = 0x02; /* reset timer */ = 0x00; /* set prescaler to zero */ = (SystemCoreClock / 4) / (1000/delayInMs); //enter delay = 0xff; = 0x04; = 0x01;

/* reset all interrrupts */ /* stop timer on match */ /* start timer */

/* wait until delay time has elapsed */ while (LPC_TIM3->TCR & 0x01); } return; } /****************************************************************************** ** Function name: Timer0_IRQHandler ** ** Descriptions: Timer/Counter 0 interrupt handler ** ** parameters: None

** Returned value: None ** ******************************************************************************/ void TIMER0_interrupt (void) { if ( LPC_TIM0->IR & (0x1
View more...

Comments

Copyright ©2017 KUPDF Inc.
SUPPORT KUPDF