STC15W408AS library 0.18.0
Loading...
Searching...
No Matches
pca.h
Go to the documentation of this file.
1#ifndef STC15_PCAH
2#define STC15_PCAH
3
49#include <bits.h>
50
52#define PCA_CPS0_BIT 1
54#define PCA_CPS_MASK 0x0E
56#define PCA_PWM_EBS0_BIT 6
58#define PCA_PWM_EBS_MASK 0xC0
59
61#define PCA_CCP_S0_BIT 4
63#define PCA_CCP_S0_MSK 0x10
65#define PCA_CCP_S1_MSK 0x20
67#define PCA_CCP_SW_MASK (uint8_t)(PCA_CCP_S0_MSK | PCA_CCP_S1_MSK)
68
86
114
136
137
142
154#define pca_set_pin_group(group) \
155do { \
156 bit_clr(P_SW1, PCA_CCP_SW_MASK); \
157 bit_set(P_SW1, (uint8_t)((group) << PCA_CCP_S0_BIT)); \
158} while(0)
159
167#define pca_get_pin_group() ((pca_pin_group_t)(bit_shift_right(get_reg(P_SW1, (PCA_CCP_S0_MSK | PCA_CCP_S1_MSK)), PCA_CCP_S0_BIT)))
168
170
175
185#define pca_set_clock_source(src) \
186do { \
187 bit_clr(CMOD, PCA_CPS_MASK); \
188 bit_set(CMOD, (uint8_t)((src) << PCA_CPS0_BIT)); \
189} while(0)
190
198#define pca_get_clock_source() ((pca_clock_source_t)(bit_shift_right(get_reg(CMOD, PCA_CPS_MASK), PCA_CPS0_BIT)))
199
208#define pca_set_counter(value) \
209do { \
210 CH = (uint8_t)bit_shift_right((uint16_t)(value), 8); \
211 CL = (uint8_t)(value); \
212} while(0)
213
221#define pca_get_counter() ((uint16_t)(bit_shift_left((uint16_t)CH, 8) | (uint16_t)CL))
222
230#define pca_start() (CR = 1)
231
238#define pca_stop() (CR = 0)
239
247#define is_pca_running() (CR)
248
256#define pca_counter_run_in_idle() (bit_clr(CMOD,SBIT7))
257
264#define pca_counter_gate_off_in_idle() (bit_set(CMOD, SBIT7))
265
273#define is_pca_counter_gated_off_in_idle() (test_if_bit_set(CMOD, SBIT7))
274
276
281
288#define pca_clear_overflow_flag() (CF = 0)
289
297#define is_pca_overflow() (CF)
298
307#define pca_enable_overflow_interrupt() (bit_set(CMOD, SBIT0))
308
315#define pca_disable_overflow_interrupt() (bit_clr(CMOD, SBIT0))
316
324#define is_pca_overflow_interrupt_enabled() (test_if_bit_set(CMOD, SBIT0))
325
327
332
342#define pca_clear_module_flag(module) (CCF ## module = 0)
343
354#define is_pca_module_flag_set(module) (CCF ## module)
355
366#define pca_module_enable_interrupt(module) (bit_set(CCAPM ## module, SBIT0))
367
376#define pca_module_disable_interrupt(module) (bit_clr(CCAPM ## module, SBIT0))
377
387#define is_pca_module_interrupt_enabled(module) (test_if_bit_set(CCAPM ## module, SBIT0))
388
390
395
405#define pca_module_enable_comparator(module) (bit_set(CCAPM ## module, SBIT6))
406
415#define pca_module_disable_comparator(module) (bit_clr(CCAPM ## module, SBIT6))
416
426#define pca_module_enable_capture_positive(module) (bit_set(CCAPM ## module, SBIT5))
427
436#define pca_module_disable_capture_positive(module) (bit_clr(CCAPM ## module, SBIT5))
437
447#define pca_module_enable_capture_negative(module) (bit_set(CCAPM ## module, SBIT4))
448
457#define pca_module_disable_capture_negative(module) (bit_clr(CCAPM ## module, SBIT4))
458
468#define pca_module_enable_match(module) (bit_set(CCAPM ## module, SBIT3))
469
478#define pca_module_disable_match(module) (bit_clr(CCAPM ## module, SBIT3))
479
489#define pca_module_enable_toggle(module) (bit_set(CCAPM ## module, SBIT2))
490
499#define pca_module_disable_toggle(module) (bit_clr(CCAPM ## module, SBIT2))
500
511#define pca_module_set_compare(module, value) \
512do { \
513 CCAP ## module ## H = (uint8_t)bit_shift_right((uint16_t)(value), 8); \
514 CCAP ## module ## L = (uint8_t)(value); \
515} while(0)
516
535#define pca_module_get_capture(module) ((uint16_t)(bit_shift_left((uint16_t)CCAP ## module ## H, 8) | (uint16_t)CCAP ## module ## L))
536
538
543
561#define pca_module_pwm_init(module, resolution) \
562do { \
563 bit_clr(PCA_PWM ## module, PCA_PWM_EBS_MASK); \
564 bit_set(PCA_PWM ## module, (uint8_t)((resolution) << PCA_PWM_EBS0_BIT)); \
565 bit_set(CCAPM ## module, SBIT1); \
566} while(0)
567
576#define pca_module_pwm_disable(module) (bit_clr(CCAPM ## module, SBIT1))
577
587#define is_pca_module_pwm_enabled(module) (test_if_bit_set(CCAPM ## module, SBIT1))
588
603#define pca_module_pwm_set_duty(module, duty) \
604do { \
605 CCAP ## module ## H = (uint8_t)(duty); \
606 CCAP ## module ## L = (uint8_t)(duty); \
607} while(0)
608
620#define pca_module_pwm_set_duty_on_overflow(module, duty) (CCAP ## module ## H = (uint8_t)(duty))
621
623
624#endif
pca_pwm_resolution_t
PCA module PWM output resolution.
Definition pca.h:128
pca_clock_source_t
PCA counter clock source.
Definition pca.h:96
pca_pin_group_t
PCA pin group.
Definition pca.h:78
@ PCA_PWM_7BIT
Definition pca.h:132
@ PCA_PWM_6BIT
Definition pca.h:134
@ PCA_PWM_8BIT
Definition pca.h:130
@ PCA_CLOCK_SYS_6
Definition pca.h:110
@ PCA_CLOCK_SYS
Definition pca.h:106
@ PCA_CLOCK_TIMER0
Definition pca.h:102
@ PCA_CLOCK_SYS_12
Definition pca.h:98
@ PCA_CLOCK_ECI
Definition pca.h:104
@ PCA_CLOCK_SYS_4
Definition pca.h:108
@ PCA_CLOCK_SYS_8
Definition pca.h:112
@ PCA_CLOCK_SYS_2
Definition pca.h:100
@ PCA_PIN_GROUP_1
Definition pca.h:80
@ PCA_PIN_GROUP_2
Definition pca.h:82
@ PCA_PIN_GROUP_3
Definition pca.h:84