16PIC877A Reset with C code

4.4k views Asked by At

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?

4

There are 4 answers

15
Jonathon Reinhart On

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
EBlake On

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

0
cup On

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

#asm
RESET
#endasm

// do it again the other way...
asm("RESET");
0
Er Prakash Kumar On

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.