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.
void main() {
TRISD=0;
PORTD=0;
T2CON=0b01111011;
PEIE_bit=1;
GIE_bit=1;
TMR2=0;
TMR2IE_bit=1;
TMR2IP_bit=1;
while (1){
TMR2IF_bit=0;
PR2=0b11111111;
TMR2ON_bit=1;
if (TMR2IF_bit==1){
PORTD=~PORTD;
TMR2ON_bit=0;
}
}
}
void main() {
TRISD=0;
PORTD=0;
T2CON=0b01111011;
//PEIE_bit=1;
//GIE_bit=1;
TMR2=0;
//TMR2IE_bit=1;
//TMR2IP_bit=1;
TMR2ON_bit=1;
PR2=0b11111111;
while (1){
if (TMR2IF_bit==1){
TMR2IF_bit=0;
PORTD=~PORTD;
}
}
}
Note I moved setup code to before the while loop and remed out the interrupt code.
void interrupt() {
if (TMR2IF_bit==1){
TMR2IF_bit=0;
Count100th++;
}
}
void main() {
PEIE_bit=1;
GIE_bit=1;
TRISD=0;
T2CON=0x4d; //Timer2 on, pre=4, postscaler 10
PR2=249; //PR2=249 gives a 10mS interval
TMR2IF_bit=0;
TMR2IE_bit = 1;
while (1){
if(Count100th==25){
Count100th=0;
PORTD=~PORTD;
}
}
}
while (1){
TMR2ON_bit=1; //turn on the timer
if (TMR2IF_bit==1){ //poll for the flag bit to go high
PORTD=~PORTD;
TMR2IF_bit=0; //reset the flag bit
TMR2ON_bit=0; //stop the timer
}
}