MCLR Reset - Please Explain

For questions and comments on programming in general. And for any items that don't fit into the forums below.

Moderators: Benj, Mods

Post Reply
Ron
Posts: 225
Joined: Wed Apr 11, 2007 6:15 pm
Has thanked: 2 times
Contact:

MCLR Reset - Please Explain

Post by Ron »

Hi,

I have written a simple program that reads an eeprom address many times. I need to use 2 different loop vars in order to count high enough. I have a block at the top if the flowchart to init the first loop var (Loop_1 type INT) to it's proper value of -30000. With each loop I INC Loop_1 until I reach +30000. Then I INC Loop_2 (BYTE) and go back and re-init loop_1 to -30000 and start over. I do this until Loop_2 reaches 50.

Since Loop_2 needed to start at 0 I did not put it into the Int block at the top of the flowchart.

The first time I run the program it appears to run fine, it takes about 20 seconds to read this eeprom address 60000 * 50.

If I press reset PB (MCLR to ground), the program starts and appears to be done almost instantly, should have taken about 20 seconds.

I then went back into the program and added Loop_2 = 0 to the init block.

Now when I run the program via HW reset it appears to work properly.

I assumed (shame on me) that the program area of the PIC would be reset on a HW reset. It appears that it does not reset.

1) Am I correct in my findings that pressing the reset button does not reset all program VARS?

2) If I am correct in 1 above, other than unplugging power to the PIC, is there a way to force the PIC to fully reinitialize?

Thank you,

Ron

User avatar
Benj
Matrix Staff
Posts: 15312
Joined: Mon Oct 16, 2006 10:48 am
Location: Matrix TS Ltd
Has thanked: 4803 times
Been thanked: 4314 times
Contact:

Re: MCLR Reset - Please Explain

Post by Benj »

Hello Ron

Variables and some registers will always startup in an unknown or undefined state independant of reset or power down etc. It is always best to initialise variables in situations where you are reading the value in the variable before assigning a new value to the variable.

Hope this makes sense.

Post Reply