Tool/software: Code Composer Studio
Hi,
I was wondering about the correct flow of program while using interrupts and its difference from Polling technique.
Lets say I want to perform a task A when a switch on P1.0 is pressed.
1. Polling method - Keep looking at P1.0. When the switch press is detected, perform Task A
2. Interrupt method - Tie an interrupt to P1.0. When switch is pressed, an interrupt is triggered. In the ISR, a global flag is flipped.
My concern with the interrupt technique is that I am still always polling for the flag status to change.
In that case does is matter that we do the polling of the switch itself (P1.0) or do polling of a flag variable?
Please verify if the below flow of program is correct way of implementing the code. Lets say I want to turn on an LED for 1 sec and then turn it off.
P1OUT |= BIT1 ; //Turn LED on P1.1 ON
start1sectimer(); //Code to setup and start 1 sec timer with interrupt
while (timerflag==1); //wait here until 1 sec is elapsed and timerflag is flipped
P1OUT &= ~BIT1; // Turn LED off when 1sec elapsed
--------------ISR-----------
timerflag=0 //flip timerflag when ISR is invoked