|||
You may type cast the address of the reset vector (0x0000) to a pointer and call that from C using the following:
((void (code *) (void)) 0x0000) ();
For example, the following program continuously resets itself.
void reset (void)
{
((void (code *) (void)) 0x0000) ();
}
void main (void)
{
reset ();
}
You should note that the software reset sequence above does not clear the 8051 interrupt system or reset any 8051 peripherals. When the above code is executed inside an interrupt routine, the 8051 blocks subsequent interrupts. Therefore, this sequence cannot be used in interrupt service routines.
The following small assembly may be called from interrupt routines or from your main program. It works by pushing a return of 0x0000 onto the stack and executing an RETI instruction (to return from interrupt). This clears any interrupt conditions and starts program execution from 0000h.
?PR?RESET SEGMENT CODE
RSEG ?PR?RESET
; C prototype: void reset (void);
PUBLIC reset
reset: POP ACC ; pop return address
POP ACC
CLR A ; push 0 as new
PUSH ACC ; return address to stack
PUSH ACC
RETI ; execute return of interrupt
END
This works well when register bank 0 is selected. If this routine is called and register bank 0 is not selected, the program may not as expected. You should add the following instruction to the above routine or to the startup code to select register bank 0.
MOV PSW, #0