While I don't know much about the microprocessor and SBC in question (though I have learned that the Rabbit series are extensions of the familiar Z80 and Z180 family), I was able to look up the Wildcat SBC documentation (http://www.rabbitsemiconductor.com/products/bl2000/docs.shtml), the processor op-code reference (http://www.rabbitsemiconductor.com/documentation/docs/manuals/Rabbit4000/InstructionReference/index.html), and for using inline assembly in Dynamic C (http://www.rabbitsemiconductor.com/documentation/docs/manuals/DC/DCUserManual/9assem.htm#1054403). After checking a few things, I can make a few suggestions right off.
First off, you are using a fixed delay loop to time the LED toggling. Now, I usually would recommend against busy-waiting, as fixed timing loops can be rather brittle. However, since this is embedded code, it is not so problematic. What is problematic is way the loop index is updated; if you look carefully at the code in this section, you should find the bug you are looking for.
As a side point, you use two separate, identical code sections to handle the two sets of timeouts, which, aside from taking up extra space on a rather memory-constrainted system, is simply bad design; this is particularly important in this case since it seems likely that the timing loops are the source of the problem you are having. I'm guessing that you professor hasn't covered subroutine calls yet, but fortunately, they are fairly easy to do on this processor using the CALL and RET instructions.
I also noticed that the code for setting and testing the LED status was also duplicated, and could easily be broken out into a subroutine as well; doing this not only saves memory, but makes debugging easier, since it isolates the different parts of the program and allows you to study them independently. Indeed, I probably would not have noticed the loop index problem mentioned above if I hadn't tried re-writing the code this way (see below). [EDIT: I was going to answer the problem outright, but I figured it would be better to give a hint and let you figure it out. :cool: The changes I've made to the code below should make it clearwhere the problem lies; fortunately, you only need to make two trivial changes to fix it.]
In fact, you probably should remove the assembly code from the main() function and put it in it's own function outright. Finally, you should be able to replace the JP (jump absolute) instructions with JR (jump relative) without any trouble, though it's not a big deal either way; similarly, the 'decrement word register and jump if not zero' can be done as a single DWJNZ instruction, though you may need to adjust the timing of the loop to account for the difference in clock cycles it uses.
Below is a modified version of your code following this recommendation (I've also changed the labels to improve readability, and added some debugging printouts):
main()
{
printf("Assembly Language Program Development Assignment: Objective 2");
toggle_led();
/* include a sanity check in case the assembly routine ever exits */
printf("Sanity Check failed: The function toggle_led() ended.");
}
debug toggle_led()
{
#asm
;; the main loop of the code is intended to toggle the
;; LED at location SPCR (or at least this is what I gather)
TOGGLE::
; set the LED, then wait five seconds
LD A, 84h
CALL SET_LED
CALL TIME_OUT
; clear LED, then wait another five seconds
LD A, 0xff
CALL SET_LED
CALL TIME_OUT
JR TOGGLE ; repeat the whole process
; debugging printout, in case the code gets past the loop
; the 'C' directive tells it to switch back to C for
; one line of code
C printf("Sanity Check Failed: Code got past the end of the toggle loop.");
RET ; backstop the function, in case
;it gets past the loop somehow
;; Subroutines
; load value of register A to LED setting register and
; return the value from the LED status
SET_LED::
IOI LD (SPCR),A
IOI LD A,(PBDR)
IOI LD (PADR),A
RET
; count out a timing loop
TIME_OUT::
LD BC, 850
DWJNZ TIME_OUT ; decrement and test BC
RET
#endasm
printf("Sanity Check failed: the assembly code has unexpectedly completed.");
}
Since I don't have access to the compiler and SBC in question, I have no way of knowing if this code is correct, but it should give you a starting point. I would recommend checking out the BIOS (http://www.rabbitsemiconductor.com/documentation/docs/manuals/Rabbit2000/DesignersHandbook/5bios.htm#934141) to see if there's a better alternative to the timing loop (you might want to look at the periodic interrupt (http://www.rabbitsemiconductor.com/documentation/docs/manuals/Rabbit2000/UsersManual/rabbios.htm#936208) and the timer (http://www.zworld.com/documentation/docs/manuals/Rabbit2000/UsersManual/rabsftwr.htm#937424) in particular).