abhi4u_84
Newbie level 1
hi there i require help on PIC16F917, i am an amature for PIC . i have never done programing. its my MSc progect to generate an square wave using Interrupt. i have written some code but its not working accordingly. i want to generate an square wave of 100 Khz-1 Mhz. but i am able to get only 21 Khz fixed frequency. i am not even able to vary the period need your help
My code:
#include<stdio.h>
#include<htc.h>
//Main Interrupt Service Routine (ISR)
void interrupt ISR()
{
int i;
OSCCON=0x70;
//Check if it is TMR2 Overflow ISR
if(TMR2IE && TMR2IF)
{
//TMR2 Overflow ISR
// counter++;
//if(counter==10)
{
//Toggle RB1
//if(RB1==0)
RB1 =~ RB1;
//else
// ; RB1=0;
// counter=0; //Reset Counter
//}
//Clear Flag
TMR2IF=0;
TMR2=255;
}
}
// T2CON=0x00;
}
void main(void)
{
IRCF2=1;
IRCF1=1;
IRCF0=1;
int i,a;
OSCCON=0X70; // 8 Mhz 8
TRISA=0X03; // input port 1 & 2
TRISB=0X00; //output port
ANSEL=0x03; //selecting channel 1 & 2;
ADCON1=0X50; // fosc/ 16
ADCON0=0X81; // right justified
INTCON=0xC0; // enabling PEIE & GIE
T2CON=0x04; //timer 2 on
TMR2IE=1;
TMR2=0;
PR2=0xFF;
T2CON=0x04; //timer 2 on
//while(1)
while(!TMR2IF);
{
interrupt isr();
}
}
My code:
#include<stdio.h>
#include<htc.h>
//Main Interrupt Service Routine (ISR)
void interrupt ISR()
{
int i;
OSCCON=0x70;
//Check if it is TMR2 Overflow ISR
if(TMR2IE && TMR2IF)
{
//TMR2 Overflow ISR
// counter++;
//if(counter==10)
{
//Toggle RB1
//if(RB1==0)
RB1 =~ RB1;
//else
// ; RB1=0;
// counter=0; //Reset Counter
//}
//Clear Flag
TMR2IF=0;
TMR2=255;
}
}
// T2CON=0x00;
}
void main(void)
{
IRCF2=1;
IRCF1=1;
IRCF0=1;
int i,a;
OSCCON=0X70; // 8 Mhz 8
TRISA=0X03; // input port 1 & 2
TRISB=0X00; //output port
ANSEL=0x03; //selecting channel 1 & 2;
ADCON1=0X50; // fosc/ 16
ADCON0=0X81; // right justified
INTCON=0xC0; // enabling PEIE & GIE
T2CON=0x04; //timer 2 on
TMR2IE=1;
TMR2=0;
PR2=0xFF;
T2CON=0x04; //timer 2 on
//while(1)
while(!TMR2IF);
{
interrupt isr();
}
}