简体   繁体   中英

16PIC877A Reset with C code

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?

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

RESET

复位指令

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.

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.)

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

#asm
RESET
#endasm

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

A microcontroller needs to be reset to get to a known state before program execution. Reset is typically generated by hardware signal from external sources, for example, you might find a reset button on the development board. Most microcontroller devices have an input pin for reset.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM