📄 timer_a.c
字号:
// +--------- timer A0 event/trigger select bits
// 00: input on TA0in (must be input)
// 01: overflow of timer B2
// 10: overflow of timer A4
// 11: overflow of timer A1
// Clock prescaler reset flag
// This function is only effective if fc32 is selected
if ((TA0MR & 0xC0)==0xC0)
{
CPSRF = 0x80; // 1--- ----
// +---------- 1: clock prescaler is reset
}
}
/**************************************************************************/
/* */
/* Timer A0 - Initialization for pwm mode */
/* The timer outputs pulses of a given width */
/* routine may be customized to the user's needs */
/* */
/* Name : timer_a0_init_pwm_mode */
/* Date/Author : 08.04.1997/ST */
/* Parameter : */
/* Return : */
/* */
/**************************************************************************/
void near timer_a0_init_pwm_mode (void)
{
TA0MR = 0x01; // XXXX X111
// |||| |||+- must always be 1 in pwm mode
// |||| ||+-- must always be 1 in pwm mode
// |||| |+--- must always be 1 in pwm mode
// |||| +---- 0: ext. trigger falling edge of
// |||| TA0in input signal
// |||| 1: ext. trigger rising edge of
// |||| TA0in input signal
// |||| TA0in must be configured as input
// |||| TA0in must be selected by
// |||| event/trigger select bits
// |||+------ 0: trigger is count start flag (TABSR)
// ||| 1: trigger is selected by event/trigger
// ||| select bits
// ||+------- 0: 16-bit pwm
// || 1: 8-bit pwm
// |+-------- count source select bits:
// +--------- count source select bits:
// 00: f1
// 01: f8
// 10: f32
// 11: fc32
ONSF |= 0xC0; // XX-- ----
// |+-------- timer A0 event/trigger select bits
// +--------- timer A0 event/trigger select bits
// 00: input on TA0in (must be input)
// 01: overflow of timer B2
// 10: overflow of timer A4
// 11: overflow of timer A1
// Clock prescaler reset flag
// This function is only effective if fc32 is selected
if ((TA0MR & 0xC0)==0xC0)
{
CPSRF = 0x80; // 1--- ----
// +---------- 1: clock prescaler is reset
}
}
/**************************************************************************/
/* */
/* Timer A0 - start */
/* In following cases this routine takes no effect: */
/* - in one-shot timer mode if ext. trigger or timer overflow is */
/* selected as start condition */
/* - in pwm mode if external trigger or timer overflow is selected */
/* as start condition */
/* */
/* Name : timer_a0_start */
/* Date/Author : 08.04.1997/ST */
/* Parameter : */
/* Return : */
/* */
/**************************************************************************/
void near timer_a0_start (void)
{
TABSR |= 0x01; // ---- ---1
// +- 1: start timer A0 (count flag)
ONSF |= 0x01; // ---- ---1
// +- 1: start timer A0 (one-shot flag)
}
/**************************************************************************/
/* */
/* Timer A0 - stop */
/* In following cases this routine takes no effect: */
/* - in one-shot timer mode if ext. trigger or timer overflow is */
/* selected as start condition */
/* - in pwm mode if external trigger or timer overflow is selected */
/* as start condition */
/* */
/* Name : timer_a0_stop */
/* Date/Author : 08.04.1997/ST */
/* Parameter : */
/* Return : */
/* */
/**************************************************************************/
void near timer_a0_stop (void)
{
TABSR &= ~(0x01); // ---- ---0
// +- 0: stop timer A0 (count flag)
ONSF &= ~(0x01); // ---- ---0
// +- 0: stop timer A0 (one-shot flag)
}
/**************************************************************************/
/* */
/* Timer A0 - get current value */
/* */
/* Name : timer_a0_get */
/* Date/Author : 08.04.1997/ST */
/* Parameter : */
/* Return : - current count value in timer mode or event */
/* counter mode */
/* - indeterminate in one-shot mode or pwm mode */
/* */
/**************************************************************************/
unsigned int near timer_a0_get (void)
{
return(TA0);
}
/**************************************************************************/
/* */
/* timer A0 - set current value */
/* when counting stopped : write value to reload register and */
/* counter */
/* when counting in progress: write value only to reload register */
/* transferred to counter at next reload */
/* time */
/* In 8-bit pwm mode highbyte gives time of high level and */
/* lowbyte gives time of low level */
/* */
/* Name : timer_a0_set */
/* Date/Author : 08.04.1997/ST */
/* Parameter : load value */
/* Return : */
/* */
/**************************************************************************/
void near timer_a0_set (unsigned int value)
{
TA0 = value;
}
/**************************************************************************/
/* */
/* Timer A0 - set interrupt */
/* user must adapt interrupt priority level */
/* */
/* Name : timer_a0_interrupt_set */
/* Date/Author : 14.04.1997/ST */
/* Parameter : */
/* Return : */
/* */
/**************************************************************************/
void near timer_a0_interrupt_set (void)
{
TA0IC = 0x01; // ---- XXXX
// ||||
// |||+-- Interupt priority level select bit
// ||+--- Interupt priority level select bit
// |+---- Interupt priority level select bit
// | 000: Level 0 (interrupt disabled)
// | 001: Level 1
// | 010: Level 2
// | 011: Level 3
// | 100: Level 4
// | 101: Level 5
// | 110: Level 6
// | 111: Level 7
// +----- Interupt request bit
// 0: Interrupt not requested
// 1: Interrupt requested
}
/**************************************************************************/
/* */
/* Timer A0 - clear interrupt */
/* */
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -