Hello,
From your code, it appears you wish to generate a two second delay, to allow closing of a (circuit) breaker. With this sort of delay, and assuming you don't need very high resolution and accuracy, the following simple approach might suffice - simply count an integral number of timer overflows to represent your delay value.
You do not say which HC08 device you are using, nor the bus clock frequency, however for a bus frequency of 3.2 MHz, and assuming a timer prescale setting of 1, timer overflow would occur each 20.48 ms. This would represent the accuracy and resolution of the delay (ignoring errors for the bus frequency).
For a delay of 2 seconds, the number of overflows required to be counted is 98, but because of the timing uncertainty before the first overflow occurs, the actual multiple would lie somewhere between 97 and 98 for this simple method.
You would need to declare a global variable -
word counter;
Timer overflow interrupt would be used, and within the ISR, the following line would be included -
if (counter) counter--; // Decrement if non-zero value
Then, whenever you needed a delay within main(), or elsewhere, the following code could be used -
// Commence delay
counter = 98; // 2-second delay for 3.2 MHz bus
while (counter) // Wait until counter decrements to zero
__RESET_WATCHDOG();
Other more accurate (and more complex) methods are possible, but this method might possibly meet your current needs.
Regards,
Mac