I have been programming the MC9S08JM16 in Relocateable Assembly using CodeWarrior 6.2 for one month. I have read the data sheet, browsed the forums, and done the occasional Google search. I wanted to work through as much as I could on my own for one month BEFORE I made my first post. (My background is Java programming and development for the last 12 years.) Here are a few unanswered questions I still have:
1) How can you keep an accurate clock? I'm not so worried about being a second or two off every day, but from what I can tell any clock is an interrupt that calls an ISR to update a counter. So if another interrupt happens, and takes 7 seconds to perform it's duty, won't the clock then be 7 seconds off? Also, if within this other interrupt, I need to use my clock counter to count to 3 seconds, I won't be able to because the clock interrupt wont happen (the interrupt mask bit is clear). I don't see using the TPM, MCG, or RTC as a solution to this problem. Also, I know you can re-enable interrupts (by acknowledging the current interrupt flag and using the instruction CLI), but then before my clock interrupt happens, the original interrupt occurs again (ie someone holding down a button.) I know you can software poll the interrupt flags in RTC and TPM, but that seems ridiculous to add that poll to then end of EVERY loop in my code that could possible last longer than my clock tick (which usually would be 1-10 ms.) So what am I missing. What keeps a fairly accurate time of day in the background, while my MC is performing its daily functions?? (Once again 'accurate' is not too relevant, as long as it can say it's within 2 or 3 minutes of 9PM or 7AM etc.)
2) I believe the JM16 has a 24 MHz internal bus frequency. Doesn't that mean each cycle count is 1/24 us? So 24 cycles would be 1 us? I have a subroutine that takes exactly 24 cycles and can be run 'x' amount of times, usually 20 or 50 as I often need to count 20 or 50 micro-second intervals. So is 24 cycles 1 us (micro-second) on the JM16??
3) Odd question, and maybe dangerous programmatically, but let's say my KBI calls a subroutine, that then calls another subroutine, that then calls a 3rd subroutine, so we are nested 3 deep. I actually don't think this is too uncommon, with the lack of execution control in assembly. Anyway, subroutine '3' doesn't like what it sees, so I set a bit, BSET, as a flag, call 2 RTS's reading/checking this flag, and eventually the original subroutine see's the flag and calls RTI. Could I just have called an RTI from the third nested subroutine and the execution would have automatically "jumped" out and picked up where it left off when the original interrupt occurred??
Ok, three long questions is enough for now. It's has been a challenge going from a HLL like Java to Assembly, but I'm starting to see the benefits. A lot of what I'm 're-learning' is the program flow and control, and the use of variables. I quick hints or tricks of the trade would be appreciated. Thank you in advance for any answers, help, or suggestions.