Hi all!
I am using a msp430f2618 board to take pulses from a water flow sensor and the program increments a counter whenever an interrupt occurs.
My program is working fine but I want to reset the counter value to '0' after every 5 seconds.
unsigned int count = 0;
void main(void) {
WDTCTL = WDTPW + WDTHOLD; // Stop watchdog timer
P2IE |= 0x10; // P2.4 interrupt enabled
P2IES |= 0x10; // P2.4 Hi/lo edge
P2IFG &= ~0x10; // P2.4 IFG cleared
while(1) {
_BIS_SR(LPM0_bits + GIE); // Enter LPM0 w/interrupt
wait(5);
printf("Round Over");
_BIC_SR(LPM0_bits + GIE);
count = 0;
}
}
// Port 2 interrupt service routine
#pragma vector=PORT2_VECTOR
__interrupt void Port_2(void) {
count++; // Incrementing the counter when ever an interrupt comes
P2IFG &= ~0x10; // P2.4 IFG cleared
}
static void wait(uint8 sec){
uint8 n;
TACCTL0 &= ~(1<<0);
for(n=0;n < sec;n++){
CCR0 = 32768;
TACTL = TASSEL_1 + MC_1; // SMCLK, upmode
while(!(TACCTL0 & (1<<0)));
TACCTL0 &= ~(1<<0);
}
}