PDA

View Full Version : WRITECODE, ERASECODE, and interrupts



RussMartin
- 5th March 2010, 05:38
For WRITECODE, my PBP manual (2.60) states (p. 176):

If interrupts are used in a program, they must be turned off (masked, not DISABLED) before executing a WRITECODE, and turned back on (if desired) after the WRITECODE is complete.

It recommends using

DEFINE WRITE_INT 1

1. Is this likewise necessary with DT interrupts?

2. Is this also the case with ERASECODE? (The manual does not say.)

3. Is this a toggle?

And . . .

4. The manual gives the syntax:

ERASECODE Block

If a block is 32 words (16F88), may I assume that this can be done in a loop, incrementing the STEP by 32 ($20) each time?

Charles Linquis
- 5th March 2010, 06:27
1. DT interrupts are just ordinary interrupts (except that Darrel has made them easy to use). So normally, I would say YES. But in searching through the PBPPIC14 LIB, I see that WRITE_INT is only used for WRITECODE. It is not used for READCODE or ERASECODE.

Flash READS and ERASES probably aren't so time critical, but It never hurts to turn off interrupts when you don't need them, especially if your ISRs take a long time to run.

2. See above.

3. WRITE_INT is not a toggle. It turns off global int at the beginning of the WRITE and turns them on again immediately after the write.

4. I believe you are correct. I have performed this operation before - but that was several years ago.

RussMartin
- 5th March 2010, 19:50
Thanks, Charles.

The PBP manual says of DEFINE WRITE_INT 1

Disable/enable global interrupts in Write, which is why it sounded like a toggle to me.

Looking at the 16F88 manual at 3.6.1, "FLASH PROGRAM MEMORY ERASE SEQUENCE", Step 3 is "Disable interrupts". Oddly, there is no complementary step to re-enable them. However, the code example 3-4 shows disabling interrupts with

BCF INTCON,GIE

and then enabling them again with

BSF INTCON, GIE

Equally oddly, the example at 3-5 for writing to flash program memory has the BSF at the end but not the BCF anywhere prior.

So . . .

It looks like interrupts do need to be disabled/re-enabled with ERASECODE, too.

Any reason why I can't just use an @ ahead of the above statements instead of the DEFINE? Would it save any time/space?

Charles Linquis
- 6th March 2010, 02:46
You can just put an @ in front - BUT

Disabling interrupts is slightly trickier than just one statement.
Read Microchip AN576