Follow along with the video below to see how to install our site as a web app on your home screen.
Note: This feature may not be available in some browsers.
#include <stdio.h>
#include <stdlib.h>
#include<xc.h>
#include "config.h"
#define _XTAL_FREQ 4000000 //4 MHz..
unsigned char count=0;
unsigned char sine[20]={ 0, 78, 155, 227, 294, 354, 405, 446, 476, 494, 500, 494, 476, 446, 405, 354, 294, 227, 155, 78};
void __interrupt() my_ISR(void)
{ if(TMR2IF==1)
{
count++;
if(count>=20)
{
count=0;
}
CCPR1L=(sine[count]>>2);
CCP1X=(sine[count]&2);
CCP1Y=(sine[count]&1);
TMR2IF=0;
RB0=~RB0;
}
}
int main(int argc, char** argv) {
CCP1M3 = 1;
CCP1M2 = 1; // activating PWM mode..
TRISC = 0; // The CCP1 Output Pin (PWM)
// Set The Prescale For Timer2 (1:4 Ratio)
TRISB0=0;
RB0=1;
T2CKPS0 = 1;
T2CKPS1 = 0;
PR2=124 ;//setting frequency for pwm, 2khz..
TMR2=0;
TMR2IF=0;
GIE=1; // activating interrupts..
PEIE=1;
TMR2IE=1;
TMR2ON=1;
//CCPR1L=64;
while(1)
{
// go on....
}
return 0;
}
#include <stdio.h>
#include <stdlib.h>
#include<xc.h>
#include "config.h"
#define _XTAL_FREQ 4000000 //4 MHz..
unsigned char count=0;
unsigned char sine[20]={ 0, 78, 155, 227, 294, 354, 405, 446, 476, 494, 500, 494, 476, 446, 405, 354, 294, 227, 155, 78};
void __interrupt() my_ISR(void)
{ if(TMR2IF==1)
{
count++;
if(count>=20)
{
count=0;
}
CCPR1L=(sine[count]>>2);
CCP1X=(sine[count]&2);
CCP1Y=(sine[count]&1);
TMR2IF=0;
RB0=~RB0;
}
}
int main(int argc, char** argv) {
CCP1M3 = 1;
CCP1M2 = 1; // activating PWM mode..
TRISC = 0; // The CCP1 Output Pin (PWM)
// Set The Prescale For Timer2 (1:4 Ratio)
TRISB0=0;
RB0=1;
T2CKPS0 = 1;
T2CKPS1 = 0;
PR2=124 ; //setting frequency for pwm, 2khz..
TMR2=0;
TMR2IF=0;
GIE=1; // activating interrupts..
PEIE=1;
TMR2IE=1;
TMR2ON=1;
while(1)
{
// go on....
}
return 0;
}