STC15W408AS library 0.10.0
Loading...
Searching...
No Matches
Macros
Counter0 Mode 1

Macros

#define T0   P34
 T0 pin definition.
 

init

Counter initializaion functions

#define counter0_mode1_init()
 Initialize mode1 for counter0.
 

start/stop

Counter0 start/stop functions

#define counter0_mode1_start(value)
 Starts Counter 0 in Mode 1 with a specified initial value.
 
#define is_counter0_mode1_started()   (TR0 == 1)
 Check if counter0 is started.
 
#define counter0_mode1_stop()
 Stop counter0.
 

read

Counter read value functions

#define counter0_mode1_get_value()   ((((uint16_t) TH0) << 8) | TL0)
 Get counter0 value in mode1.
 

Detailed Description

Counter0 mode 1 routines.

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

Counter increments on T0 pin change state.

Counter0 Mode1 is 16-bit counter. Mode1 is like mode0 but without reloading and P35 pin output features.

Author
Michael Golovanov

Macro Definition Documentation

◆ counter0_mode1_get_value

#define counter0_mode1_get_value ( )    ((((uint16_t) TH0) << 8) | TL0)

Get counter0 value in mode1.

Returns
uint16_t counter value

◆ counter0_mode1_init

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

Initialize mode1 for counter0.

Enable counter0 interrupt and set mode1.

Mode 1 is configured as setting TMOD lowest 4 bytes:

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

◆ counter0_mode1_start

#define counter0_mode1_start (   value)
Value:
do { \
static_assert(value <= 0xffff, "value is too large"); \
\
const uint16_t _val = value; \
TH0 = (uint8_t) (_val >> 8); \
TL0 = (uint8_t) (_val & 0xFF); \
\
TF0 = 0; \
TR0 = 1; \
} while(0)

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

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

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

◆ counter0_mode1_stop

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

Stop counter0.

Stop counter0 and clear TF0 flag.

◆ is_counter0_mode1_started

#define is_counter0_mode1_started ( )    (TR0 == 1)

Check if counter0 is started.

Returns
true if counter0 started otherwise false