
#ifndef _MAIN_C_
#define _MAIN_C_
/*********************************************************************************************************************/
#include "include/ca51f_config.h"		
#include "include/ca51f2sfr.h"
#include "include/ca51f2xsfr.h"
#include "include/gpiodef_f2.h"
#include "include/system_clock.h"

#include "include/uart.h"
#include "include/pwm.h"
#include "include/delay.h"
#include <intrins.h>
/*********************************************************************************************************************
	本例程设置PWM0输出频率为30KHZ、占空比50%的PWM信号

	备注：
	1、PWM有多种时钟源可以选择，时钟源是以两路PWM为单位进行设置的，
	分别是：PWM0 和 PWM1、PWM2 和 PWM3、PWM4 和 PWM5、PWM6 和 PWM7，
	也就是说，每组PWM的时钟源是共同设置的，时钟源通过 PWM0、PWM2、
	PWM4、PWM6对应的控制寄存器 PWMCON 的PWMCKS来选择。

	2、PWMCON、PWMCFG、PWMDIVH、PWMDIVL、PWMDUTH、PWMDUTL、PWMCMAX等
	寄存器是带索引的寄存器，设置带索引的寄存器前先设置INDEX寄存器，
	具体操作请参考下面的例子
*********************************************************************************************************************/

#define PWM0DIV_V				(FOSC/30000)			//当前示例选用系统时钟作为时钟源。若PWM时钟采用其他频率的时钟源，则需根据选择的时钟源，调整参数。
#define PWM0DUT_V				(PWM0DIV_V/2)			//本示例中占空比为50%，实际应用时，请根据具体产品需求进行调整。

#define PWM1DIV_V				(FOSC/33000)			//当前示例选用系统时钟作为时钟源。若PWM时钟采用其他频率的时钟源，则需根据选择的时钟源，调整参数。
#define PWM1DUT_V				(PWM1DIV_V/2)			//本示例中占空比为50%，实际应用时，请根据具体产品需求进行调整。

#define PWM2DIV_V				(FOSC/100000)			//当前示例选用系统时钟作为时钟源。若PWM时钟采用其他频率的时钟源，则需根据选择的时钟源，调整参数。
#define PWM2DUT_V				(PWM2DIV_V/2)			//本示例中占空比为50%，实际应用时，请根据具体产品需求进行调整。

#define PWM3DIV_V				(FOSC/50000)			//当前示例选用系统时钟作为时钟源。若PWM时钟采用其他频率的时钟源，则需根据选择的时钟源，调整参数。
#define PWM3DUT_V				(PWM3DIV_V/2)			//本示例中占空比为50%，实际应用时，请根据具体产品需求进行调整。

#define PWM4DIV_V				(FOSC/10000)			//当前示例选用系统时钟作为时钟源。若PWM时钟采用其他频率的时钟源，则需根据选择的时钟源，调整参数。
#define PWM4DUT_V				(PWM4DIV_V/2)			//本示例中占空比为50%，实际应用时，请根据具体产品需求进行调整。

#define PWM5DIV_V				(FOSC/15000)			//当前示例选用系统时钟作为时钟源。若PWM时钟采用其他频率的时钟源，则需根据选择的时钟源，调整参数。
#define PWM5DUT_V				(PWM5DIV_V/2)			//本示例中占空比为50%，实际应用时，请根据具体产品需求进行调整。

#define PWM6DIV_V				(FOSC/20000)			//当前示例选用系统时钟作为时钟源。若PWM时钟采用其他频率的时钟源，则需根据选择的时钟源，调整参数。
#define PWM6DUT_V				(PWM6DIV_V/2)			//本示例中占空比为50%，实际应用时，请根据具体产品需求进行调整。

#define PWM7DIV_V				(FOSC/25000)			//当前示例选用系统时钟作为时钟源。若PWM时钟采用其他频率的时钟源，则需根据选择的时钟源，调整参数。
#define PWM7DUT_V				(PWM7DIV_V/2)			//本示例中占空比为50%，实际应用时，请根据具体产品需求进行调整。

