Hello, I am working on an autonomous robot for a university robotics club. I am trying to program a system that periodically interrupts and performs a different action from a sequential list of instructions. I've done this before using pure assembly with the P&E WinIDE on the same chip, so it shouldn't be too difficult in Codewarrior, but it has been. I can't seem to find a way to load a label into a variable. I've tried using something like this: void *address = &&Label_1
but CodeWarrior does not seem to recognize &&. I tried using inline assembly to mark off each label using something like this: __asm Label_1: ; // define a label __asm LDD #Label_1; //load the address of the label into accumulator D
but Codewarrior gives me an error saying that Label Addressing mode is not supported!
So if someone knows how to make one of these methods work, that would be great. Or, if you know of a fast alternative (does not use many cpu cycles since this is a fairly short periodic timer interrupt), please let me know.
Here is an idea of the actions I want to take place: [In init, define a label variable with the address of init] [Interrupt occurs] [goto/BRA to the label]
Init: // perform any initialization that only occurs on first interrupt . . . [Load Step1 address into variable] - This is where the problem occurs [Return from Interrupt]
Step1: . . . [Load Step1 into variable] - problem again [Return from Interrupt]
... Step2: // Assume this is the last step . . . [Load Step1 into variable to start sequence all over] - problem again [Return from Interrupt]
Notice that this method does not need to perform ANY checks after the interrupt, it simply performs a goto/BRA, and starts into that stage of execution. Thanks for any help you can provide with this!
This is really a C programming question rather than anything to do with the S12, so you may have more luck in the CodeWarrior forum.
Goto is regarded as "infinitely abusable" and "never necessary" by the creators of C so you should avoid using this approach if possible.
If you have a finite set of labels you can simply store the function number in a variable and call the relevant function using a switch statement. Alternatively, you can pass a pointer to the function you want but that is adding a lot of complexity that probably isn't necessary here.
If the initialisation is known at compile time you can just use macros to select the appropriate function.