need help with PWM,Interrupt and Timer0 coding in C language
Posted: Tue Mar 03, 2009 12:40 pm
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;
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
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum