16PIC877A Reset with C code

夙愿已清 提交于 2021-01-29 03:06:14

问题


I am using PIC16F877a and I need program reset without using button. When I looked at datasheet and referance designs, there is a button on MLCR pin. If button was pushed, MCU was reset. But I need reset that can control with C code, I don't want to use reset button. Is there another way to do it?


回答1:


PIC 8-bit MCUS have a software reset assembly instruction:

RESET

reset instruction

http://microchip.wikidot.com/8bit:rst

You will have to use inline assembly. I've never used inline assembly for a PIC, but from this page it looks like this is the correct syntax for MPLAB:

void soft_reset(void)
{
    _asm
        reset
    _endasm
}

Do note that, as the linked page states, an external watchdog timer is generally a better way to trigger a full system reset. With a soft reset, external devices are not also reset. With an external WDT, you simply stop petting the watchdog, and then it resets the whole board.




回答2:


The format for MPLABX XC16 (assuming that this is the compiler you are using) is:

__asm__ volatile ("reset");

Depending on your processor, you can also examine the contents of the RCON register on startup to find out the cause of the reset (MCLR, software, watchdog timer, brownout, etc.)




回答3:


For XC8, use #asm and #endasm. Using the example from the XC8 manual

#asm
RESET
#endasm

// do it again the other way...
asm("RESET");


来源:https://stackoverflow.com/questions/41395154/16pic877a-reset-with-c-code

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!