below is the code that i'm using....
#include <p18f4431.h> /* header file for PIC18F4431*/
#include <stdio.h>
/* CONFIGURATION BIT SET UP (all this is done using the configuration bit setup menu) */
/* Oscillator Set up */
/* All FOSC settings set up the ocilator to use HS mode */
/*control which uses external 16MHz crystal.*/
/*Also fail-safe clock mode disabled so uses the external clock setup.*/
/* RE7 (pin 4) to be set up as an input and not a master clear. */
/* Watchdog timer disabled as it is not required */
/* Low Voltage Program disabled so that pin 38 acts as normal I/O. */
/* Polarity of PWM reversed */
/* function prototypes */
void main(void); /* main code */
void init(void); /* Intialisition of the PIC */
void foo(void); /* Interupt Service Routine */
unsigned char test;
#pragma interruptlow foo save = PROD, test
void foo (void)
{
PIR1bits.TMR1IF = 0; /*clear interupt flags */
TMR1H = 0xF1; /* load higher byte */
TMR1L = 0x1D; /* Load lower byte */
}
#pragma code lowvector=0x18
void lowvector(void)
{
_asm goto foo _endasm
}
#pragma code
#pragma code highvector=0x08
void highvector(void)
{
_asm goto foo _endasm
}
#pragma code
void main()
{
init(); /* Intialisation for EUSART control */
while(1) /*Continous Loop*/
{
Nop();
}
}
void init()
{
/* Interrupt Setup */
INTCON = 0x00; /* Clear Registers */
PIR1 = 0x00;
PIE1 = 0x00;
TMR1L = 0x00;
TMR1H = 0x00;
T1CON = 0x00;
RCON = 0x00;
RCONbits.IPEN = 1; /* Set Priorities */
INTCONbits.GIEH = 1; /* Enable global Interupt */
INTCONbits.GIEL = 1; /* Enable peripheral interrupt */
T1CONbits.RD16 = 1; /* Enable 16bit read/write of timer. */
T1CONbits.T1CKPS1 = 0; /* Set Prescaler 1:1 */
T1CONbits.T1CKPS0 = 0;
T1CONbits.TMR1CS = 0; /* Increment every instructrion cycle */
T1CONbits.TMR1ON = 1; /* Enable the timer */
PIE1bits.TMR1IE = 1; /* Enable timer1 interrupt */
/* Load timer for interupt every 0.9525m seconds */
TMR1H = 0xF1; /* Load timer1 higher byte */
TMR1L = 0x1D; /* Load timer1 lower byte */
//PIE1.TMR1IE = 1;
/* Port Set Up*/
TRISA = 0x00; /* Set all pins for ouputs. */
TRISB = 0x00;
TRISC = 0x00;
TRISD = 0x00;
TRISE = 0x00;
/* PWM Setup */
PTCON0 = 0x03; /* 1:1 post and prescaler. Continuos up/down*/
/*mode with double updates.*/
PTCON1 = 0x80;
//PTCON.PTEN = 1; /* Turn on the time base. */
PWMCON0 = 0x40; /* Enable PWM 0,1,2,3,4 and 5 pins for PWM. */
/*And put them in complementry output mode. */
//UNDIS = 0; /* Enable updates of duty cycle. */
PTPERH = 0x07; /* Load the time base perod (1050Hz) */
PTPERL = 0x71;
PDC0H = 0x07; /* Duty Cycle of Half */
PDC0L = 0x71;
PDC1H = 0x07;
PDC1L = 0x71;
PDC2H = 0x07;
PDC2L = 0x71;
}