STC15W408AS library 0.10.0
Loading...
Searching...
No Matches
Macros
Counter2 Mode0

Macros

#define T2   P31
 T2 pin definition.
 

init

Counter initializaion functions

#define counter2_mode0_init()
 Initialize mode0 for counter2.
 

run

Counter run/stop/reload functions

#define counter2_mode0_start(value)
 Run counter2.
 
#define counter2_mode0_stop()
 Stop counter2.
 
#define is_counter2_mode0_started()   (test_if_bit_set(_AUXR, SBIT4))
 Get counter2 mode0 started status.
 

read/write

Counter2 get and set value functions

#define counter2_mode0_get_value()   ((((uint16_t) T2H) << 8) | T2L)
 get counter2 value in mode0
 
#define counter2_mode0_set_value(value)
 set counter2 value in mode0
 

config

Counter2 pin output and gate config functions

#define counter2_mode0_enable_P30_output()   (bit_set(INT_CLKO, SBIT2))
 enable output to P3.0
 
#define counter2_mode0_disable_P30_output()   (bit_clr(INT_CLKO, CBIT2))
 disable output to P3.0
 
#define is_counter2_mode0_P30_output_enabled()   (test_if_bit_set(INT_CLKO, SBIT2))
 get pin P3.0 output state to P3.0
 

Detailed Description

Functions and data structures for counter2 mode0.

This module supports general purpose counter2. Mode0 is auto reload 16-bit counter..

Counter2 increments its value on T0 pin change state from 0 to 1. Once the counter reaches its maximum value of 65535, the counter is reset to zero at the next increment. On counter overflow reset interrupt 1 is raised.

Author
Michael Golovanov

Macro Definition Documentation

◆ counter2_mode0_disable_P30_output

#define counter2_mode0_disable_P30_output ( )    (bit_clr(INT_CLKO, CBIT2))

disable output to P3.0

Disable pin P.3.0 state changes on counter2 overflow. By default P3.0 output is disabled

◆ counter2_mode0_enable_P30_output

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

enable output to P3.0

Enable pin P.3.0 state changes on counter2 overflow. By default P3.0 output is disabled

◆ counter2_mode0_get_value

#define counter2_mode0_get_value ( )    ((((uint16_t) T2H) << 8) | T2L)

get counter2 value in mode0

Returns
uint16_t counter value

◆ counter2_mode0_init

#define counter2_mode0_init ( )
Value:
do { \
enable_mcu_interrupts(); \
enable_timer2_interrupt(); \
\
bit_clr(AUXR, CBIT4); \
bit_set(AUXR, SBIT3); /* init Counter2 */ \
} while(0)

Initialize mode0 for counter2.

Enable counter2 interrupt and set mode0

◆ counter2_mode0_set_value

#define counter2_mode0_set_value (   value)
Value:
do { \
static_assert(value <= 0xffff, "value to large"); \
const uint16_t _val = (value); \
T2H = (uint8_t)(_val >> 8); \
T2L = (uint8_t)(_val & 0xff); \
} while(0)

set counter2 value in mode0

Call this method before counter2 started.

Parameters
valueuint16_t counter value to set

◆ counter2_mode0_start

#define counter2_mode0_start (   value)
Value:
do { \
counter2_mode0_set_value(value); \
\
bit_set(AUXR, SBIT4); \
} while (0);

Run counter2.

Before run counter2_mode0_init should be called. After run counter2 is counted T0 pin state change. Interrupt handler void timer0ISR(void) __interrupt(1) should be defined in user code.

Parameters
valueuint16_t initial counter value

◆ counter2_mode0_stop

#define counter2_mode0_stop ( )
Value:
do { \
bit_clr(AUXR, CBIT4); \
} while (0)

Stop counter2.

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

◆ is_counter2_mode0_P30_output_enabled

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

get pin P3.0 output state to P3.0

Returns
true if P3.0 output enabled otherwise false

◆ is_counter2_mode0_started

#define is_counter2_mode0_started ( )    (test_if_bit_set(_AUXR, SBIT4))

Get counter2 mode0 started status.

Returns
bool true if started otherwise false