void main(void)
{
#ifdef LVD_RST_ENABLE
	LVDCON = 0xE1;					//设置LVD复位电压为2V
#endif

#if (SYSCLK_SRC == PLL)
	Sys_Clk_Set_PLL(PLL_Multiple);	//设置系统时钟为PLL，PLL_Multiple为倍频倍数
#endif
	
#ifdef UART0_EN
	Uart0_Initial(UART0_BAUTRATE);	//初始化UART0
#endif
	
#ifdef UART1_EN
	Uart1_Initial(UART1_BAUTRATE);	//初始化UART1
#endif

#ifdef UART2_EN
	Uart2_Initial(UART2_BAUTRATE);	//初始化UART2
#endif
	
	EA = 1;													//开全局中断

#ifdef PRINT_EN
	uart_printf("PWM Simple Demo Code\n");
#endif

//---------------------------------------------------------------------------------------------	
	CKCON |= IHCKE;				//打开IRCH时钟
// 	CKCON |= ILCKE;				//打开IRCL时钟
// 	CKCON |= TFCKE;				//打开TFRC时钟

// 	GPIO_Init(P72F,P72_XOSCL_IN_SETTING);
// 	GPIO_Init(P71F,P71_XOSCL_OUT_SETTING);
// 	CKCON |= XLCKE;
// 	while(!(CKCON & XLSTA));
// 	CKSEL = (CKSEL&0xF8) | CKSEL_XOSCL;		//打开XSOCL时钟

// 	PLLCON = PLLON(1) | MULFT(7);
// 	while(!(PLLCON & PLSTA));
// 	CKSEL = (CKSEL&0xF8) | CKSEL_PLL;		//打开PLL时钟

/*********************************************************************************************************************/
//  以下是多路PWM同时使用的演示例子
//	备注：
//	PWM 有多种时钟源可以选择，时钟源是以两路 PWM 为单位进行设置的，分别是：PWM0和PWM1、PWM2和PWM3、PWM4和PWM5、PWM6和PWM7，
//	也就是说，每组 PWM 的时钟源是共同设置的，时钟源通过 PWM0、PWM2、PWM4、PWM6对应的控制寄存器PWMCON的PWMCKS来选择。
/*********************************************************************************************************************/

#if (0)
	P50F = P50_PWM0_SETTING;								//设置P50为PWM引脚功能
	P51F = P51_PWM1_SETTING;								//设置P51为PWM引脚功能

	INDEX = PWM_CH0;													//设置INDEX值对应PWM0
	PWMCON = TIE(0) | ZIE(0) | PIE(0) | NIE(0) | MS(0) | CKS_SYS;		//设置PWM时钟源为系统时钟
//	PWMCON = TIE(0) | ZIE(0) | PIE(0) | NIE(0) | MS(0) | CKS_IH ;		//设置PWM时钟源为IRCH  
// 	PWMCON = TIE(0) | ZIE(0) | PIE(0) | NIE(0) | MS(0) | CKS_IL ;		//设置PWM时钟源为IRCL
// 	PWMCON = TIE(0) | ZIE(0) | PIE(0) | NIE(0) | MS(0) | CKS_XL ;		//设置PWM时钟源为XOSCL  
// 	PWMCON = TIE(0) | ZIE(0) | PIE(0) | NIE(0) | MS(0) | CKS_TF ;		//设置PWM时钟源为TFRC 
// 	PWMCON = TIE(0) | ZIE(0) | PIE(0) | NIE(0) | MS(0) | CKS_PLL;		//设置PWM时钟源为PLL  
	PWMCFG = TOG(0) | 0;																								
	
	//设置PWMDIV、PWMDUT
	PWMDIVH	= (unsigned char)(PWM0DIV_V>>8);			
	PWMDIVL	= (unsigned char)(PWM0DIV_V);			
	PWMDUTH	= (unsigned char)(PWM0DUT_V>>8);		
	PWMDUTL	= (unsigned char)(PWM0DUT_V);		

	INDEX = PWM_CH1;
	PWMCON = TIE(0) | ZIE(0) | PIE(0) | NIE(0) | MS(0) | MOD(0);		
	PWMCFG = TOG(0) | 0;
	//设置PWMDIV、PWMDUT
	PWMDIVH	= (unsigned char)(PWM1DIV_V>>8);			
	PWMDIVL	= (unsigned char)(PWM1DIV_V);			
	PWMDUTH	= (unsigned char)(PWM1DUT_V>>8);		
	PWMDUTL	= (unsigned char)(PWM1DUT_V);	
//---------------------------------------------------------------------------------------------	
	P52F = P52_PWM2_SETTING;								//设置P52为PWM引脚功能
	P53F = P53_PWM3_SETTING;								//设置P53为PWM引脚功能

	INDEX = PWM_CH2;													//设置INDEX值对应PWM2
	PWMCON = TIE(0) | ZIE(0) | PIE(0) | NIE(0) | MS(0) | CKS_SYS;		//设置PWM时钟源为系统时钟
//	PWMCON = TIE(0) | ZIE(0) | PIE(0) | NIE(0) | MS(0) | CKS_IH ;		//设置PWM时钟源为IRCH  
// 	PWMCON = TIE(0) | ZIE(0) | PIE(0) | NIE(0) | MS(0) | CKS_IL ;		//设置PWM时钟源为IRCL
// 	PWMCON = TIE(0) | ZIE(0) | PIE(0) | NIE(0) | MS(0) | CKS_XL ;		//设置PWM时钟源为XOSCL  
// 	PWMCON = TIE(0) | ZIE(0) | PIE(0) | NIE(0) | MS(0) | CKS_TF ;		//设置PWM时钟源为TFRC 
// 	PWMCON = TIE(0) | ZIE(0) | PIE(0) | NIE(0) | MS(0) | CKS_PLL;		//设置PWM时钟源为PLL  
	PWMCFG = TOG(0) | 0;																								
	
	//设置PWMDIV、PWMDUT
	PWMDIVH	= (unsigned char)(PWM2DIV_V>>8);			
	PWMDIVL	= (unsigned char)(PWM2DIV_V);			
	PWMDUTH	= (unsigned char)(PWM2DUT_V>>8);		
	PWMDUTL	= (unsigned char)(PWM2DUT_V);		

	INDEX = PWM_CH3;
	PWMCON = TIE(0) | ZIE(0) | PIE(0) | NIE(0) | MS(0) | MOD(0);		
	PWMCFG = TOG(0) | 0;
	//设置PWMDIV、PWMDUT
	PWMDIVH	= (unsigned char)(PWM3DIV_V>>8);			
	PWMDIVL	= (unsigned char)(PWM3DIV_V);			
	PWMDUTH	= (unsigned char)(PWM3DUT_V>>8);		
	PWMDUTL	= (unsigned char)(PWM3DUT_V);	

//---------------------------------------------------------------------------------------------	

 	PWMUPD = (1<<PWM_CH0)|(1<<PWM_CH1)|(1<<PWM_CH2)|(1<<PWM_CH3);		//PWMDIV、PWMDUT更新使能
	while(PWMUPD);														//等待更新完成
 	PWMEN  = (1<<PWM_CH0)|(1<<PWM_CH1)|(1<<PWM_CH2)|(1<<PWM_CH3);		//PWM0、PWM1、PWM2、PWM3使能

#endif

/*********************************************************************************************************************/
//  以下是单路PWM使用的演示例子
//	备注：
//	PWM 有多种时钟源可以选择，时钟源是以两路 PWM 为单位进行设置的，分别是：PWM0和PWM1、PWM2和PWM3、PWM4和PWM5、PWM6和PWM7，
//	也就是说，每组 PWM 的时钟源是共同设置的，时钟源通过 PWM0、PWM2、PWM4、PWM6对应的控制寄存器PWMCON的PWMCKS来选择。
/*********************************************************************************************************************/
//  以打开PWM0为例
#if (0)
	INDEX = PWM_CH0;													//设置INDEX值对应PWM0
	PWMCON = TIE(0) | ZIE(0) | PIE(0) | NIE(0) | MS(0) | CKS_SYS;		//设置PWM时钟源为系统时钟
//	PWMCON = TIE(0) | ZIE(0) | PIE(0) | NIE(0) | MS(0) | CKS_IH ;		//设置PWM时钟源为IRCH  
// 	PWMCON = TIE(0) | ZIE(0) | PIE(0) | NIE(0) | MS(0) | CKS_IL ;		//设置PWM时钟源为IRCL
// 	PWMCON = TIE(0) | ZIE(0) | PIE(0) | NIE(0) | MS(0) | CKS_XL ;		//设置PWM时钟源为XOSCL  
// 	PWMCON = TIE(0) | ZIE(0) | PIE(0) | NIE(0) | MS(0) | CKS_TF ;		//设置PWM时钟源为TFRC 
// 	PWMCON = TIE(0) | ZIE(0) | PIE(0) | NIE(0) | MS(0) | CKS_PLL;		//设置PWM时钟源为PLL  
	PWMCFG = TOG(0) | 0;																								
	
	//设置PWMDIV、PWMDUT
	PWMDIVH	= (unsigned char)(PWM0DIV_V>>8);			
	PWMDIVL	= (unsigned char)(PWM0DIV_V);			
	PWMDUTH	= (unsigned char)(PWM0DUT_V>>8);		
	PWMDUTL	= (unsigned char)(PWM0DUT_V);
		
	P50F = P50_PWM0_SETTING;				//设置P50为PWM引脚功能

 	PWMUPD |= (1<<PWM_CH0);					//PWMDIV、PWMDUT更新使能
	while(PWMUPD);							//等待更新完成
 	PWMEN  |= (1<<PWM_CH0);					//PWM0使能
#endif

//  以打开PWM1为例，设置的重点：每组PWM的时钟源是共同设置的，时钟源通过PWM0、PWM2、PWM4、PWM6对应的控制寄存器PWMCON的PWMCKS来选择。
#if (0)
	INDEX = PWM_CH0;													//设置INDEX值对应PWM0
	PWMCON = TIE(0) | ZIE(0) | PIE(0) | NIE(0) | MS(0) | CKS_SYS;		//设置PWM时钟源为系统时钟
//	PWMCON = TIE(0) | ZIE(0) | PIE(0) | NIE(0) | MS(0) | CKS_IH ;		//设置PWM时钟源为IRCH  
// 	PWMCON = TIE(0) | ZIE(0) | PIE(0) | NIE(0) | MS(0) | CKS_IL ;		//设置PWM时钟源为IRCL
// 	PWMCON = TIE(0) | ZIE(0) | PIE(0) | NIE(0) | MS(0) | CKS_XL ;		//设置PWM时钟源为XOSCL  
// 	PWMCON = TIE(0) | ZIE(0) | PIE(0) | NIE(0) | MS(0) | CKS_TF ;		//设置PWM时钟源为TFRC 
// 	PWMCON = TIE(0) | ZIE(0) | PIE(0) | NIE(0) | MS(0) | CKS_PLL;		//设置PWM时钟源为PLL  	
	INDEX = PWM_CH1;
	PWMCON = TIE(0) | ZIE(0) | PIE(0) | NIE(0) | MS(0) | MOD(0);		
	PWMCFG = TOG(0) | 0;

	//设置PWMDIV、PWMDUT
	PWMDIVH	= (unsigned char)(PWM1DIV_V>>8);			
	PWMDIVL	= (unsigned char)(PWM1DIV_V);			
	PWMDUTH	= (unsigned char)(PWM1DUT_V>>8);		
	PWMDUTL	= (unsigned char)(PWM1DUT_V);

	P51F = P51_PWM1_SETTING;				//设置P51为PWM引脚功能

 	PWMUPD |= (1<<PWM_CH1);					//PWMDIV、PWMDUT更新使能
	while(PWMUPD);							//等待更新完成
 	PWMEN  |= (1<<PWM_CH1);					//PWM1使能
#endif	

//  以打开PWM2为例
#if (0)
	INDEX = PWM_CH2;													//设置INDEX值对应PWM2
	PWMCON = TIE(0) | ZIE(0) | PIE(0) | NIE(0) | MS(0) | CKS_SYS;		//设置PWM时钟源为系统时钟
//	PWMCON = TIE(0) | ZIE(0) | PIE(0) | NIE(0) | MS(0) | CKS_IH ;		//设置PWM时钟源为IRCH  
// 	PWMCON = TIE(0) | ZIE(0) | PIE(0) | NIE(0) | MS(0) | CKS_IL ;		//设置PWM时钟源为IRCL
// 	PWMCON = TIE(0) | ZIE(0) | PIE(0) | NIE(0) | MS(0) | CKS_XL ;		//设置PWM时钟源为XOSCL  
// 	PWMCON = TIE(0) | ZIE(0) | PIE(0) | NIE(0) | MS(0) | CKS_TF ;		//设置PWM时钟源为TFRC 
// 	PWMCON = TIE(0) | ZIE(0) | PIE(0) | NIE(0) | MS(0) | CKS_PLL;		//设置PWM时钟源为PLL  
	PWMCFG = TOG(0) | 0;																								
	
	//设置PWMDIV、PWMDUT
	PWMDIVH	= (unsigned char)(PWM2DIV_V>>8);			
	PWMDIVL	= (unsigned char)(PWM2DIV_V);			
	PWMDUTH	= (unsigned char)(PWM2DUT_V>>8);		
	PWMDUTL	= (unsigned char)(PWM2DUT_V);
		
	P52F = P52_PWM2_SETTING;			   //设置P52为PWM引脚功能

 	PWMUPD |= (1<<PWM_CH2);					//PWMDIV、PWMDUT更新使能
	while(PWMUPD);							//等待更新完成
 	PWMEN  |= (1<<PWM_CH2);					//PWM0使能
#endif

//  以打开PWM3为例，设置的重点：每组PWM的时钟源是共同设置的，时钟源通过PWM0、PWM2、PWM4、PWM6对应的控制寄存器PWMCON的PWMCKS来选择。
#if (0)
	INDEX = PWM_CH2;													//设置INDEX值对应PWM2
	PWMCON = TIE(0) | ZIE(0) | PIE(0) | NIE(0) | MS(0) | CKS_SYS;		//设置PWM时钟源为系统时钟
//	PWMCON = TIE(0) | ZIE(0) | PIE(0) | NIE(0) | MS(0) | CKS_IH ;		//设置PWM时钟源为IRCH  
// 	PWMCON = TIE(0) | ZIE(0) | PIE(0) | NIE(0) | MS(0) | CKS_IL ;		//设置PWM时钟源为IRCL
// 	PWMCON = TIE(0) | ZIE(0) | PIE(0) | NIE(0) | MS(0) | CKS_XL ;		//设置PWM时钟源为XOSCL  
// 	PWMCON = TIE(0) | ZIE(0) | PIE(0) | NIE(0) | MS(0) | CKS_TF ;		//设置PWM时钟源为TFRC 
// 	PWMCON = TIE(0) | ZIE(0) | PIE(0) | NIE(0) | MS(0) | CKS_PLL;		//设置PWM时钟源为PLL  	
	INDEX = PWM_CH3;
	PWMCON = TIE(0) | ZIE(0) | PIE(0) | NIE(0) | MS(0) | MOD(0);		
	PWMCFG = TOG(0) | 0;

	//设置PWMDIV、PWMDUT
	PWMDIVH	= (unsigned char)(PWM3DIV_V>>8);			
	PWMDIVL	= (unsigned char)(PWM3DIV_V);			
	PWMDUTH	= (unsigned char)(PWM3DUT_V>>8);		
	PWMDUTL	= (unsigned char)(PWM3DUT_V);

	P53F = P53_PWM3_SETTING;				//设置P53为PWM引脚功能

 	PWMUPD |= (1<<PWM_CH3);					//PWMDIV、PWMDUT更新使能
	while(PWMUPD);							//等待更新完成
 	PWMEN  |= (1<<PWM_CH3);					//PWM1使能
#endif

//  以打开PWM4为例
#if (0)
	INDEX = PWM_CH4;													//设置INDEX值对应PWM4
	PWMCON = TIE(0) | ZIE(0) | PIE(0) | NIE(0) | MS(0) | CKS_SYS;		//设置PWM时钟源为系统时钟
//	PWMCON = TIE(0) | ZIE(0) | PIE(0) | NIE(0) | MS(0) | CKS_IH ;		//设置PWM时钟源为IRCH  
// 	PWMCON = TIE(0) | ZIE(0) | PIE(0) | NIE(0) | MS(0) | CKS_IL ;		//设置PWM时钟源为IRCL
// 	PWMCON = TIE(0) | ZIE(0) | PIE(0) | NIE(0) | MS(0) | CKS_XL ;		//设置PWM时钟源为XOSCL  
// 	PWMCON = TIE(0) | ZIE(0) | PIE(0) | NIE(0) | MS(0) | CKS_TF ;		//设置PWM时钟源为TFRC 
// 	PWMCON = TIE(0) | ZIE(0) | PIE(0) | NIE(0) | MS(0) | CKS_PLL;		//设置PWM时钟源为PLL  
	PWMCFG = TOG(0) | 0;																								
	
	//设置PWMDIV、PWMDUT
	PWMDIVH	= (unsigned char)(PWM4DIV_V>>8);			
	PWMDIVL	= (unsigned char)(PWM4DIV_V);			
	PWMDUTH	= (unsigned char)(PWM4DUT_V>>8);		
	PWMDUTL	= (unsigned char)(PWM4DUT_V);
		
	P54F = P54_PWM4_SETTING;			   //设置P54为PWM引脚功能

 	PWMUPD |= (1<<PWM_CH4);					//PWMDIV、PWMDUT更新使能
	while(PWMUPD);							//等待更新完成
 	PWMEN  |= (1<<PWM_CH4);					//PWM0使能
#endif

//  以打开PWM5为例，设置的重点：每组PWM的时钟源是共同设置的，时钟源通过PWM0、PWM2、PWM4、PWM6对应的控制寄存器PWMCON的PWMCKS来选择。
#if (0)
	INDEX = PWM_CH4;													//设置INDEX值对应PWM4
	PWMCON = TIE(0) | ZIE(0) | PIE(0) | NIE(0) | MS(0) | CKS_SYS;		//设置PWM时钟源为系统时钟
//	PWMCON = TIE(0) | ZIE(0) | PIE(0) | NIE(0) | MS(0) | CKS_IH ;		//设置PWM时钟源为IRCH  
// 	PWMCON = TIE(0) | ZIE(0) | PIE(0) | NIE(0) | MS(0) | CKS_IL ;		//设置PWM时钟源为IRCL
// 	PWMCON = TIE(0) | ZIE(0) | PIE(0) | NIE(0) | MS(0) | CKS_XL ;		//设置PWM时钟源为XOSCL  
// 	PWMCON = TIE(0) | ZIE(0) | PIE(0) | NIE(0) | MS(0) | CKS_TF ;		//设置PWM时钟源为TFRC 
// 	PWMCON = TIE(0) | ZIE(0) | PIE(0) | NIE(0) | MS(0) | CKS_PLL;		//设置PWM时钟源为PLL  	
	INDEX = PWM_CH5;
	PWMCON = TIE(0) | ZIE(0) | PIE(0) | NIE(0) | MS(0) | MOD(0);		
	PWMCFG = TOG(0) | 0;

	//设置PWMDIV、PWMDUT
	PWMDIVH	= (unsigned char)(PWM5DIV_V>>8);			
	PWMDIVL	= (unsigned char)(PWM5DIV_V);			
	PWMDUTH	= (unsigned char)(PWM5DUT_V>>8);		
	PWMDUTL	= (unsigned char)(PWM5DUT_V);

	P55F = P55_PWM5_SETTING;				//设置P55为PWM引脚功能

 	PWMUPD |= (1<<PWM_CH5);					//PWMDIV、PWMDUT更新使能
	while(PWMUPD);							//等待更新完成
 	PWMEN  |= (1<<PWM_CH5);					//PWM1使能
#endif

//  以打开PWM6为例
#if (1)
	INDEX = PWM_CH6;													//设置INDEX值对应PWM6
	PWMCON = TIE(0) | ZIE(0) | PIE(0) | NIE(0) | MS(0) | CKS_SYS;		//设置PWM时钟源为系统时钟
//	PWMCON = TIE(0) | ZIE(0) | PIE(0) | NIE(0) | MS(0) | CKS_IH ;		//设置PWM时钟源为IRCH  
// 	PWMCON = TIE(0) | ZIE(0) | PIE(0) | NIE(0) | MS(0) | CKS_IL ;		//设置PWM时钟源为IRCL
// 	PWMCON = TIE(0) | ZIE(0) | PIE(0) | NIE(0) | MS(0) | CKS_XL ;		//设置PWM时钟源为XOSCL  
// 	PWMCON = TIE(0) | ZIE(0) | PIE(0) | NIE(0) | MS(0) | CKS_TF ;		//设置PWM时钟源为TFRC 
// 	PWMCON = TIE(0) | ZIE(0) | PIE(0) | NIE(0) | MS(0) | CKS_PLL;		//设置PWM时钟源为PLL  
	PWMCFG = TOG(0) | 0;																								
	
	//设置PWMDIV、PWMDUT
	PWMDIVH	= (unsigned char)(PWM6DIV_V>>8);			
	PWMDIVL	= (unsigned char)(PWM6DIV_V);			
	PWMDUTH	= (unsigned char)(PWM6DUT_V>>8);		
	PWMDUTL	= (unsigned char)(PWM6DUT_V);
		
	P33F = P33_PWM6_SETTING;			    //设置P33为PWM引脚功能

 	PWMUPD |= (1<<PWM_CH6);					//PWMDIV、PWMDUT更新使能
	while(PWMUPD);							//等待更新完成
 	PWMEN  |= (1<<PWM_CH6);					//PWM6使能
#endif

//  以打开PWM7为例，设置的重点：每组PWM的时钟源是共同设置的，时钟源通过PWM0、PWM2、PWM4、PWM6对应的控制寄存器PWMCON的PWMCKS来选择。
#if (1)
	INDEX = PWM_CH6;													//设置INDEX值对应PWM6
	PWMCON = TIE(0) | ZIE(0) | PIE(0) | NIE(0) | MS(0) | CKS_SYS;		//设置PWM时钟源为系统时钟
//	PWMCON = TIE(0) | ZIE(0) | PIE(0) | NIE(0) | MS(0) | CKS_IH ;		//设置PWM时钟源为IRCH  
// 	PWMCON = TIE(0) | ZIE(0) | PIE(0) | NIE(0) | MS(0) | CKS_IL ;		//设置PWM时钟源为IRCL
// 	PWMCON = TIE(0) | ZIE(0) | PIE(0) | NIE(0) | MS(0) | CKS_XL ;		//设置PWM时钟源为XOSCL  
// 	PWMCON = TIE(0) | ZIE(0) | PIE(0) | NIE(0) | MS(0) | CKS_TF ;		//设置PWM时钟源为TFRC 
// 	PWMCON = TIE(0) | ZIE(0) | PIE(0) | NIE(0) | MS(0) | CKS_PLL;		//设置PWM时钟源为PLL  	
	INDEX = PWM_CH7;
	PWMCON = TIE(0) | ZIE(0) | PIE(0) | NIE(0) | MS(0) | MOD(0);		
	PWMCFG = TOG(0) | 0;

	//设置PWMDIV、PWMDUT
	PWMDIVH	= (unsigned char)(PWM7DIV_V>>8);			
	PWMDIVL	= (unsigned char)(PWM7DIV_V);			
	PWMDUTH	= (unsigned char)(PWM7DUT_V>>8);		
	PWMDUTL	= (unsigned char)(PWM7DUT_V);

	P32F = P32_PWM7_SETTING;				//设置P32为PWM引脚功能

 	PWMUPD |= (1<<PWM_CH7);					//PWMDIV、PWMDUT更新使能
	while(PWMUPD);							//等待更新完成
 	PWMEN  |= (1<<PWM_CH7);					//PWM7使能
#endif

/*********************************************************************************************************************/

	while(1)
	{
	}
}
#endif

