#include "LPC177x_8x.h"
unsigned int counter;
void timer_counter_init(void);
//void TIMER1_IRQHandeler(void);
//void TIMER0_IRQHandeler(void);
void timer_counter_init(void)
{
LPC_SC->PCONP|=3;// timer0,1 =on
LPC_TIM1->CTCR=0;// timer mod
LPC_TIM1->PR=120;
LPC_TIM1->MR0=1000;
LPC_TIM1->TCR=2;
LPC_TIM1->MCR=3;
//NVIC_SetPriority(TIMER1_IRQn,0);
NVIC_EnableIRQ(TIMER1_IRQn);
LPC_TIM1->TCR=1;//start timer1
//---------- counter init --------------------------------------
LPC_TIM0->CTCR=0x05; // counter mod - rising edge on cap0.1
LPC_TIM0->PR=0;
LPC_TIM0->MR0=65000;
LPC_TIM0->TCR=2;
LPC_TIM0->MCR=3;
// NVIC_SetPriority(TIMER0_IRQn,0);
// NVIC_EnableIRQ(TIMER0_IRQn);
LPC_TIM0->TCR=1;//start counter0
LPC_IOCON->P1_27=3;//counter_pulse p1.27
}
//************************************************** ****
void TIMER1_IRQHandeler(void)
{
unsigned int regVal;
regVal = LPC_PWM1->IR;
counter=LPC_TIM1->TC;
LPC_TIM1->TC=0;
//LPC_TIM1->IR=(1UL<<0);
LPC_PWM1->IR |= regVal; /* clear interrupt flag on match 0 */
return;
}
//************************************************** ****
void TIMER0_IRQHandeler(void)
{
LPC_TIM1->TC=0;
LPC_TIM0->IR=(1UL<<0);
}