Code:
and in main loop---------->>
while(true){
while(!delayFlag); // stucking here
printToArduino("I am a delay!!");
}
The code will try to repeat until 'delayFlag' is zero and your print code is probably delaying the loop so it can't get back to check in time for the next time it is zero again. It is possible there is also something in 'timerInterruptFired()' that causes problems, especially if there is more than one timer running. Try replacing it with "if(INTCONbits.T0IF)" so it only checks Timer 0.
You can fix it by adding a line to load a value into delayFlag again after the 'while' line or a better method that probably uses less code is to reverse the way it counts. For example, instead of
Code:
if (delayCount == delayTime) { //delayTime = 4
delayCount = 0;
delayFlag = 1;
}
use
if (delayCount == 0) {
delayCount = 4; //delayTime = 4
delayFlag = 1;
}
and make the '++' into '--'
Note that you should declare 'delayFlag' as volatile and make sure some sensible values are in ledCount and delayCount at the start of your program or it could take longer than expected for the values to fall inside the test range.
Brian.