imranahmed
Advanced Member level 3
- Joined
- Dec 4, 2011
- Messages
- 822
- Helped
- 3
- Reputation
- 6
- Reaction score
- 3
- Trophy points
- 1,298
- Location
- Karachi,Pakistan
- Activity points
- 6,533
if (PIR1bits.TMR1IF==1)
{
PIR1bits.TMR1IF=0;
count++;
TMR1H = 0xD2; // you have to load the timer value in the interrupt routine also
TMR1L = 0x38;
Flag=1; // flag to say 1sec elapsed
Timer1bits.TMR1ON=0; // stop timer1
}
while(1)
{
Count=0;
Timer0=0; // init value timer0 to zero
Timer0.bits.TMR0ON=1; // enable counting
// wait fro one second
while(Flag==0)
{
if (Timer0.bits.TMR0IF==1)
{
Count=Count+65535; // sumarize all counter overflows
Timer0.bits.TMR0IF=0;
}
}
Flag=0;
Value=value + (long) Timer0; // add the rest inside the timer0
/*
here you have the nb of pulses during 1 seconde..
Count is in Hertz
then convert to RPM
and display
*/
}
volatile int Sec ; // compteur de secondes
volatile int count;
volatile int Flag;
if (PIR1bits.TMR1IF==1)
{
PIR1bits.TMR1IF=0;
count++;
TMR1H = 0x48; // you have to load the timer value 18660 in the interrupt routine also
TMR1L = 0xE4;
if (count>8)
{
Flag=1; // one second elapsed used for TMR0 counting
count=0;
Sec ++; // increment secondes
}
}
void main()
{
Sec=0;
count=0;
......
while(1)
{
Count=0;
Timer0=0; // init value timer0 to zero
Timer0.bits.TMR0ON=1; // enable counting
// wait fro one second
while(Flag==0)
{
if (Timer0.bits.TMR0IF==1)
{
Count=Count+255; // sumarize all counter overflows
Timer0.bits.TMR0IF=0;
}
}
Flag=0;
Value=value + (long) Timer0; // add the rest inside the timer0
/*
here you have the nb of pulses during 1 seconde..
Count is in Hertz
then convert to RPM
and display
*/
#include<htc.h>
__CONFIG(FOSC_HS & WDTE_OFF);
#define _XTAL_FREQ 2000000
unsigned char x;
unsigned int COUNT=0;
int1 interrupt_flag = 1;
void interrupt_isr()
{
if(INTCONbits.INTF==1)
{
INTCONbits.INTF=0;
interrupt_flag = 0;
}
if(PIR1bits.TMR1IF == 1)
{
PIR1bits.TMR1IF=0;
COUNT++;
TMR1L=0xDB;
TMR1H=0x0B;
}
}
void main()
{
CMCON=7;
ADCON0=0;
TRISC=0;
TRISD=0;
T1CON=0b00110101;
PIR1=0b00000001;
PIE1=0b00000001;
OPTION_REG=0b11000000;
INTCON=0b11010010;
while(1)
{
PORTC=COUNT;
if(interrupt_flag==0)
{
for(x=0;x<=5;x++)
{
PORTD=255;
__delay_ms(500);
PORTD=0;
__delay_ms(500);
}
}
interrupt_flag = 1;
}
}
Code C - [expand] 1 INTCONbits.RBIF==1
Code C - [expand] 1 INTCONbits.INTF==1
We use cookies and similar technologies for the following purposes:
Do you accept cookies and these technologies?
We use cookies and similar technologies for the following purposes:
Do you accept cookies and these technologies?