32 #ifndef __STC8x_PCA_H_
33 #define __STC8x_PCA_H_
44 #if (PER_LIB_MCU_MUODEL == STC8Ax)
46 #elif (PER_LIB_MCU_MUODEL == STC8Cx)
48 #elif (PER_LIB_MCU_MUODEL == STC8Fx)
50 #elif (PER_LIB_MCU_MUODEL == STC8Gx)
52 #elif (PER_LIB_MCU_MUODEL == STC8Hx)
61 #ifndef PER_LIB_MCU_MUODEL
64 #define PER_LIB_MCU_MUODEL STC8Ax
68 #ifndef PER_LIB_PCA_CTRL
71 #define PER_LIB_PCA_CTRL 1
75 #ifndef PER_LIB_PCA_INIT_CTRL
78 #define PER_LIB_PCA_INIT_CTRL 1
82 #ifndef PER_LIB_PCA_NVIC_CTRL
85 #define PER_LIB_PCA_NVIC_CTRL 1
89 #ifndef PER_LIB_PCA_WORK_CTRL
92 #define PER_LIB_PCA_WORK_CTRL 1
171 #if ( PER_LIB_PCA_CTRL == 1)
173 #if (PER_LIB_MCU_MUODEL == STC8Ax || PER_LIB_MCU_MUODEL == STC8Gx)
175 #if ( PER_LIB_PCA_INIT_CTRL == 1)
222 #if (PER_LIB_MCU_MUODEL == STC8Ax)
267 #if (PER_LIB_MCU_MUODEL == STC8Ax)
312 #if (PER_LIB_MCU_MUODEL == STC8Ax)
356 #if (PER_LIB_MCU_MUODEL == STC8Ax)
372 #if ( PER_LIB_PCA_WORK_CTRL == 1 )
401 #if (PER_LIB_MCU_MUODEL == STC8Ax)
418 #define PCA0_WORK_STOP() do{CCAPM0 = 0;}while(0)
425 #define PCA1_WORK_STOP() do{CCAPM1 = 0;}while(0)
432 #define PCA2_WORK_STOP() do{CCAPM2 = 0;}while(0)
435 #if (PER_LIB_MCU_MUODEL == STC8Ax)
441 #define PCA3_WORK_STOP() do{CCAPM3 = 0;}while(0)
452 #define PCA0_PWM_6BITS_CTRL(duty) \
454 CCAPM0 = PCA_TYPE_PWM; \
455 PCA_PWM0 = (PCA_PWM0 & 0x3F)|(0x02 << 6); \
456 PCA_PWM0 = (PCA_PWM0 & 0XFE) | ((duty & 0x40) >> 6); \
457 PCA_PWM0 = (PCA_PWM0 & 0XFD) | ((duty & 0x40) >> 5); \
458 CCAP0L = (uint8_t)(duty & 0x003F); \
459 CCAP0H = (uint8_t)(duty & 0x003F); \
469 #define PCA0_PWM_7BITS_CTRL(duty) \
471 CCAPM0 = PCA_TYPE_PWM; \
472 PCA_PWM0 = (PCA_PWM0 & 0x3F)|(0x01 << 6); \
473 PCA_PWM0 = (PCA_PWM0 & 0XFE) | ((duty & 0x80) >> 7); \
474 PCA_PWM0 = (PCA_PWM0 & 0XFD) | ((duty & 0x80) >> 6); \
475 CCAP0L = (uint8_t)(duty & 0x007F); \
476 CCAP0H = (uint8_t)(duty & 0x007F); \
486 #define PCA0_PWM_8BITS_CTRL(duty) \
488 CCAPM0 = PCA_TYPE_PWM; \
489 PCA_PWM0 = (PCA_PWM0 & 0x3F)|(0x00 << 6); \
490 PCA_PWM0 = (PCA_PWM0 & 0XFE) | ((duty & 0x100) >> 8); \
491 PCA_PWM0 = (PCA_PWM0 & 0XFD) | ((duty & 0x100) >> 7); \
492 CCAP0L = (uint8_t)duty; \
493 CCAP0H = (uint8_t)duty; \
503 #define PCA0_PWM_10BITS_CTRL(duty) \
505 CCAPM0 = PCA_TYPE_PWM; \
506 PCA_PWM0 = (PCA_PWM0 & 0x3F)|(0x03 << 6); \
507 PCA_PWM0 = (PCA_PWM0 & 0XFE) | ((duty & 0x400) >> 10); \
508 PCA_PWM0 = (PCA_PWM0 & 0XFD) | ((duty & 0x400) >> 9); \
509 PCA_PWM0 = (PCA_PWM0 & 0XF3) | ((duty & 0x300) >> 6); \
510 PCA_PWM0 = (PCA_PWM0 & 0XCF) | ((duty & 0x300) >> 4); \
511 CCAP0L = (uint8_t)duty; \
512 CCAP0H = (uint8_t)duty; \
522 #define PCA1_PWM_6BITS_CTRL(duty) \
524 CCAPM1 = PCA_TYPE_PWM; \
525 PCA_PWM1 = (PCA_PWM1 & 0x3F)|(0x02 << 6); \
526 PCA_PWM1 = (PCA_PWM1 & 0XFE) | ((duty & 0x40) >> 6); \
527 PCA_PWM1 = (PCA_PWM1 & 0XFD) | ((duty & 0x40) >> 5); \
528 CCAP1L = (uint8_t)(duty & 0x003F); \
529 CCAP1H = (uint8_t)(duty & 0x003F); \
539 #define PCA1_PWM_7BITS_CTRL(duty) \
541 CCAPM1 = PCA_TYPE_PWM; \
542 PCA_PWM1 = (PCA_PWM1 & 0x3F)|(0x01 << 6); \
543 PCA_PWM1 = (PCA_PWM1 & 0XFE) | ((duty & 0x80) >> 7); \
544 PCA_PWM1 = (PCA_PWM1 & 0XFD) | ((duty & 0x80) >> 6); \
545 CCAP1L = (uint8_t)(duty & 0x007F); \
546 CCAP1H = (uint8_t)(duty & 0x007F); \
556 #define PCA1_PWM_8BITS_CTRL(duty) \
558 CCAPM1 = PCA_TYPE_PWM; \
559 PCA_PWM1 = (PCA_PWM1 & 0x3F)|(0x00 << 6); \
560 PCA_PWM1 = (PCA_PWM1 & 0XFE) | ((duty & 0x100) >> 8); \
561 PCA_PWM1 = (PCA_PWM1 & 0XFD) | ((duty & 0x100) >> 7); \
562 CCAP1L = (uint8_t)duty; \
563 CCAP1H = (uint8_t)duty; \
573 #define PCA1_PWM_10BITS_CTRL(duty) \
575 CCAPM1 = PCA_TYPE_PWM; \
576 PCA_PWM1 = (PCA_PWM1 & 0x3F)|(0x03 << 6); \
577 PCA_PWM1 = (PCA_PWM1 & 0XFE) | ((duty & 0x400) >> 10); \
578 PCA_PWM1 = (PCA_PWM1 & 0XFD) | ((duty & 0x400) >> 9); \
579 PCA_PWM1 = (PCA_PWM1 & 0XF3) | ((duty & 0x300) >> 6); \
580 PCA_PWM1 = (PCA_PWM1 & 0XCF) | ((duty & 0x300) >> 4); \
581 CCAP1L = (uint8_t)duty; \
582 CCAP1H = (uint8_t)duty; \
592 #define PCA2_PWM_6BITS_CTRL(duty) \
594 CCAPM2 = PCA_TYPE_PWM; \
595 PCA_PWM2 = (PCA_PWM2 & 0x3F)|(0x02 << 6); \
596 PCA_PWM2 = (PCA_PWM2 & 0XFE) | ((duty & 0x40) >> 6); \
597 PCA_PWM2 = (PCA_PWM2 & 0XFD) | ((duty & 0x40) >> 5); \
598 CCAP2L = (uint8_t)(duty & 0x003F); \
599 CCAP2H = (uint8_t)(duty & 0x003F); \
609 #define PCA2_PWM_7BITS_CTRL(duty) \
611 CCAPM2 = PCA_TYPE_PWM; \
612 PCA_PWM2 = (PCA_PWM2 & 0x3F)|(0x01 << 6); \
613 PCA_PWM2 = (PCA_PWM2 & 0XFE) | ((duty & 0x80) >> 7); \
614 PCA_PWM2 = (PCA_PWM2 & 0XFD) | ((duty & 0x80) >> 6); \
615 CCAP2L = (uint8_t)(duty & 0x007F); \
616 CCAP2H = (uint8_t)(duty & 0x007F); \
626 #define PCA2_PWM_8BITS_CTRL(duty) \
628 CCAPM2 = PCA_TYPE_PWM; \
629 PCA_PWM2 = (PCA_PWM2 & 0x3F)|(0x00 << 6); \
630 PCA_PWM2 = (PCA_PWM2 & 0XFE) | ((duty & 0x100) >> 8); \
631 PCA_PWM2 = (PCA_PWM2 & 0XFD) | ((duty & 0x100) >> 7); \
632 CCAP2L = (uint8_t)duty; \
633 CCAP2H = (uint8_t)duty; \
643 #define PCA2_PWM_10BITS_CTRL(duty) \
645 CCAPM2 = PCA_TYPE_PWM; \
646 PCA_PWM2 = (PCA_PWM2 & 0x3F)|(0x03 << 6); \
647 PCA_PWM2 = (PCA_PWM2 & 0XFE) | ((duty & 0x400) >> 10); \
648 PCA_PWM2 = (PCA_PWM2 & 0XFD) | ((duty & 0x400) >> 9); \
649 PCA_PWM2 = (PCA_PWM2 & 0XF3) | ((duty & 0x300) >> 6); \
650 PCA_PWM2 = (PCA_PWM2 & 0XCF) | ((duty & 0x300) >> 4); \
651 CCAP2L = (uint8_t)duty; \
652 CCAP2H = (uint8_t)duty; \
656 #if (PER_LIB_MCU_MUODEL == STC8Ax)
664 #define PCA3_PWM_6BITS_CTRL(duty) \
666 CCAPM3 = PCA_TYPE_PWM; \
667 PCA_PWM3 = (PCA_PWM3 & 0x3F)|(0x02 << 6); \
668 PCA_PWM3 = (PCA_PWM3 & 0XFE) | ((duty & 0x40) >> 6); \
669 PCA_PWM3 = (PCA_PWM3 & 0XFD) | ((duty & 0x40) >> 5); \
670 CCAP3L = (uint8_t)(duty & 0x003F); \
671 CCAP3H = (uint8_t)(duty & 0x003F); \
681 #define PCA3_PWM_7BITS_CTRL(duty) \
683 CCAPM3 = PCA_TYPE_PWM; \
684 PCA_PWM3 = (PCA_PWM3 & 0x3F)|(0x01 << 6); \
685 PCA_PWM3 = (PCA_PWM3 & 0XFE) | ((duty & 0x80) >> 7); \
686 PCA_PWM3 = (PCA_PWM3 & 0XFD) | ((duty & 0x80) >> 6); \
687 CCAP3L = (uint8_t)(duty & 0x007F); \
688 CCAP3H = (uint8_t)(duty & 0x007F); \
698 #define PCA3_PWM_8BITS_CTRL(duty) \
700 CCAPM3 = PCA_TYPE_PWM; \
701 PCA_PWM3 = (PCA_PWM3 & 0x3F)|(0x00 << 6); \
702 PCA_PWM3 = (PCA_PWM3 & 0XFE) | ((duty & 0x100) >> 8); \
703 PCA_PWM3 = (PCA_PWM3 & 0XFD) | ((duty & 0x100) >> 7); \
704 CCAP3L = (uint8_t)duty; \
705 CCAP3H = (uint8_t)duty; \
715 #define PCA3_PWM_10BITS_CTRL(duty) \
717 CCAPM3 = PCA_TYPE_PWM; \
718 PCA_PWM3 = (PCA_PWM3 & 0x3F)|(0x03 << 6); \
719 PCA_PWM3 = (PCA_PWM3 & 0XFE) | ((duty & 0x400) >> 10); \
720 PCA_PWM3 = (PCA_PWM3 & 0XFD) | ((duty & 0x400) >> 9); \
721 PCA_PWM3 = (PCA_PWM3 & 0XF3) | ((duty & 0x300) >> 6); \
722 PCA_PWM3 = (PCA_PWM3 & 0XCF) | ((duty & 0x300) >> 4); \
723 CCAP3L = (uint8_t)duty; \
724 CCAP3H = (uint8_t)duty; \
741 #if ( PER_LIB_PCA_INIT_CTRL == 1)
784 #if (PER_LIB_MCU_MUODEL == STC8Ax)
832 #if (PER_LIB_MCU_MUODEL == STC8Ax)
852 #define PCA_CNT_GET_FLAG() (CF)
859 #define PCA_CNT_CLEAR_FLAG() do{CF = 0;}while(0)
867 #define PCA0_GET_FLAG() (CCF0)
875 #define PCA1_GET_FLAG() (CCF1)
883 #define PCA2_GET_FLAG() (CCF2)
886 #if (PER_LIB_MCU_MUODEL == STC8Ax)
893 #define PCA3_GET_FLAG() (CCF3)
901 #define PCA0_CLEAR_FLAG() do{CCF0 = 0;}while(0)
908 #define PCA1_CLEAR_FLAG() do{CCF1 = 0;}while(0)
915 #define PCA2_CLEAR_FLAG() do{CCF2 = 0;}while(0)
918 #if (PER_LIB_MCU_MUODEL == STC8Ax)
925 #define PCA3_CLEAR_FLAG() do{CCF3 = 0;}while(0)
934 #define NVIC_PCA_CNT_CTRL(run) \
936 CMOD = (CMOD & 0xFE) | run; \
945 #define NVIC_PCA_PRI(pri) \
947 IPH = (IPH & 0x7F) | ((pri & 0x02) << 6); \
948 IP = (IP & 0x7F) | ((pri & 0x01) << 7); \
957 #define NVIC_PCA0_CTRL(run) \
959 CCAPM0 = (CCAPM0 & 0xFE) | (run); \
968 #define NVIC_PCA1_CTRL(run) \
970 CCAPM1 = (CCAPM1 & 0xFE) | (run); \
979 #define NVIC_PCA2_CTRL(run) \
981 CCAPM2 = (CCAPM2 & 0xFE) | (run); \
984 #if (PER_LIB_MCU_MUODEL == STC8Ax)
991 #define NVIC_PCA3_CTRL(run) \
993 CCAPM3 = (CCAPM3 & 0xFE) | (run); \
NVICPri_Type
Definition: ELL_CORE.h:99
BOOL
Definition: ELL_CORE.h:50
FSCSTATE
Definition: ELL_CORE.h:65
GPIOSWPort_Type
Definition: ELL_CORE.h:81
unsigned int uint16_t
Definition: ELL_TYPE.h:73
PCA_CAPMode_Type
PCA做CAP时,触发模式枚举体。
Definition: STC8x_PCA.h:114
@ PCA_CAP_Mode_Rising
Definition: STC8x_PCA.h:116
@ PCA_CAP_Mode_Falling
Definition: STC8x_PCA.h:115
@ PCA_CAP_Mode_Edge
Definition: STC8x_PCA.h:117
PCACLKSrc_Type
PCA时钟源枚举体
Definition: STC8x_PCA.h:126
@ PCA_SCLK_DIV_1
Definition: STC8x_PCA.h:131
@ PCA_SCLK_DIV_6
Definition: STC8x_PCA.h:133
@ PCA_SCLK_DIV_8
Definition: STC8x_PCA.h:134
@ PCA_TIMER0
Definition: STC8x_PCA.h:129
@ PCA_SCLK_DIV_4
Definition: STC8x_PCA.h:132
@ PCA_SCLK_DIV_2
Definition: STC8x_PCA.h:128
@ PCA_SCLK_DIV_12
Definition: STC8x_PCA.h:127
@ PCA_ECI
Definition: STC8x_PCA.h:130
PCA_PWMBits_Type
PCA做PWM时,分辨率枚举体。
Definition: STC8x_PCA.h:143
@ PCA_PWM_6Bits
Definition: STC8x_PCA.h:146
@ PCA_PWM_10Bits
Definition: STC8x_PCA.h:147
@ PCA_PWM_7Bits
Definition: STC8x_PCA.h:145
@ PCA_PWM_8Bits
Definition: STC8x_PCA.h:144
FSCSTATE GPIO_PCA_SWPort(GPIOSWPort_Type port)
PCA切换复用IO函数。
FSCSTATE NVIC_PCA1_PWM_CAP_Init(PCA_CAPTri_Type triMode, BOOL run)
PCA1做PWM或CAP中断初始化函数。
void PCA3_TIM_POP_ReValue(void)
PCA3做TIMER或POP时,重载载计数器。
void PCA2_TIM_POP_ReValue(void)
PCA2做TIMER或POP时,重载载计数器。
FSCSTATE PCA3_POP_Init(uint16_t fre)
PCA3做POP初始化,必须放在PCA计数器初始化之前。
FSCSTATE NVIC_PCA3_PWM_CAP_Init(PCA_CAPTri_Type triMode, BOOL run)
PCA3做PWM或CAP中断初始化函数。
FSCSTATE NVIC_PCA_CNT_Init(NVICPri_Type pri, BOOL run)
PCA计数器中断初始化函数。
void PCA0_TIM_POP_ReValue(void)
PCA0做TIMER或POP时,重载载计数器。
FSCSTATE NVIC_PCA1_TIM_POP_Init(BOOL run)
PCA1做TIMER或POP中断初始化函数。
FSCSTATE PCA1_POP_Init(uint16_t fre)
PCA1做POP初始化,必须放在PCA计数器初始化之前。
FSCSTATE NVIC_PCA3_TIM_POP_Init(BOOL run)
PCA3做TIMER或POP中断初始化函数。
FSCSTATE PCA0_TIM_Init(uint16_t time)
PCA0做TIMER初始化,必须放在PCA计数器初始化之前。
FSCSTATE PCA2_CAP_Init(PCA_CAPMode_Type mode)
PCA2做CAP初始化,必须放在PCA计数器初始化之前。
FSCSTATE PCA_CNT_Init(PCACLKSrc_Type clkSrc, BOOL run)
PCA计数器初始化,必须放在所有PCA函数的后面。
FSCSTATE PCA2_PWM_Init(PCA_PWMBits_Type pwmBits, uint16_t duty)
PCA2做PWM初始化,必须放在PCA计数器初始化之前。
FSCSTATE PCA3_TIM_Init(uint16_t time)
PCA3做TIMER初始化,必须放在PCA计数器初始化之前。
FSCSTATE PCA0_POP_Init(uint16_t fre)
PCA0做POP初始化,必须放在PCA计数器初始化之前。
FSCSTATE NVIC_PCA0_PWM_CAP_Init(PCA_CAPTri_Type triMode, BOOL run)
PCA0做PWM或CAP中断初始化函数。
void PCA1_TIM_POP_ReValue(void)
PCA1做TIMER或POP时,重载载计数器。
FSCSTATE PCA0_CAP_Init(PCA_CAPMode_Type mode)
PCA0做CAP初始化,必须放在PCA计数器初始化之前。
FSCSTATE PCA3_CAP_Init(PCA_CAPMode_Type mode)
PCA3做CAP初始化,必须放在PCA计数器初始化之前。
FSCSTATE NVIC_PCA2_PWM_CAP_Init(PCA_CAPTri_Type triMode, BOOL run)
PCA2做PWM或CAP中断初始化函数。
FSCSTATE PCA2_TIM_Init(uint16_t time)
PCA2做TIMER初始化,必须放在PCA计数器初始化之前。
FSCSTATE PCA1_PWM_Init(PCA_PWMBits_Type pwmBits, uint16_t duty)
PCA1做PWM初始化,必须放在PCA计数器初始化之前。
FSCSTATE NVIC_PCA0_TIM_POP_Init(BOOL run)
PCA0做TIMER或POP中断初始化函数。
PCAType_Type
PCA工作类型枚举体
Definition: STC8x_PCA.h:101
@ PCA_TYPE_TIM
Definition: STC8x_PCA.h:104
@ PCA_TYPE_POP
Definition: STC8x_PCA.h:105
@ PCA_TYPE_PWM
Definition: STC8x_PCA.h:103
@ PCA_TYPE_CAP
Definition: STC8x_PCA.h:102
FSCSTATE PCA2_POP_Init(uint16_t fre)
PCA2做POP初始化,必须放在PCA计数器初始化之前。
FSCSTATE NVIC_PCA2_TIM_POP_Init(BOOL run)
PCA2做TIMER或POP中断初始化函数。
FSCSTATE PCA1_TIM_Init(uint16_t time)
PCA1做TIMER初始化,必须放在PCA计数器初始化之前。
FSCSTATE PCA3_PWM_Init(PCA_PWMBits_Type pwmBits, uint16_t duty)
PCA3做PWM初始化,必须放在PCA计数器初始化之前。
FSCSTATE PCA1_CAP_Init(PCA_CAPMode_Type mode)
PCA1做CAP初始化,必须放在PCA计数器初始化之前。
PCA_CAPTri_Type
PCA做CAP时,触发中断方式枚举体。
Definition: STC8x_PCA.h:156
@ PCA_CAPTri_Falling
Definition: STC8x_PCA.h:159
@ PCA_CAPTri_Null
Definition: STC8x_PCA.h:157
@ PCA_CAPTri_Rising
Definition: STC8x_PCA.h:161
@ PCA_CAPTri_Edge
Definition: STC8x_PCA.h:163
FSCSTATE PCA0_PWM_Init(PCA_PWMBits_Type pwmBits, uint16_t duty)
PCA0做PWM初始化,必须放在PCA计数器初始化之前。