vinodstanur
Advanced Member level 3
- Joined
- Oct 31, 2009
- Messages
- 751
- Helped
- 114
- Reputation
- 234
- Reaction score
- 114
- Trophy points
- 1,333
- Location
- Kerala (INDIA)
- Activity points
- 7,054
yes............
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.
You can use timer interrupt and in ISR you can increment some variable.
In PIC16 and 18F families 1 instruction cycle = 4 crystal cycles
#include<pic.h>
__CONFIG(0x3F38); //for Internal oscillator
void interrupt timer0()
{
char count;
if(T0IF == 1)
{
T0IF = 0; //reset flag
count++; // increment counter
if(count == 15) // set timer to count 15 aprox to 1 second delay.
{
RA2 ^= 1; //toggle LED
count = 0; //reset counter
}
}
}
void main(void)
{
TMR0 = 0;
OPTION_REG = 0b0111; // set prescaler to timer 0 and 1:256 prescaler..
T0CS = 0; // timer 0 Internal clock source
T0IE = 1; // enable timer 0 interrrupt
GIE =1; // Enable global interrupt
TRISA2 = 0; //set bit 1 of portB as output.
while(1);
}
where do you disable the interrupt before exiting the ISR routine??
#include<pic.h>
__CONFIG(0x3F38); //for Internal oscillator
char count;
void interrupt timer0()
{
if(T0IF == 1)
{
T0IF = 0;
// PEIE = 0;
count++;
if(count == 15)
{
RA2 ^= 1; //toggle LED
count = 0;
}
// PEIE = 1;
}
}
void main(void)
{
TMR0 = 0;
OPTION_REG = 0b0111; // set prescaler to timer 0 and 1:256 prescaler..
T0CS = 0; // timer 0 Internal clock source
T0IE = 1; // enable timer 0 interrrupt
GIE =1; // Enable global interrupt
TRISA2 = 0; //set bit 1 of portB as output.
while(1);
}
Peie=1; ........