STC15系列PWM中断控制寄存器介绍以及PWM呼吸灯代码实现
- 📌相关篇《STC15系列PWM功能相关功能寄存器介绍》
- ✨以下数据来源于stc15手册。
📓增强型PWM波形发生器的中断控制
1.PWM中断优先级控制寄存器:IP2
- PPWMFD:PWM异常检测中断优先级控制位。
当PPWMFD=0时,PWM异常检测中断为最低优先级中断(优先级0)
当PPWMFD-1时,PWM异常检测中断为最高优先级中断(优先级1) - PPWM: PWM中断优先级控制位。
当PPWM=0时,PWM中断为最低优先级中断(优先级0)
当PPWM=1时,PWM中断为最高优先级中断(优先级1
中断优先级控制寄存器IP和IP2的各位都由可用户程序置“1”和清“0”。但IP寄存器可位操作,所以可用位操作指令或字节操作指令更新IP的内容。而IP2寄存器的内容只能用字节操作指令来更新。STC15系列单片机复位后IP和IP2均为00H,各个中断源均为低优先级中断。
2. PWM控制寄存器:PWMCR
- ECBI :PWM计数器归零中断使能位
0:关闭PWM计数器归零中断(CBIF依然会被硬件置位)
1:使能PWM计数器归零中断
3. PWM中断标志寄存器:PWMIF
- CBIF :PWM计数器归零中断标志位
当PWM计数器归零时,硬件自动将此位置1。当ECBI==1时,程序会跳转到相应中断
入口执行中断服务程序。需要软件清零。 - C7IF :第7通道的PWM中断标志位
可设置在翻转点1和翻转点2触发C7IF(详见EC7T1SI和EC7T2SI)。当PWM发生翻转时,硬件自动将此位置1。当EPWM7I==1时,程序会跳转到相应中断入口执行中断服务程序。需要软件清零。 - C6IF:第6通道的PWM中断标志位
可设置在翻转点1和翻转点2触发C6IF (详见EC6TISI和EC6T2SI)当PWM发生翻转时,硬件自动将此位置1。程序会跳转到相应中断入口执行中断服务程序。需要软件清零。 - C5IF:第S通道的PWM中断标志位
可设置在翻转点1和翻转点2触发CSIF(详见ECSTISI和ECST2SI) 。当PWM发生翻转当EPWMSI–1时,程序会跳转到相应中断入口执行中断服时,硬件自动将此位置1。务程序。需要软件清零。 - C4IF:第4通道的PWM中断标志位
可设置在翻转点1和翻转点2触发C4IF (详见EC4TISI和EC4T2SI) 。当PWM发生翻转时,硬件自动将此位置1。当EPWM4–1时,程序会跳转到相应中断入口执行中断服务程序。需要软件清零。 - C3FF:第3通道的PWM中断标志位
可设置在翻转点1和翻转点2触发C3IF (详见EC3TISI和EC3T2SI) 。当PWM发生翻转时,硬件自动将此位置1。当EPWM3I–1时,程序会跳转到相应中断入口执行中断服务程序。需要软件清零。 - C2IF:第2通道的PWM中断标志位
可设置在翻转点1和翻转点2触发C2IF (详见EC2T1SI和EC2T2SI) 。当PWM发生翻转时,硬件自动将此位置1。当EPWM2I–1时,程序会跳转到相应中断入口执行中断服务程序。需要软件清零。
4. PWM外部异常控制寄存器:PWMFDCR
- EFDI :PWM异常检测中断使能位
0:关闭PWM异常检测中断(FDIF�然会被硬件置位)
1:使能PWM异常检测中断 - FDIF :PWM异常检测中断标志位
当发生PWM异常(比较器正极P5.5/CMP+的电平比比较器负极P5.4/CMP-的电平高
或比较器正极 比较器正极P5.5/CMP+的电平比内部参考电压源1.28V高或者P2.4的电平为高) 为高)
时,硬件自动将此位置1。当EFDI==1时,程序会跳转到相应中断入口执行中断服务程序。需要软件清零。
5. PWM2的控制寄存器:PWM2CR
- EPWM2I :PWM2中断使能控制位
0:关闭PWM2中断
1:使能PWM2中断,当C2IF被硬件置1时,程序将跳转到相应中断入口执行中断服务程序。 - EC2T2SI:PWM2的T2匹配发生波形翻转时的中断控制位
0:关闭T2翻转时中断
1:使能T2翻转时中断,当PWM波形发生器内部计数值与T2计数器所设定的值相匹配时,PWM的波形发生翻转,同时硬件将C2正F置1,此时若EPWM2I–1,则程序将跳转到相应中断入口执行中断服务程序 - EC2T1SI :PWM2的T1匹配发生波形翻转时的中断控制位
0:关闭T1翻转时中断
1:使能T1翻转时中断,当PWM波形发生器内部计数值与T1计数器所设定的值相匹配时,PWM的波形发生翻转,同时硬件将C2IF置1,此时若EPWM2I==1,则程序将跳转到相应中断入口执行中断服务程序。
6. PWM3的控制寄存器:PWM3CR
- EPWM3I :PWM3中断使能控制位
0:关闭PWM3中断
1:使能PWM3中断,当C3IF被硬件置1时,程序将跳转到相应中断入口执行中断服务
程序。 - EC3T2SI :PWM3的T2匹配发生波形翻转时的中断控制位
0:关闭T2翻转时中断
1:使能T2翻转时中断,当PWM波形发生器内部计数值与T2计数器所设定的值相匹配时,PWM的波形发生翻转,同时硬件将C3IF置1,此时若EPWM3I==1,则程序将跳转到相应中断入口执行中断服务程序。 - EC3T1SI :PWM3的T1匹配发生波形翻转时的中断控制位
0:关闭T1翻转时中断
1:使能T1翻转时中断,当PWM波形发生器内部计数值与T1计数器所设定的值相匹配时,PWM的波形发生翻转,同时硬件将C3IF置1,此时若EPWM3I==1,则程序将跳转到相应中断入口执行中断服务程序。
7.PWM4的控制寄存器: PWM4CR
- EPWM4I :PWM4中断使能控制位
0:关闭PWM4中断
1:使能PWM4中断,当C4IF被硬件置1时,程序将跳转到相应中断入口执行中断服务程序。 - EC4T2SI :PWM4的T2匹配发生波形翻转时的中断控制位
0:关闭T2翻转时中断
1:使能T2翻转时中断,当PWM波形发生器内部计数值与T2计数器所设定的值相匹配时,PWM的波形发生翻转,同时硬件将C4IF置1,此时若EPWM4I==1,则程序将跳转到相应中断入口执行中断服务程序。 - EC4T1SI :PWM4的T1匹配发生波形翻转时的中断控制位
0:关闭T1翻转时中断
1:使能T1翻转时中断,当PWM波形发生器内部计数值与T1计数器所设定的值相匹配时,PWM的波形发生翻转,同时硬件将C4IF置1,此时若EPWM4I==1,则程序将跳转到相应中断入口执行中断服务程序。
8. PWM5的控制寄存器:PWM5CR
- EPWM5I :PWM5中断使能控制位
0:关闭PWM5中断
1:使能PWM5中断,当C5IF被硬件置1时,程序将跳转到相应中断入口执行中断服务程序。 - EC5T2SI :PWM5的T2匹配发生波形翻转时的中断控制位
0:关闭T2翻转时中断
1:使能T2翻转时中断,当PWM波形发生器内部计数值与T2计数器所设定的值相匹配时,PWM的波形发生翻转,同时硬件将C5IF置1,此时若EPWM5I==1,则程序将跳转到相应中断入口执行中断服务程序。 - ECSTISI:PWM5的Tl配发生波形翻转时的中断控制位
0: 关闭TI翻转时中断
1:使能T1翻转时中断,当PWM波形发生器内部计数值与T1计数器所设定的值相匹配时,PWM的波形发生翻转,同时硬件将CSIF置1,此时若EPWMSI==1,则程序将跳转到相应中断入口执行中断服务程序
9.PWM6的控制寄存器:PWM6CR
- EPWM6I :PWM6中断使能控制位
0:关闭PWM6中断
1:使能PWM6中断,当C6IF被硬件置1时,程序将跳转到相应中断入口执行中断服务程序。 - EC6T2SI :PWM6的T2匹配发生波形翻转时的中断控制位
0:关闭T2翻转时中断
1:使能T2翻转时中断,当PWM波形发生器内部计数值与T2计数器所设定的值相匹配时,PWM的波形发生翻转,同时硬件将C6IF置1,此时若EPWM6I==1,则程序将跳转到相应中断入口执行中断服务程序。 - EC6T1SI :PWM6的T1匹配发生波形翻转时的中断控制位
0:关闭T1翻转时中断
1:使能T1翻转时中断,当PWM波形发生器内部计数值与T1计数器所设定的值相匹配时,PWM的波形发生翻转,同时硬件将C6IF置1,此时若EPWM6I==1,则程序将跳转到相应中断入口执行中断服务程序。
10. PWM7的控制寄存器:PWM7CR
- EPWM7I :PWM7中断使能控制位
0:关闭PWM7中断
1:使能PWM7中断,当C7IF被硬件置1时,程序将跳转到相应中断入口执行中断服务程序。 - EC7T2SI:PWM7的T2匹配发生波形翻转时的中断控制位
0:关闭T2翻转时中断
1:使能T2翻转时中断,当PWM波形发生器内部计数值与T2计数器所设定的值相匹配时,PWM的波形发生翻转,同时硬件将C7IF置1,此时若EPWM7I–1,则程序将跳转到相应中断入口执行中断服务程序。 - EC7TISI:PWM7的TI匹配发生波形翻转时的中断控制位
0:关闭T1翻转时中断
1:使能T1翻转时中断,当PWM波形发生器内部计数值与T1计数器所设定的值相匹配时,PWM的波形发生翻转,同时硬件将C7IF置1,此时若EPWM7I-1,则程序将跳转到相应中断入口执行中断服务程序。
中断向量地址及中断控制
- 在Keil C中声明中断函数:
void PWM_Routine(void) interrupt 22;
void PWMFD_Routine(void) interrupt 23;
- PWM波形发生器的结构框图
🌻PWM呼吸灯实现代码
/*---------------------------------------------------------------------*/
/* --- STC MCU Limited ------------------------------------------------*/
/* --- STC15Fxx 系列 使用PWM实现渐变灯实例-----------------------------*/
/* --- Mobile: (86)13922805190 ----------------------------------------*/
/* --- Fax: 86-0513-55012956,55012947,55012969 ------------------------*/
/* --- Tel: 86-0513-55012928,55012929,55012966-------------------------*/
/* --- Web: www.STCMCU.com --------------------------------------------*/
/* --- Web: www.GXWMCU.com --------------------------------------------*/
/* 如果要在程序中使用此代码,请在程序中注明使用了STC的资料及程序 */
/* 如果要在文章中应用此代码,请在文章中注明使用了STC的资料及程序 */
/*---------------------------------------------------------------------*/
//本示例在Keil开发环境下请选择Intel的8058芯片型号进行编译
//若无特别说明,工作频率一般为11.0592MHz
#include "reg51.h"
#define CYCLE 0x1000L //4096定义PWM周期2.7KHz
#define PWMC (*(unsigned int volatile xdata *)0xfff0)
#define PWMCH (*(unsigned char volatile xdata *)0xfff0)
#define PWMCL (*(unsigned char volatile xdata *)0xfff1)
#define PWMCKS (*(unsigned char volatile xdata *)0xfff2)
#define PWM2T1 (*(unsigned int volatile xdata *)0xff00)
#define PWM2T1H (*(unsigned char volatile xdata *)0xff00)
#define PWM2T1L (*(unsigned char volatile xdata *)0xff01)
#define PWM2T2 (*(unsigned int volatile xdata *)0xff02)
#define PWM2T2H (*(unsigned char volatile xdata *)0xff02)
#define PWM2T2L (*(unsigned char volatile xdata *)0xff03)
#define PWM2CR (*(unsigned char volatile xdata *)0xff04)
#define PWM3T1 (*(unsigned int volatile xdata *)0xff10)
#define PWM3T1H (*(unsigned char volatile xdata *)0xff10)
#define PWM3T1L (*(unsigned char volatile xdata *)0xff11)
#define PWM3T2 (*(unsigned int volatile xdata *)0xff12)
#define PWM3T2H (*(unsigned char volatile xdata *)0xff12)
#define PWM3T2L (*(unsigned char volatile xdata *)0xff13)
#define PWM3CR (*(unsigned char volatile xdata *)0xff14)
#define PWM4T1 (*(unsigned int volatile xdata *)0xff20)
#define PWM4T1H (*(unsigned char volatile xdata *)0xff20)
#define PWM4T1L (*(unsigned char volatile xdata *)0xff21)
#define PWM4T2 (*(unsigned int volatile xdata *)0xff22)
#define PWM4T2H (*(unsigned char volatile xdata *)0xff22)
#define PWM4T2L (*(unsigned char volatile xdata *)0xff23)
#define PWM4CR (*(unsigned char volatile xdata *)0xff24)
#define PWM5T1 (*(unsigned int volatile xdata *)0xff30)
#define PWM5T1H (*(unsigned char volatile xdata *)0xff30)
#define PWM5T1L (*(unsigned char volatile xdata *)0xff31)
#define PWM5T2 (*(unsigned int volatile xdata *)0xff32)
#define PWM5T2H (*(unsigned char volatile xdata *)0xff32)
#define PWM5T2L (*(unsigned char volatile xdata *)0xff33)
#define PWM5CR (*(unsigned char volatile xdata *)0xff34)
#define PWM6T1 (*(unsigned int volatile xdata *)0xff40)
#define PWM6T1H (*(unsigned char volatile xdata *)0xff40)
#define PWM6T1L (*(unsigned char volatile xdata *)0xff41)
#define PWM6T2 (*(unsigned int volatile xdata *)0xff42)
#define PWM6T2H (*(unsigned char volatile xdata *)0xff42)
#define PWM6T2L (*(unsigned char volatile xdata *)0xff43)
#define PWM6CR (*(unsigned char volatile xdata *)0xff44)
#define PWM7T1 (*(unsigned int volatile xdata *)0xff50)
#define PWM7T1H (*(unsigned char volatile xdata *)0xff50)
#define PWM7T1L (*(unsigned char volatile xdata *)0xff51)
#define PWM7T2 (*(unsigned int volatile xdata *)0xff52)
#define PWM7T2H (*(unsigned char volatile xdata *)0xff52)
#define PWM7T2L (*(unsigned char volatile xdata *)0xff53)
#define PWM7CR (*(unsigned char volatile xdata *)0xff54)
sfr PIN_SW2 = 0xba;
sfr P0M1 = 0x93;
sfr P0M0 = 0x94;
sfr P1M1 = 0x91;
sfr P1M0 = 0x92;
sfr P2M1 = 0x95;
sfr P2M0 = 0x96;
sfr P3M1 = 0xb1;
sfr P3M0 = 0xb2;
sfr P4M1 = 0xb3;
sfr P4M0 = 0xb4;
sfr P5M1 = 0xC9;
sfr P5M0 = 0xCA;
sfr P6M1 = 0xCB;
sfr P6M0 = 0xCC;
sfr P7M1 = 0xE1;
sfr P7M0 = 0xE2;
sfr PWMCFG = 0xf1;
sfr PWMCR = 0xf5;
sfr PWMIF = 0xf6;
sfr PWMFDCR = 0xf7;
void pwm_isr() interrupt 22
{
static bit dir = 1;
static int val = 0;
if (PWMIF & 0x40)
{
PWMIF &= ~0x40;
if (dir)
{
val++;
if (val >= CYCLE) dir = 0;
}
else
{
val--;
if (val <= 1) dir = 1;
}
PIN_SW2 |= 0x80;
PWM2T2 = val;
PIN_SW2 &= ~0x80;
}
}
void main()
{
P0M0 = 0x00;//配置IO组为准双向口
P0M1 = 0x00;
P1M0 = 0x00;
P1M1 = 0x00;
P2M0 = 0x00;
P2M1 = 0x00;
P3M0 = 0x00;
P3M1 = 0x00;
PIN_SW2 |= 0x80; //使能访问XSFR
PWMCFG = 0x00; //配置PWM的输出初始电平为低电平
PWMCKS = 0x00; //选择PWM的时钟为Fosc/1
PWMC = CYCLE; //设置PWM周期
PWM2T1 = 0x0000; //设置PWM2第1次反转的PWM计数
PWM2T2 = 0x0001; //设置PWM2第2次反转的PWM计数
//占空比为(PWM2T2-PWM2T1)/PWMC
PWM2CR = 0x00; //选择PWM2输出到P3.7,不使能PWM2中断
PWMCR = 0x01; //使能PWM信号输出
PWMCR |= 0x40; //使能PWM归零中断
PWMCR |= 0x80; //使能PWM模块
PIN_SW2 &= ~0x80;
EA = 1;
while (1);
}
🌼使用增强型PWM控制舞台灯光示例
/*---------------------------------------------------------------------*/
/* --- STC MCU Limited ------------------------------------------------*/
/* --- STC15Fxx 系列 使用增强型PWM控制舞台灯光示例---------------------*/
/* --- Mobile: (86)13922805190 ----------------------------------------*/
/* --- Fax: 86-0513-55012956,55012947,55012969 ------------------------*/
/* --- Tel: 86-0513-55012928,55012929,55012966-------------------------*/
/* --- Web: www.STCMCU.com --------------------------------------------*/
/* --- Web: www.GXWMCU.com --------------------------------------------*/
/* 如果要在程序中使用此代码,请在程序中注明使用了STC的资料及程序 */
/* 如果要在文章中应用此代码,请在文章中注明使用了STC的资料及程序 */
/*---------------------------------------------------------------------*/
//本示例在Keil开发环境下请选择Intel的8058芯片型号进行编译
//若无特别说明,工作频率一般为11.0592MHz
#include "reg51.h"
#define CYCLE 0x1000L //定义PWM周期(最大值为32767)
#define PWMC (*(unsigned int volatile xdata *)0xfff0)
#define PWMCH (*(unsigned char volatile xdata *)0xfff0)
#define PWMCL (*(unsigned char volatile xdata *)0xfff1)
#define PWMCKS (*(unsigned char volatile xdata *)0xfff2)
#define PWM2T1 (*(unsigned int volatile xdata *)0xff00)
#define PWM2T1H (*(unsigned char volatile xdata *)0xff00)
#define PWM2T1L (*(unsigned char volatile xdata *)0xff01)
#define PWM2T2 (*(unsigned int volatile xdata *)0xff02)
#define PWM2T2H (*(unsigned char volatile xdata *)0xff02)
#define PWM2T2L (*(unsigned char volatile xdata *)0xff03)
#define PWM2CR (*(unsigned char volatile xdata *)0xff04)
#define PWM3T1 (*(unsigned int volatile xdata *)0xff10)
#define PWM3T1H (*(unsigned char volatile xdata *)0xff10)
#define PWM3T1L (*(unsigned char volatile xdata *)0xff11)
#define PWM3T2 (*(unsigned int volatile xdata *)0xff12)
#define PWM3T2H (*(unsigned char volatile xdata *)0xff12)
#define PWM3T2L (*(unsigned char volatile xdata *)0xff13)
#define PWM3CR (*(unsigned char volatile xdata *)0xff14)
#define PWM4T1 (*(unsigned int volatile xdata *)0xff20)
#define PWM4T1H (*(unsigned char volatile xdata *)0xff20)
#define PWM4T1L (*(unsigned char volatile xdata *)0xff21)
#define PWM4T2 (*(unsigned int volatile xdata *)0xff22)
#define PWM4T2H (*(unsigned char volatile xdata *)0xff22)
#define PWM4T2L (*(unsigned char volatile xdata *)0xff23)
#define PWM4CR (*(unsigned char volatile xdata *)0xff24)
#define PWM5T1 (*(unsigned int volatile xdata *)0xff30)
#define PWM5T1H (*(unsigned char volatile xdata *)0xff30)
#define PWM5T1L (*(unsigned char volatile xdata *)0xff31)
#define PWM5T2 (*(unsigned int volatile xdata *)0xff32)
#define PWM5T2H (*(unsigned char volatile xdata *)0xff32)
#define PWM5T2L (*(unsigned char volatile xdata *)0xff33)
#define PWM5CR (*(unsigned char volatile xdata *)0xff34)
#define PWM6T1 (*(unsigned int volatile xdata *)0xff40)
#define PWM6T1H (*(unsigned char volatile xdata *)0xff40)
#define PWM6T1L (*(unsigned char volatile xdata *)0xff41)
#define PWM6T2 (*(unsigned int volatile xdata *)0xff42)
#define PWM6T2H (*(unsigned char volatile xdata *)0xff42)
#define PWM6T2L (*(unsigned char volatile xdata *)0xff43)
#define PWM6CR (*(unsigned char volatile xdata *)0xff44)
#define PWM7T1 (*(unsigned int volatile xdata *)0xff50)
#define PWM7T1H (*(unsigned char volatile xdata *)0xff50)
#define PWM7T1L (*(unsigned char volatile xdata *)0xff51)
#define PWM7T2 (*(unsigned int volatile xdata *)0xff52)
#define PWM7T2H (*(unsigned char volatile xdata *)0xff52)
#define PWM7T2L (*(unsigned char volatile xdata *)0xff53)
#define PWM7CR (*(unsigned char volatile xdata *)0xff54)
sfr P_SW2 = 0xba;
sfr P0M1 = 0x93;
sfr P0M0 = 0x94;
sfr P1M1 = 0x91;
sfr P1M0 = 0x92;
sfr P2M1 = 0x95;
sfr P2M0 = 0x96;
sfr P3M1 = 0xb1;
sfr P3M0 = 0xb2;
sfr P4M1 = 0xb3;
sfr P4M0 = 0xb4;
sfr P5M1 = 0xC9;
sfr P5M0 = 0xCA;
sfr P6M1 = 0xCB;
sfr P6M0 = 0xCC;
sfr P7M1 = 0xE1;
sfr P7M0 = 0xE2;
sfr PWMCFG = 0xf1;
sfr PWMCR = 0xf5;
sfr PWMIF = 0xf6;
sfr PWMFDCR = 0xf7;
sbit PWM2 = P3^7;
sbit PWM3 = P2^1;
sbit PWM4 = P2^2;
sbit PWM5 = P2^3;
sbit PWM6 = P0^7;
sbit PWM7 = P0^6;
void PWM_config(void);
void PWM2_SetPwmWide(unsigned short Wide);
void PWM3_SetPwmWide(unsigned short Wide);
void PWM4_SetPwmWide(unsigned short Wide);
void PWM5_SetPwmWide(unsigned short Wide);
void PWM6_SetPwmWide(unsigned short Wide);
void PWM7_SetPwmWide(unsigned short Wide);
void main()
{
PWM_config();
PWM2_SetPwmWide(0); //输出全低电平
PWM3_SetPwmWide(1); //输出1/2550高电平
PWM4_SetPwmWide(CYCLE); //输出全高电平
PWM5_SetPwmWide(CYCLE-1); //输出2549/2550低电平
PWM6_SetPwmWide(CYCLE/2); //输出1/2高电平
PWM7_SetPwmWide(CYCLE/3); //输出1/3高电平
while (1);
}
void PWM_config(void)
{
P0M0 &= ~0xc0;
P0M1 &= ~0xc0;
P0 &= ~0xc0; //设置P0.6/.P0.7电平
P2M0 &= ~0x0e;
P2M1 &= ~0x0e;
P2 &= ~0x0e; //设置P2.1/P2.2/P2.3电平
P3M0 &= ~0x80;
P3M1 &= ~0x80;
P3 &= ~0x80; //设置P3.7电平
P_SW2 |= 0x80;
PWMCKS = 0x00;
PWMC = CYCLE; //设置PWM周期
PWM2T1 = 1;
PWM2T2 = 0;
PWM2CR = 0x00; //PWM2输出到P3.7
PWM3T1 = 1;
PWM3T2 = 0;
PWM3CR = 0x00; //PWM3输出到P2.1
PWM4T1 = 1;
PWM4T2 = 0;
PWM4CR = 0x00; //PWM4输出到P2.2
PWM5T1 = 1;
PWM5T2 = 0;
PWM5CR = 0x00; //PWM5输出到P2.3
PWM6T1 = 1;
PWM6T2 = 0;
PWM6CR = 0x08; //PWM6输出到P0.7
PWM7T1 = 1;
PWM7T2 = 0;
PWM7CR = 0x08; //PWM7输出到P0.6
PWMCFG = 0x00; //配置PWM的输出初始电平
PWMCR = 0x3f; //使能PWM信号输出
PWMCR |= 0x80; //使能PWM模块
P_SW2 &= ~0x80;
}
void PWM2_SetPwmWide(unsigned short Wide)
{
if (Wide == 0)
{
PWMCR &= ~0x01;
PWM2 = 0;
}
else if (Wide == CYCLE)
{
PWMCR &= ~0x01;
PWM2 = 1;
}
else
{
P_SW2 |= 0x80;
PWM2T1 = Wide;
P_SW2 &= ~0x80;
PWMCR |= 0x01;
}
}
void PWM3_SetPwmWide(unsigned short Wide)
{
if (Wide == 0)
{
PWMCR &= ~0x02;
PWM3 = 0;
}
else if (Wide == CYCLE)
{
PWMCR &= ~0x02;
PWM3 = 1;
}
else
{
P_SW2 |= 0x80;
PWM3T1 = Wide;
P_SW2 &= ~0x80;
PWMCR |= 0x02;
}
}
void PWM4_SetPwmWide(unsigned short Wide)
{
if (Wide == 0)
{
PWMCR &= ~0x04;
PWM4 = 0;
}
else if (Wide == CYCLE)
{
PWMCR &= ~0x04;
PWM4 = 1;
}
else
{
P_SW2 |= 0x80;
PWM4T1 = Wide;
P_SW2 &= ~0x80;
PWMCR |= 0x04;
}
}
void PWM5_SetPwmWide(unsigned short Wide)
{
if (Wide == 0)
{
PWMCR &= ~0x08;
PWM5 = 0;
}
else if (Wide == CYCLE)
{
PWMCR &= ~0x08;
PWM5 = 1;
}
else
{
P_SW2 |= 0x80;
PWM5T1 = Wide;
P_SW2 &= ~0x80;
PWMCR |= 0x08;
}
}
void PWM6_SetPwmWide(unsigned short Wide)
{
if (Wide == 0)
{
PWMCR &= ~0x10;
PWM6 = 0;
}
else if (Wide == CYCLE)
{
PWMCR &= ~0x10;
PWM6 = 1;
}
else
{
P_SW2 |= 0x80;
PWM6T1 = Wide;
P_SW2 &= ~0x80;
PWMCR |= 0x10;
}
}
void PWM7_SetPwmWide(unsigned short Wide)
{
if (Wide == 0)
{
PWMCR &= ~0x20;
PWM7 = 0;
}
else if (Wide == CYCLE)
{
PWMCR &= ~0x20;
PWM7 = 1;
}
else
{
P_SW2 |= 0x80;
PWM7T1 = Wide;
P_SW2 &= ~0x80;
PWMCR |= 0x20;
}
}