📄 ma_tmr.c
字号:
** Starts the selected timer channel. Optionally, the timer counter
** can be cleared before the timer is started.
**
** Parameters:
** Channel The timer channel to start (0-3)
** Reset 0 = Do not reset timer before start
** 1 = Reset timer value before start
**
** Returns:
** MA_ERROR If illegal channel number was given
** MA_OK Otherwise
**
**---------------------------------------------------------------------------
*/
{
/*--- Handle user code on function entry ---*/
// ENTER_MA_START_TMR;
/*--- Handle correct channel ---*/
switch( Channel )
{
case 0:
/*--- Reset timer first? ---*/
if( Reset )
{
TCNT0 = 0;
}
/*--- Start channel 0 ---*/
TCCR0 = MA_TCCR0_TMR;
break;
case 1:
/*--- Reset timer first? ---*/
if( Reset )
{
TCNT1 = 0;
}
/*--- Start channel 1 ---*/
TCCR1B = MA_TCCR1B_TMR;
break;
case 2:
/*--- Reset timer first? ---*/
if( Reset )
{
TCNT2 = 0;
}
/*--- Start channel 2 ---*/
TCCR2 = MA_TCCR2_TMR;
break;
case 3:
/*--- Reset timer first? ---*/
if( Reset )
{
TCNT3 = 0;
}
/*--- Start channel 3 ---*/
TCCR3B = MA_TCCR3B_TMR;
break;
default:
/*--- Handle user code on function exit ---*/
//EXIT_MA_START_TMR;
/*--- Illegal channel ---*/
return MA_ERROR;
}
/*--- Handle user code on function exit ---*/
//EXIT_MA_START_TMR;
return MA_OK;
} /* MA_START_TMR */
S8 MA_Stop_TMR( U8 Channel )
/*
**---------------------------------------------------------------------------
**
** Abstract:
** Stops the selected timer channel.
**
** Parameters:
** Channel The timer channel to stop (0-3)
**
** Returns:
** MA_ERROR If illegal channel number was given
** MA_OK Otherwise
**
**---------------------------------------------------------------------------
*/
{
/*--- Handle user code on function entry ---*/
//ENTER_MA_STOP_TMR;
/*--- Handle correct channel ---*/
switch( Channel )
{
case 0:
/*--- Stop channel 0 ---*/
TCCR0 &= ~0x07;
break;
case 1:
/*--- Stop channel 1 ---*/
TCCR1B &= ~0x07;
break;
case 2:
/*--- Stop channel 2 ---*/
TCCR2 &= ~0x07;
break;
case 3:
/*--- Stop channel 3 ---*/
TCCR3B &= ~0x07;
break;
default:
/*--- Handle user code on function exit ---*/
//EXIT_MA_STOP_TMR;
/*--- Illegal channel ---*/
return MA_ERROR;
}
/*--- Handle user code on function exit ---*/
//EXIT_MA_STOP_TMR;
return MA_OK;
} /* MA_STOP_TMR */
S8 MA_SetCompareMatch_TMR( U8 Channel, U16 ValueA, U16 ValueB, U16 ValueC )
/*
**---------------------------------------------------------------------------
**
** Abstract:
** Sets new compare match values for selected channel. Please note that
** only some channels have support for B and C values. For channels
** with support for one compare match value only, use Value A.
*
** Parameters:
** Channel The timer channel to change
** ValueA The new compare match value (A) (all channels)
** ValueB The new compare match value (B) (channels 1 and 3)
** ValueC The new compare match value (C) (channels 1 and 3)
**
** Returns:
** MA_ERROR If illegal channel number was given
** MA_OK Otherwise
**
**---------------------------------------------------------------------------
*/
{
/*--- Handle user code on function entry ---*/
//ENTER_MA_SETCOMPAREMATCH_TMR;
/*--- Handle correct channel ---*/
switch( Channel )
{
case 0:
/*--- Update channel 0 ---*/
OCR0 = (U8)ValueA;
break;
case 1:
/*--- Update channel 1 ---*/
OCR1A = ValueA;
OCR1B = ValueB;
OCR1C = ValueC;
break;
case 2:
/*--- Update channel 2 ---*/
OCR2 = (U8)ValueA;
break;
case 3:
/*--- Update channel 3 ---*/
OCR3A = ValueA;
OCR3B = ValueB;
OCR3C = ValueC;
break;
default:
/*--- Handle user code on function exit ---*/
//EXIT_MA_SETCOMPAREMATCH_TMR;
/*--- Illegal channel ---*/
return MA_ERROR;
}
/*--- Handle user code on function exit ---*/
//EXIT_MA_SETCOMPAREMATCH_TMR;
return MA_OK;
} /* MA_SETCOMPAREMATCH_TMR */
extern int i;
#pragma vector=MA_TIMER0_OVF_vect
__interrupt void MA_IntHandler_OVF0_TMR( void )
/*
**---------------------------------------------------------------------------
**
** Abstract:
** This function is the high level language interrupt handler for the
** timer 0 overflow interrupt.
**
** Parameters:
** None
**
** Returns:
** None
**
**---------------------------------------------------------------------------
*/
{
/*--- Handle user code on function entry ---*/
//ENTER_MA_INTHANDLER_OVF0_TMR;
/*--- Handle user code ---*/
//INSIDE_MA_INTHANDLER_OVF0_TMR;
/*--- Handle user code on function exit ---*/
//EXIT_MA_INTHANDLER_OVF0_TMR;
i++;
} /* MA_IntHandler_OVF0_TMR */
/*
**===========================================================================
** 5. INTERNAL FUNCTIONS (declared in Section 3.5)
**===========================================================================
*/
/*
**===========================================================================
** END OF FILE
**===========================================================================
*/
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -