⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 setdcoc12pwm_gb.c

📁 Mplab C30编译器
💻 C
字号:
#if defined(__PIC24F__)
#include <p24Fxxxx.h>
#endif
#include <outcompare.h>

#if defined (_OCMP_V4_1) && defined (_OCMP_V4_2)
/*************************************************************************************
Function Prototype : char SetDCOC12PWM(unsigned long dutycycle,unsigned long period)

Include            : outcompare.h
 
Description        : This function configures the Output Compare Secondary Duty Cycle
                     register (OCxRS) when the module is in PWM mode.

Arguments          : dutycycle - This is the duty cycle value to be stored into Output
                     Compare Main Duty Cycle register (OCxR).
                     period - This is the period stored into Secondary register (OCxRS)
 
Return Value       : Returns '1' on successful loading value else return '-1'.
 
Remarks            : The Output Compare Main and Secondary register will be
                     configured with new value only if the module is in PWM mode.
**************************************************************************************/

char SetDCOC12PWM(unsigned long dutycycle,unsigned long period)
{       
    if(((OC1CON1bits.OCM & 0x06) == 0x06) && ((OC2CON1bits.OCM & 0x06) == 0x06 ))/* check if OC is in PWM Mode */
    {
    	if(OC1CON2bits.OC32 == 1 && OC2CON2bits.OC32 == 1 ) /*check if OC is in cascade mode*/     
    	{
       		OC1R = dutycycle;       /* Odd OCx loaded with LSB */
       		OC2R = dutycycle >> 16; /* Even OCx loaded with MSB */      
       		OC1RS = period;
       		OC2RS = period >> 16;
      		return 1;
    	}
    	else
    	 return -1;
    }	    
    else
       return -1;       
}

#else
#warning "Does not build on this target"
#endif

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -