Continue to Site

Welcome to our site!

Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

  • Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

PIC16 beginner questions

easyhermit

New Member
Hey, I consider myself a beginner with PICs even though I've been messing with them for a few years; I just never made anything impressive with them.

I'm reading about interrupts. Mainly the part where you save and then restore the registers in an ISR. I was studying Jon Wilder 's code here: https://www.electro-tech-online.com/threads/pic-timer-interrupt.128914/post-1073925

Code:
ISR:

        movwf        W_TEMP            ;save W
        swapf        STATUS,W        ;save STATUS
        movwf        STATUS_TEMP
        banksel        0                ;bank 0
        movfw        PCLATH            ;save PCLATH
        movwf        PCLATH_TEMP

        ; ISR code

        movfw        PCLATH_TEMP        ;restore PCLATH
        movwf        PCLATH
        swapf        STATUS_TEMP,W    ;restore STATUS
        movwf        STATUS
        swapf        W_TEMP,F        ;restore W
        swapf        W_TEMP,W
        retfie                        ;return to main code

And this code by Diver300 here: https://www.electro-tech-online.com/threads/pic-interrupt-saving-w-and-status.34143/post-261191

Code:
movwf        w_save
swapf         STATUS,w
movwf        status_save
swapf         w_save, f

after the interupt, you should use:-

swapf       status_save, w
movwf      status
swapf       w_save, f
retfie

The first three lines are equivalent, but Diver300 has
Code:
swapf w_save, f
for line 4. What's the purpose of that? Is it important? Also, Jon Wilder saves PCLATH, but Diver300 doesn't. Can someone please explain the differences and reasoning between these two methods?

The datasheet says it swaps nibbles. So does that mean if f = 8Eh, the destination register would be E8h?
 
Last edited:

Latest threads

Back
Top