STC15W408AS library 0.9.0
Timer2 Mode0

init

Timer initializaion functions

#define timer2_mode0_12T_init()
 Initialize mode0 12T for timer2. More...
 
#define timer2_mode0_1T_init()
 Initialize mode0 1T for timer2. More...
 

config

Timer configuration functions

#define timer2_mode0_enable_P30_output()   (bit_set(INT_CLKO, SBIT2))
 Enable output of meander with timer times on P3.0 pin. More...
 
#define timer2_mode0_disable_P30_output()   (bit_clr(INT_CLKO, CBIT2))
 Disable output of meander with timer times on P3.0 pin.
 
#define is_timer2_mode0_P30_output_enabled()   (test_if_bit_set(INT_CLKO, SBIT2))
 

run in async mode

Timer run/stop/reload functions

#define timer2_mode0_start(ticks)
 Run timer2 mode0 with interrupt support. More...
 
#define timer2_mode0_direct_start(th0, tl0)
 Run timer2 mode0 with direct set of TH0 and TL0 registers. More...
 
#define timer2_mode0_stop()
 Stop timer2 mode0. More...
 
#define timer2_mode0_reload(ticks)
 Reload timer2 ticks on the fly. More...
 
#define timer2_mode0_direct_reload(th2, tl2)
 Reload timer2 T2H and T2L registers on the fly. More...
 
#define is_timer2_mode0_started()   (test_if_bit_set(AUXR, SBIT4))
 Get timer2 started status. More...
 

baud rate enable/disable

Select timer2 as UART1 baud rate generator

#define timer2_mode0_enable_as_uart1_baud_rate()   (bit_set(AUXR, SBIT0))
 Select timer2 as uart1 baud rate generator. More...
 
#define timer2_mode0_disable_as_uart1_baud_rate()   (bit_clr(AUXR, CBIT0))
 Unselect timer2 as uart1 baud rate generator. More...
 
#define is_timer2_mode0_as_uart1_baud_rate_enabled()   (test_if_bit_set(AUXR, SBIT0))
 Is timer0 used as UART1 baud rate generator? More...
 

Detailed Description

Functions and data structures for timer2 mode0.

Timer can work as COUNTER or TIMER.

Counter increments on external singnal (like pin 1/0 change state).

8051 chips timer2

For timer:

Timer2 mode0 can be used in sync (main prorgam flow blocked until timer overloaded) and interrupt (call interrupt handler on timer overloaded) modes.

Author
Michael Golovanov

Macro Definition Documentation

◆ is_timer2_mode0_as_uart1_baud_rate_enabled

#define is_timer2_mode0_as_uart1_baud_rate_enabled ( )    (test_if_bit_set(AUXR, SBIT0))

Is timer0 used as UART1 baud rate generator?

by default timer0 used as UART1 baud rate generator

Returns
bool true if timer0 used as UART1 baud rate generator, otherwise false

◆ is_timer2_mode0_P30_output_enabled

#define is_timer2_mode0_P30_output_enabled ( )    (test_if_bit_set(INT_CLKO, SBIT2))

Get output to pin P3.0 output flag enabled value

Returns
bool true if output enabled oterwise false

◆ is_timer2_mode0_started

#define is_timer2_mode0_started ( )    (test_if_bit_set(AUXR, SBIT4))

Get timer2 started status.

Returns
bool true if started otherwise false

◆ timer2_mode0_12T_init

#define timer2_mode0_12T_init ( )
Value:
{ \
enable_mcu_interrupts(); \
enable_timer2_interrupt(); \
AUXR &= 0xE2; \
}

Initialize mode0 12T for timer2.

Timer2 could be used for UART. This method init timer2 as general purpose timer in mode0 with input from sysClk/12. Using timer2 in this mode disable UART capability.

◆ timer2_mode0_1T_init

#define timer2_mode0_1T_init ( )
Value:
{ \
enable_mcu_interrupts(); \
enable_timer2_interrupt(); \
AUXR &= 0xE2; \
AUXR |= 0x05; \
}

Initialize mode0 1T for timer2.

Timer2 could be used for UART. This method init timer2 as general purpose timer in mode0 with input from sysClk/1. Using timer2 in this mode disable UART capability.

◆ timer2_mode0_direct_reload

#define timer2_mode0_direct_reload (   th2,
  tl2 
)
Value:
{ \
T2H = th2; \
T2L = tl2; \
}

Reload timer2 T2H and T2L registers on the fly.

Reload is available in mode 0 only

Parameters
th2uint8_t T2H value
tl2uint8_t T2L value

◆ timer2_mode0_direct_start

#define timer2_mode0_direct_start (   th0,
  tl0 
)
Value:
{ \
timer2_mode0_direct_reload(th0, tl0); \
\
bit_set(AUXR, SBIT4); \
}

Run timer2 mode0 with direct set of TH0 and TL0 registers.

Before run timer2_mode0_12T_init or timer2_mode0_1T_init should be called.

After run program flow not blocked and interrupt will raised when timer is overloaded. Interrupt handler void timer2ISR(void) __interrupt(12) should be defined in user code.

Timer rerun occurs after overloading and interuppt handler calling. Timer overloading occurs when [TH0, TL0] = 0xff + 1

Parameters
th0uint8_t TH0 value
tl0uint8_t TL0 value

◆ timer2_mode0_disable_as_uart1_baud_rate

#define timer2_mode0_disable_as_uart1_baud_rate ( )    (bit_clr(AUXR, CBIT0))

Unselect timer2 as uart1 baud rate generator.

by default timer0 used as UART1 baud rate generator

◆ timer2_mode0_enable_as_uart1_baud_rate

#define timer2_mode0_enable_as_uart1_baud_rate ( )    (bit_set(AUXR, SBIT0))

Select timer2 as uart1 baud rate generator.

by default timer0 used as UART1 baud rate generator

◆ timer2_mode0_enable_P30_output

#define timer2_mode0_enable_P30_output ( )    (bit_set(INT_CLKO, SBIT2))

Enable output of meander with timer times on P3.0 pin.

By default output is disabled

◆ timer2_mode0_reload

#define timer2_mode0_reload (   ticks)
Value:
{ \
uint16_t value = 0xffff - ticks; \
T2L = value & 0xff; \
T2H = (value >> 8) & 0xff; \
}

Reload timer2 ticks on the fly.

Reload is available in mode 0 only

Parameters
ticksuint16_t timer ticks reloaded value

◆ timer2_mode0_start

#define timer2_mode0_start (   ticks)
Value:
{ \
timer2_mode0_reload(ticks); \
\
bit_set(AUXR, SBIT4); \
}

Run timer2 mode0 with interrupt support.

Before run timer2_mode0_12T_init or timer2_mode0_1T_init should be called.

After run program flow not blocked and interrupt will raised when timer is overloaded.

Interrupt handler void timer2ISR(void) __interrupt(12) should be defined in user code.

Timer rerun occurs after overloading and interuppt handler calling.

Parameters
ticksuint16_t timer tick count

◆ timer2_mode0_stop

#define timer2_mode0_stop ( )
Value:
{ \
bit_clr(AUXR, CBIT4); /* clear T2 run flag */ \
}

Stop timer2 mode0.

Before stop timer2_mode0_start should be called.