Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to reset a PIC18 in C?

What is the best way to reset a PIC18 using C code with the HiTech Pic18 C compiler?

Edit:

I am currenlty using

void reset()
{
#asm 
  reset
#endasm
}

but there must be a better way

like image 569
Charles Faiga Avatar asked Dec 09 '22 22:12

Charles Faiga


2 Answers

The compilers usually have their own reset() function built in, but it just does exactly what your function does, and the actual name may vary from compiler to compiler.

You are already doing it the best possible way.

like image 74
MrZebra Avatar answered Jan 27 '23 22:01

MrZebra


Your answer is the best way I know of. The key is that you have the assembly instruction inside a function call, all by itself. The compiler will not optimize a function that has inline assembly in it, so if you include the reset instruction inline to a very large function, the compiler will not optimize any of the code in that function. You have avoided this by putting Reset in its own function. The code in this function won't be optimized, but who cares, since it is such a small function.

like image 32
Brent Avatar answered Jan 28 '23 00:01

Brent