News:

Let's find out together what makes a PIC Tick!

Main Menu

How to reset PIC

Started by drewdavis, Aug 13, 2024, 06:53 AM

Previous topic - Next topic

drewdavis

Hi everyone,

I want to reset my PIC how to do it and when resetting will the bit data table be changed?

Thank you!

John Lawton

I assume you want a software reset?

What PIC are you using?

John

SCV

ASM
     reset
ENDASM

Has always worked for me.

Maxi


top204

#4
As stated above, the 18F devices and the enhanced 14-bit core devices have a Reset mnemonic, that has been brought out to the BASIC language, so just use it as a command:

Reset

This will perform a hardware reset and re-start the device, but will keep the contents of user RAM as it was, unless you have a Clear command within the code listing, which will clear all user RAM at device start-up.

Note that some SFRs (Special Function Registers) will revert to their start-up values, so they will need to be re-initialised again.

John Lawton

Hi Les,

interesting, I did not know of that command. Maybe add it to the manuals?

John

top204

#6
It's a device mnemonic John, and they are all brought out into the High Level Language. So in BASIC, you can do something like:

Dim MyByte As Byte

Movlw 127
Movwf MyByte
Btfsc STATUS,C

etc....

So simple form mnemonics are allowable in the high-level language as well, but be careful, because they do not alter RAM or page banks, and do not support the more complex parameters in the mnemonics. For the more complex mnemonic parameters, wrap them in Asm-EndAsm.

See the Asm..EndAsm section in the compiler's manual.

Also, when used within a procedure, the variable names and symbols are raw because the mnemonics are passed directly to the assembler (with a bit of checking to see if they are valid for the device), so the procedure name precedes the variable name.

Wimax

Hi Les,

Is there something similar for 16 bit devices ?

top204

#8
If you look at the "Instruction Set Summary" section in a PIC24 or dsPIC33 device's datasheet, you will see they also have a Reset mnemonic, and as with the 8-bit devices, the simplified mnemonics are brought out to the high level language.

This means that the Reset mnemonic can be placed in the code listing.

I've just noticed it does not highlight as a mnemonic for a 16-bit device in the IDE, so I have just corrected that in the "database.mcd" file, with the change listed below:

KEY ("Reset")
    Devicecore = [dc14, dc16, dc24, dc33]
    Highlighter = KeywordASM
ENDKEY


Wimax

Thank you very much  ;)

GERARD

Hello,
what's the point of doing a software reset?
I am the happy grandpa of twins

diebobo

I use it for example to force a controlled restart to enter bootmode.

Parmin

Often reset is useful when getting out of brownout or such to ensure every setting is done properly.

top204

As stated above, I have also, often used the Reset mnemonic to re-start the device if defaults are being placed, or a bootload is required, via a signal from another device.

This saves having to bring out the MCLR line to a serial interface, and a command is received to state a bootload is required, and the device is reset so the bootload can take place. It is a very handy mnemonic.

GERARD

I don't really understand.
Where in the program is the RESET command placed?
I am the happy grandpa of twins

top204

#15
Wherever the Reset mnemonic is within the code listing is when the device reset will happen.

For example, a pseudo template could be:

If MyButton = 1 Then
    Reset
EndIf

So the device will reset upon a button press.

Wimax

So there is no need to force the MCRL pin for this, you can use this to bootload using a serial link as suggested by Les before

top204

QuoteSo there is no need to force the MCRL pin for this, you can use this to bootload using a serial link as suggested by Les before

Yes. The Reset mnemonic performs, essentially, the same task as bringing the MCLR pin down to ground. i.e. It performs a hardware reset of the device, as opposed to just jumping to code address 0.

I've used it in several projects that have a serial interface, but need the ability to also bootload from the serial coms unit controlling it.

GERARD

Thanks to all of you, I learned something new today.
I usually put a BP on the MCLR pin.
I am the happy grandpa of twins

John Lawton

A hardware reset using a pushbutton on the MCLR line will always work as long as MCLR is enabled as hardware reset in the fuses.

If Reset is used in in a code loop it should work to reset the device but may not if the code loop goes haywire such as getting stuck in an interrupt and doesn't then reach that bit of code.

John