1 
2 
3 
4 #ifndef __CH57x_PWM_H__
5 #define __CH57x_PWM_H__
6 
7 #ifdef __cplusplus
8  extern "C" {
9 #endif
10 
11 #include "CH579SFR.h"
12 #include "core_cm0.h"
13 
14 /**
15   * @brief  channel of PWM define
16   */
17 
18 #define CH_PWM4     0x01                // PWM4 通道
19 #define CH_PWM5     0x02                // PWM5 通道
20 #define CH_PWM6     0x04                // PWM6 通道
21 #define CH_PWM7     0x08                // PWM7 通道
22 #define CH_PWM8     0x10                // PWM8 通道
23 #define CH_PWM9     0x20                // PWM9 通道
24 #define CH_PWM10    0x40                // PWM10 通道
25 #define CH_PWM11    0x80                // PWM11 通道
26 
27 
28 
29 /**
30   * @brief  channel of PWM define
31   */
32 typedef enum
33 {
34     High_Level = 0,                     // 默认低电平,高电平有效
35     Low_Level,                          // 默认高电平,低电平有效
36 }PWMX_PolarTypeDef;
37 
38 
39 /**
40   * @brief  Configuration PWM4_11 Cycle size
41   */
42 typedef enum
43 {
44     PWMX_Cycle_256 = 0,                 // 256 个PWMX周期
45     PWMX_Cycle_255,                     // 255 个PWMX周期
46     PWMX_Cycle_128,                     // 128 个PWMX周期
47     PWMX_Cycle_127,                     // 127 个PWMX周期
48     PWMX_Cycle_64,                      // 64 个PWMX周期
49     PWMX_Cycle_63,                      // 63 个PWMX周期
50     PWMX_Cycle_32,                      // 32 个PWMX周期
51     PWMX_Cycle_31,                      // 31 个PWMX周期
52 }PWMX_CycleTypeDef;
53 
54 
55 #define PWMX_CLKCfg( d )            (R8_PWM_CLOCK_DIV=d)                /* PWM4-PWM11 通道基准时钟配置,= d*Tsys */
56 void PWMX_CycleCfg( PWMX_CycleTypeDef cyc );                            /* PWM4-PWM11 通道输出波形周期配置 */
57 
58 #define PWM4_ActDataWidth( d )      (R8_PWM4_DATA = d)                  /* PWM4 有效数据脉宽 */
59 #define PWM5_ActDataWidth( d )      (R8_PWM5_DATA = d)                  /* PWM5 有效数据脉宽 */
60 #define PWM6_ActDataWidth( d )      (R8_PWM6_DATA = d)                  /* PWM6 有效数据脉宽 */
61 #define PWM7_ActDataWidth( d )      (R8_PWM7_DATA = d)                  /* PWM7 有效数据脉宽 */
62 #define PWM8_ActDataWidth( d )      (R8_PWM8_DATA = d)                  /* PWM8 有效数据脉宽 */
63 #define PWM9_ActDataWidth( d )      (R8_PWM9_DATA = d)                  /* PWM9 有效数据脉宽 */
64 #define PWM10_ActDataWidth( d )     (R8_PWM10_DATA = d)                 /* PWM10 有效数据脉宽 */
65 #define PWM11_ActDataWidth( d )     (R8_PWM11_DATA = d)                 /* PWM11 有效数据脉宽 */
66 
67 // 占空比 = 数据有效脉宽/波形周期
68 void PWMX_ACTOUT( UINT8 ch, UINT8 da, PWMX_PolarTypeDef pr, UINT8 s);   /* PWM4-PWM11通道输出波形配置 */
69 void PWMX_AlterOutCfg( UINT8 ch, UINT8 s);          /* PWM 交替输出模式配置 */
70 
71 
72 
73 
74 
75 #ifdef __cplusplus
76 }
77 #endif
78 
79 #endif  // __CH57x_PWM_H__
80 
81