STC15W408AS library 0.12.0
Loading...
Searching...
No Matches
Macros
Counter0 Mode2

Macros

#define T0   P34
 T0 pin definition.
 
#define INT0   P32
 INT0 pin definition.
 

init

Counter initializaion functions

#define counter0_mode2_init()
 Initialize mode2 for counter0.
 

start/stop

Counter0 start/stop functions

#define counter0_mode2_start(value)
 Starts Counter 0 in Mode 2 with a specified initial value.
 
#define counter0_mode2_stop()
 Stop counter0.
 
#define is_counter0_mode2_started()   (TR0 == 1 && (is_counter0_mode2_gate_opened() || INT0 == 1) )
 Get counter0 mode2 started status.
 

read/write

Counter get and set value functions

#define counter0_mode2_get_value()   (TL0)
 get counter0 value in mode2
 
#define counter0_mode2_set_value(value)
 set counter0 value in mode2
 

config

Counter0 pin output and gate config functions

#define counter0_mode2_enable_P35_output()   (bit_set(INT_CLKO, SBIT0))
 enable output to P3.5
 
#define counter0_mode2_disable_P35_output()   (bit_clr(INT_CLKO, CBIT0))
 disable output to P3.5
 
#define is_counter0_mode2_P35_output_enabled()   (test_if_bit_set(INT_CLKO, SBIT0))
 get pin P3.5 output state to P3.5
 
#define counter0_mode2_open_gate()   (bit_clr(TMOD, CBIT3))
 Open counter0 gate.
 
#define counter0_mode2_close_gate()   (bit_set(TMOD, SBIT3))
 Close counter0 gate.
 
#define is_counter0_mode2_gate_opened()   (test_if_bit_cleared(TMOD, SBIT3))
 Get gate state.
 

Detailed Description

Counter0 mode 2 routines. This module supports general purpose counter0. Timer can work as COUNTER or TIMER.

Counter increments on T0 pin change state.

Counter0 Mode2 is 8-bit autoreloadable counter.

Author
Michael Golovanov

Macro Definition Documentation

◆ counter0_mode2_close_gate

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

Close counter0 gate.

Closing gate stop counter0.

◆ counter0_mode2_disable_P35_output

#define counter0_mode2_disable_P35_output ( )    (bit_clr(INT_CLKO, CBIT0))

disable output to P3.5

Disable pin P.3.5 state changes on counter0 overflow. By default P3.5 output is disabled

◆ counter0_mode2_enable_P35_output

#define counter0_mode2_enable_P35_output ( )    (bit_set(INT_CLKO, SBIT0))

enable output to P3.5

Enable pin P.3.5 state changes on counter0 overflow. By default P3.5 output is disabled

◆ counter0_mode2_get_value

#define counter0_mode2_get_value ( )    (TL0)

get counter0 value in mode2

Returns
uint8_t counter value

◆ counter0_mode2_init

#define counter0_mode2_init ( )
Value:
do { \
enable_mcu_interrupts(); \
enable_timer0_interrupt(); \
\
TMOD &= 0xF0; \
TMOD |= 0x06; \
\
TF0 = 0; \
TR0 = 0; \
} while(0)

Initialize mode2 for counter0.

Enable counter0 interrupt and set mode2.

Mode2 is configured as setting TMOD lowest 4 bytes:

  • TMOD.0 = 0
  • TMOD.1 = 1
  • TMOD.2 = 1
  • TMOD.3 = 0
Attention
Interrupt handler void counter0ISR(void) __interrupt(1) should be defined in user code.

◆ counter0_mode2_open_gate

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

Open counter0 gate.

When gate is opened counter0 will count. By default after init gate is opened. This routine explicitly open the gate.

◆ counter0_mode2_set_value

#define counter0_mode2_set_value (   value)
Value:
do { \
static_assert(value <= 0xff, "value is too large"); \
TH0 = value; \
} while(0)

set counter0 value in mode2

Call this method before counter0 started.

Parameters
valueuint8_t counter value to set

◆ counter0_mode2_start

#define counter0_mode2_start (   value)
Value:
do { \
static_assert(value <= 0xff, "value is too large"); \
\
TH0 = (uint8_t) value; \
\
TF0 = 0; \
TR0 = 1; \
} while(0)

Starts Counter 0 in Mode 2 with a specified initial value.

Loads the initial 8-bit value into Counter 0 registers and starts the counter.

Attention
Before calling this function, counter0_mode2_init() should be called.
Parameters
value8-bit unsigned integer specifying the initial counter count

◆ counter0_mode2_stop

#define counter0_mode2_stop ( )
Value:
do { \
TR0 = 0; \
} while (0)

Stop counter0.

Stop count T0 pin state changes. Before stop counter0_mode2_start should be called.

◆ is_counter0_mode2_gate_opened

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

Get gate state.

returns bool. True if gate is opened and false if gate is closed

◆ is_counter0_mode2_P35_output_enabled

#define is_counter0_mode2_P35_output_enabled ( )    (test_if_bit_set(INT_CLKO, SBIT0))

get pin P3.5 output state to P3.5

Returns
true if P3.5 output enabled otherwise false

◆ is_counter0_mode2_started

#define is_counter0_mode2_started ( )    (TR0 == 1 && (is_counter0_mode2_gate_opened() || INT0 == 1) )

Get counter0 mode2 started status.

Returns
bool true if started otherwise false