#include <p18cxxx.h>
#include <delays.h>
#include <timers.h>
#include <pwm.h>
#pragma config WDT = OFF
/*function prototypes, reproduced from Header Files for information
void OpenPWM1 (char);
void OpenPWM2 (char);
void OpenTimer2 (unsigned char);
void Delay10KTCYx (unsigned char);
*/
unsigned int dimmer1 = 0;
unsigned int dimmer2 = 0;
unsigned int dutycycle1 = 0;
unsigned int dutycycle2 = 0;
void main (void)
{
ADCON1 = 0b00000110; //Set Port A for digital i/o
TRISA = 0x00;
TRISB = 0xF0;
TRISC = 0xF0;
PORTA = 0;
PORTB = 0;
PORTC = 0;
OpenTimer2 (TIMER_INT_OFF & T2_PS_1_16 & T2_POST_1_1);
OpenPWM1 (0xFF); //Enable PWM1 and set period
OpenPWM2 (0xFF); //Enable PWM2 and set period
while (1)
{
dimmer1 = PORTC & 0xF0;
dimmer2 = PORTB & 0xF0;
dimmer1 = dimmer1 >> 4;
dimmer2 = dimmer2 >> 4;
if(dimmer1 > 0 && dimmer1 < 11)
{
dutycycle1 = dimmer1 * 100; // Scaling out (Max 1000)
}
else
{
dutycycle1 = 0;
}
if(dimmer2 > 0 && dimmer2 < 11)
{
dutycycle2 = dimmer2 * 100; // Scaling out (Max 1000)
}
else
{
dutycycle2 = 0;
}
SetDCPWM1 (dutycycle1);
SetDCPWM2 (dutycycle2);
}
}