I want to produce a frequency(I use PWM) for a certain period of time(timer0),then interrupt-on-overflow to stop the frequency for another period of time.So i should have tones play at certain interval.Below is my attempt on coding for that purpose and it isn't working...Please help me find where has gone wrong.Thanks !
Code:
/** I N C L U D E S **************************************************/
#include "p18f46k20.h"
#include "delays.h"
#include "12 CCP PWM.h" // header file
#include "08 Interrupts.h"
/** V A R I A B L E S *************************************************/
#pragma udata // declare statically allocated initialized variables
/** D E C L A R A T I O N S *******************************************/
void timer0(void);
#pragma code // declare executable instructions
void main (void)
{
// set internal oscillator to 1MHz
//OSCCON = 0b10110110; // IRCFx = 101
//OSCTUNEbits.PLLEN = 0; //PLL disabled
//PWM settings for a frequency
TRISDbits.TRISD7 = 0; //PWM-pin ON
T2CON = 0b00000101; //timer2 on
PR2 = 240;
CCPR1L = 0x78;
CCP1CON= 0b01001100;
timer0();
while(1);
}
//---------------------------------------------------------------------------
void timer0(void)
{
T0CON=0b10100010; //enable timer0
//timer is configured as 16-bits counter
//transition on TOCKl pin
//increment on low-high transition on T0CKl pin
//set prescaler
//1:8 prescaler
INTCONbits.TMR0IF = 0; //clear roll-over interrupt flag
INTCON2bits.INTEDG0=0; // interrupt is falling edge
INTCONbits.INT0IE=1; // enable interrupt
INTCONbits.GIEH = 1; //enable global interrupts
TMR0H = 0; // clear timer - always write upper byte first
TMR0L = 0;
}
//----------------------------------------------------------------------------
//Low priority interrupt vector
#pragma code InterruptVectorLow = 0x18
void
InterruptVectorLow (void)
{
_asm
goto InterruptHandlerLow
_endasm
}
//-------------------------------------------------------------------------
// Low priority interrupt routine
#pragma code
#pragma interrupt InterruptHandlerLow
void
InterruptHandlerLow ()
{
if (INTCONbits.TMR0IF)
{
LATDbits.LATD7=0;
Delay1KTCYx(10);
INTCONbits.TMR0IF=0;
}
}