STC15W408AS library 0.9.0
Macros
Timer0 Mode1

Macros

#define INT0   P32
 INT0 pin definition.
 
#define INT0   P32
 INT0 pin definition.
 
#define INT0   P32
 INT0 pin definition.
 

init

Timer initializaion functions

#define timer0_mode1_12T_init()
 Initialize mode1 12T for timer0. More...
 
#define timer0_mode1_1T_init()
 Initialize mode1 1T for timer0. More...
 

config

Timer configuration functions

#define timer0_mode1_close_gate()   (bit_set(TMOD, SBIT3))
 Close timer starting gate. More...
 
#define timer0_mode1_open_gate()   (bit_clr(TMOD, CBIT3))
 Open timer starting gate. More...
 
#define is_timer0_mode1_gate_opened()   (test_if_bit_cleared(TMOD, SBIT3))
 Get timer starting gate state. More...
 

run in async mode

Timer run/stop/reload functions

#define timer0_mode1_start(ticks)
 Run timer0 in mode1. More...
 
#define timer0_mode1_direct_start(th0, tl0)
 Run timer0 in mode1 with direct set of TH0 and TL0 registers. More...
 
#define timer0_mode1_stop()
 Stop timer0. More...
 
#define is_timer0_mode1_started()   (TR0 == 1 && (is_timer0_mode1_gate_opened() || INT0 == 1))
 Get timer0 mode1 started status. More...
 

run in sync mode

Timer run once functions

#define timer0_mode1_delay(ticks)
 Run timer0 mode1 once and wait with program flow blocking timer not finished. More...
 

Detailed Description

Functions and data structures for timer0 mode1.

This module supports general purpose timer0. Timer can work as COUNTER or TIMER.

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

Timer0 Mode1 is like mode0 but without timer reloading and P35 pin output features.

For timer0 in mode1:

Timer0 in mode1 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_timer0_mode1_gate_opened

#define is_timer0_mode1_gate_opened ( )    (test_if_bit_cleared(TMOD, SBIT3))

Get timer starting gate state.

Returns
bool true if gate is open otherwise false

◆ is_timer0_mode1_started

#define is_timer0_mode1_started ( )    (TR0 == 1 && (is_timer0_mode1_gate_opened() || INT0 == 1))

Get timer0 mode1 started status.

Returns
bool true if started otherwise false

◆ timer0_mode1_12T_init

#define timer0_mode1_12T_init ( )
Value:
{ \
enable_mcu_interrupts(); \
enable_timer0_interrupt(); \
TMOD &= 0xf0; \
bit_set(TMOD, SBIT0); \
bit_clr(AUXR, CBIT7); \
}

Initialize mode1 12T for timer0.

◆ timer0_mode1_1T_init

#define timer0_mode1_1T_init ( )
Value:
{ \
enable_mcu_interrupts(); \
enable_timer0_interrupt(); \
TMOD &= 0xf0; \
bit_set(TMOD, SBIT0); \
bit_set(AUXR, SBIT7); \
}

Initialize mode1 1T for timer0.

◆ timer0_mode1_close_gate

#define timer0_mode1_close_gate ( )    (bit_set(TMOD, SBIT3))

Close timer starting gate.

When gate is closed timer will ticks after start only when INT0 pin is HIGH

◆ timer0_mode1_delay

#define timer0_mode1_delay (   ticks)
Value:
{ \
bool is_gate_opened = is_timer0_mode1_gate_opened(); \
/* Waiting for timer overloaded (timer overload flag set to 1) */ \
while(!TF0) \
{ \
} \
timer0_mode1_stop(); \
\
if (!is_gate_opened) \
{ \
timer0_mode1_close_gate(); \
} \
}
#define timer0_mode1_open_gate()
Open timer starting gate.
Definition: timer0_mode1.h:94
#define timer0_mode1_start(ticks)
Run timer0 in mode1.
Definition: timer0_mode1.h:127
#define is_timer0_mode1_gate_opened()
Get timer starting gate state.
Definition: timer0_mode1.h:103

Run timer0 mode1 once and wait with program flow blocking timer not finished.

Before run timer0_mode1_12T_init or timer0_mode1_1T_init should be called.

After run program flow blocked until timer does not overloaded.

Dont mix call of timer0_mode1_delay with timer0_mode1_open_gate/timer0_mode1_close_gate calls.

Parameters
ticksuint16_t timer ticks count.

◆ timer0_mode1_direct_start

#define timer0_mode1_direct_start (   th0,
  tl0 
)
Value:
{ \
TH0 = th0; \
TL0 - tl0; \
\
TF0 = 0; \
TR0 = 1; \
}

Run timer0 in mode1 with direct set of TH0 and TL0 registers.

Before run timer0_mode1_12T_init or timer0_mode1_1T_init should be called.

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

Timer rerun after overloaded and interupt handler called. Timer overload occurs on [TH0, TL0] = 0xff + 1.

Dont mix call timer0__mode1_direct_start call with void timer0_mode1_delay call

Parameters
th0uint8_t TH0 value
tl0uint8_t TL0 value

◆ timer0_mode1_open_gate

#define timer0_mode1_open_gate ( )    (bit_clr(TMOD, CBIT3))

Open timer starting gate.

When gate is open timer ticks after starts

◆ timer0_mode1_start

#define timer0_mode1_start (   ticks)
Value:
{ \
uint16_t value = 0xffff - ticks; \
/* Load timer high and low bytes value */ \
TL0 = value & 0xff; \
TH0 = (value >> 8) & 0xff; \
\
TF0 = 0; /* clear timer overload flag */ \
TR0 = 1; /* set run timer flag */ \
}

Run timer0 in mode1.

Before run timer0_mode1_12T_init or timer0_mode1_1T_init should be called.

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

Timer rerun after overloaded and interupt handler called.

Dont mix call timer0__mode1_start call with void timer0_mode1_delay call

Parameters
ticksuint16_t timer ticks count.

◆ timer0_mode1_stop

#define timer0_mode1_stop ( )
Value:
{ \
TR0 = 0; /* clear run timer flag */ \
TF0 = 0; /* clear timer overload flag */ \
}

Stop timer0.

Before stop timer1_start should be called. Dont mix timer1_stop call with timer0_mode1_delay call