如何用C语言复位PIC18?
通过 HiTech Pic18 C 编译器使用 C 代码重置 PIC18 的最佳方法是什么?
编辑:
我正在使用
void reset()
{
#asm
reset
#endasm
}
,但必须有更好的方法
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
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(6)
编译器通常内置有自己的 Reset() 函数,但它只是完全执行您的函数的操作,并且实际名称可能因编译器而异。
您已经以最好的方式做到了。
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.
您的回答是我所知道的最好的方法。 关键是您在函数调用中拥有汇编指令,全部都是单独的。
编译器不会优化包含内联汇编的函数,因此,如果将重置指令内联到非常大的函数中,编译器将不会优化该函数中的任何代码。 您可以通过将 Reset 放入其自己的函数中来避免这种情况。 该函数中的代码不会被优化,但谁在乎呢,因为它是一个很小的函数。
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.
这里有一个常见问题解答。
问:如何重置微控制器?
There's a FAQ here.
Q: How do I reset the micro?
由于 Mike 编辑了 11 年前的这个原始问题,因此原始海报是否需要全面的答案似乎值得怀疑。 事实上,在过去 9 年里,OP 似乎只询问或回答了 2 个有关微控制器的主题。
考虑到所有这些,了解使用使用 Hi-Tech C 或 XC8(现在由 Microchip 称为)编译的代码从复位向量开始执行 PIC18F 控制器的一些方法可能会有所帮助。
该代码已使用 MPLABX v5.25、XC8 v2.05 和 PIC18F45K20 控制器进行了测试。
As Mike has edited this original question from 11 years ago it seems doubtful the Original Poster needs a comprehensive answer. In fact the OP seems to have asked about or responded on just 2 topics regarding microcontrollers in the past 9 years.
Given all that it may be helpful to look at some of the ways the PIC18F controller can be caused to begin execution from the reset vector with code that compiles with Hi-Tech C or XC8 as it is now called by Microchip.
This code has been tested using MPLABX v5.25, XC8 v2.05 and the PIC18F45K20 controller.
除非编译器供应商的运行时库定义了一个库函数(如果这样的库甚至存在于微控制器世界中......但它应该),那么就不会。 C 本身当然不会帮助你,做“重置”对于 C 来说是一个平台特定的问题,无法涵盖它。
Unless there's a library function defined by the compiler vendor's runtime library (if such a lib even exists in the microcontroller world ... but it should), then no. C itself certainly won't help you out, doing "a reset" is far too much of a platform-specific issue for C to cover it.
我使用 ccsinfo.com 编译器,它有一个类似的 API 调用来重置 PIC,但我认为编译器的解决方案会做正确的事情。
I use the ccsinfo.com compiler, which has a similar API call for resetting the PIC, but I would think the compiler's solution would do the right thing.