$ifndef _HPWM8_INC_ $define _HPWM8_INC_ ' ' Note that these macros use FSR0L/H and INDF0 in order to achieve bankless operation ' ' Configure CCP1 as PWM with a resolution of 8-bits (0 - 255) ' ' Turn on Timer2 with a Prescaler value of 1:1 ' Set PWM resolution to 8-bits ' Reset the CCPR1L register ' Turn on PWM Module 1 by setting bits 2 and 3 of CCP1CON ' Enable the PWM1 output pin $define OpenAnalog1() ' T2CON = %00000100 ' PR2 = 63 ' CCPR1L = 0 ' CCP1CON = %00001100 ' Output PORTC.2 ' ' Configure CCP2 as PWM with a resolution of 8-bits (0 - 255) ' Turn on Timer2 with a Prescaler value of 1:1 ' Set PWM resolution to 8-bits ' Reset the CCPR2L register ' Turn on PWM Module 2 by setting bits 2 and 3 of CCP2CON ' Enable the PWM2 output pin ' $define OpenAnalog2() ' T2CON = %00000100 ' PR2 = 63 ' CCPR2L = 0 ' CCP2CON = %00001100 ' Output PORTC.1 '--------------------------------------------------------- $define WriteAnalog1(pDutyCycle) _mWriteAnalog1 pDutyCycle _mWriteAnalog1 Macro pDutyCycle #if((Prm_1 == Byte) || (Prm_1 == Word) || (Prm_1 == Dword)) lfsr 0,(pDutyCycle) movlw 207 ' CCP1CON = CCP1CON & %11001111 andwf CCP1CON,f swapf INDF0,w ' WREG = pDutyCycle << 4 andlw 48 ' WREG = WREG & %00110000 iorwf CCP1CON,f ' CCP1CON = CCP1CON | WREG bcf STATUS,0 ' CCPR1L = pDutyCycle >> 2 rrcf INDF0,w bcf STATUS,0 rrcf WREG,f movwf CCPR1L Exitm #endif #if(Prm_1 == Num8) || (Prm_1 == Num16) || (Prm_1 == Num32) movlw 207 andwf CCP1CON,f movlw ((pDutyCycle << 4) & 48) iorwf CCP1CON,f movlw (pDutyCycle >> 2) movwf CCPR1L Exitm #endif Endm '--------------------------------------------------------- $define WriteAnalog2(pDutyCycle) _mWriteAnalog2 pDutyCycle _mWriteAnalog2 Macro pDutyCycle #if((Prm_1 == Byte) || (Prm_1 == Word) || (Prm_1 == Dword)) lfsr 0,(pDutyCycle) movlw 207 ' CCP2CON = CCP2CON & %11001111 andwf CCP2CON,f swapf INDF0,w ' WREG = pDutyCycle << 4 andlw 48 ' WREG = WREG & %00110000 iorwf CCP2CON,f ' CCP2CON = CCP2CON | WREG bcf STATUS,0 ' CCPR2L = pDutyCycle >> 2 rrcf INDF0,w bcf STATUS,0 rrcf WREG,f movwf CCPR2L Exitm #endif #if(Prm_1 == Num8) || (Prm_1 == Num16) || (Prm_1 == Num32) movlw 207 andwf CCP2CON,f movlw ((pDutyCycle << 4) & 48) iorwf CCP2CON,f movlw (pDutyCycle >> 2) movwf CCPR2L Exitm #endif Endm '--------------------------------------------------------- ' Turn off PWM Module 1 by clearing CCP1CON ' Disable the PWM1 output pin $define CloseAnalog1() CCP1CON = 0 : Input PORTC.2 '--------------------------------------------------------- ' Turn off PWM Module 2 by clearing CCP1CON ' Disable the PWM2 output pin $define CloseAnalog2() CCP2CON = 0 : Input PORTC.1 $endif