Another question included this program:
void main(void){
TRISD = 0x00;
PORTD = 0xFF;
}
Let us assume that it does exactly what was intended up through the last line of main()
.
My question is, what happens in a PIC18F4550 when the flow of control falls off the end of main()
? I assume any decent PIC programmer will fill the instruction space after main()
with either all-1s or all-0s, but I don't know which.
I can see from the PIC instruction set docs that an all-zeroes instruction is NOP
, which is harmless in itself, but what happens when the program counter hits the end of the instruction space? Does it wrap around, halt, catch fire, emit monkeys...?
If PIC programmers fill program space with all-1s instead, as in an empty EEPROM, it appears that that will be an ADDLW
instruction that adds 0xFF to W
. If that is correct and we don't care about what happens to W
, is this the same as the NOP
case?
Do the answers to the above questions argue for doing something else, such as running an infinite loop to prevent execution from leaving main()
? I don't think we can sleep the microcontroller here, since that won't keep the port D lines up indefinitely, as the OP wanted.