?? timer.c
字號:
/*****************************************************************************
* timer.c: Timer C file for NXP LPC17xx Family Microprocessors
*
* Copyright(C) 2009, NXP Semiconductor
* All rights reserved.
*
* History
* 2009.05.26 ver 1.00 Prelimnary version, first Release
*
******************************************************************************/
#include "..\Drive\PLC_PUBLIC.H"
/*uint32 timer0_counter = 0;
uint32 timer1_counter = 0;
uint32 timer2_counter = 0;
uint32 timer3_counter = 0;*/
/******************************************************************************
** Function name: Timer0_IRQHandler
**
** Descriptions: Timer/Counter 0 interrupt handler
**
** parameters: None
** Returned value: None
**
******************************************************************************/
void TIMER0_IRQHandler (void)
{
LPC_TIM0->IR = 1; /* clear interrupt flag */
PLC_RUN_TIME+=10; //運行時間+1MS
PLC_1MS_BIT++;
PLC_T_COUNT(); //計時
PLC_M_MS();
return;
}
/******************************************************************************
** Function name: Timer1_IRQHandler
**
** Descriptions: Timer/Counter 1 interrupt handler
**
** parameters: None
** Returned value: None
**
******************************************************************************/
void TIMER1_IRQHandler (void)
{
LPC_TIM1->IR = 1; /* clear interrupt flag */
return;
}
/******************************************************************************
******************************************************************************/
void TIMER2_IRQHandler (void)
{
LPC_TIM2->IR = 1;
if(Y0_H_OE==1) //PWM
{if(PWM_Y0_COUNT>=PWM_Y0_CYCLE){PWM_Y0_COUNT=0;}
else{if(PWM_Y0_COUNT<=PWM_Y0_ON_TIMER){LPC_GPIO2->FIOCLR =Y0;}
else{LPC_GPIO2->FIOSET =Y0;}
PWM_Y0_COUNT++;}
}
else if(Y0_H_OE==2) //PLSY
{if(LPC_GPIO2->FIOPIN&Y0){LPC_GPIO2->FIOCLR =Y0;}
else {LPC_GPIO2->FIOSET =Y0;D8140_1++;PLSY_Y0_COUNT--;
if(PLSY_Y0_COUNT==0){LPC_TIM2->TCR = 0;}
}
}
//LPC_TIM2->IR = 1;
return;
}
/******************************************************************************
******************************************************************************/
void TIMER3_IRQHandler (void)
{
LPC_TIM3->IR = 1;
if(Y1_H_OE==1) //PWM
{if(PWM_Y1_COUNT>=PWM_Y1_CYCLE){PWM_Y1_COUNT=0;}
else{if(PWM_Y1_COUNT<=PWM_Y1_ON_TIMER){LPC_GPIO2->FIOCLR =Y1;}
else{LPC_GPIO2->FIOSET =Y1;}
PWM_Y1_COUNT++;}
}
else if(Y1_H_OE==2) //PLSY
{if(LPC_GPIO2->FIOPIN&Y1){LPC_GPIO2->FIOCLR =Y1;}
else{LPC_GPIO2->FIOSET =Y1;D8142_3++;PLSY_Y1_COUNT--;
if(PLSY_Y1_COUNT==0){LPC_TIM3->TCR = 0;}
}
}
//LPC_TIM3->IR = 1;
return;
}
/******************************************************************************
** Function name: enable_timer
**
** Descriptions: Enable timer
**
** parameters: timer number: 0 or 1
** Returned value: None
**
******************************************************************************/
void enable_timer( uint8_t timer_num )
{
if ( timer_num == 0 )
{
LPC_TIM0->TCR = 1;
}
else if( timer_num == 1 )
{
LPC_TIM1->TCR = 1;
}
else if( timer_num == 2 )
{
LPC_TIM2->TCR = 1;
}
else if( timer_num == 3 )
{
LPC_TIM3->TCR = 1;
}
return;
}
/******************************************************************************
** Function name: disable_timer
**
** Descriptions: Disable timer
**
** parameters: timer number: 0 or 1
** Returned value: None
**
******************************************************************************/
void disable_timer( uint8 timer_num )
{
if ( timer_num == 0 )
{
LPC_TIM0->TCR = 0;
}
else if ( timer_num == 1 )
{
LPC_TIM1->TCR = 0;
}
else if ( timer_num == 2 )
{
LPC_TIM2->TCR = 0;
}
else if ( timer_num == 3 )
{
LPC_TIM3->TCR = 0;
}
}
/******************************************************************************
** Function name: init_timer
**
** Descriptions: Initialize timer, set timer interval, reset timer,
** install timer interrupt handler
**
** parameters: timer number and timer interval
** Returned value: true or false, if the interrupt handler can't be
** installed, return false.
**
******************************************************************************/
void init_timer ( uint8 timer_num, uint32 TimerInterval )
{
if ( timer_num == 1 )
{
//timer1_counter = 0;
LPC_TIM1->MR0 = TimerInterval;
LPC_TIM1->MCR = 3; /* Interrupt and Reset on MR1 */
NVIC_EnableIRQ(TIMER1_IRQn);
}
else if ( timer_num == 2 )
{
//timer2_counter = 0;
LPC_TIM2->MR0 = TimerInterval;
LPC_TIM2->MCR = 3; /* Interrupt and Reset on MR1 */
NVIC_EnableIRQ(TIMER2_IRQn);
}
else if ( timer_num == 3 )
{
//timer3_counter = 0;
LPC_TIM3->MR0 = TimerInterval;
LPC_TIM3->MCR = 3; /* Interrupt and Reset on MR1 */
NVIC_EnableIRQ(TIMER3_IRQn);
}
}
/******************************************************************************
** End Of File
******************************************************************************/
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -