Understanding PIC18F4550 interrupts and indirect addressing mode

Thread Starter

corsair

Joined Mar 6, 2010
51
I've looked at a ton of examples for interrupts and indirect addressing modes for PICs and they all seem very confusing for me. I just can't seem to understand it.

So, I'm going to try to make an example, and if you guys could point me in the right direction, I would greatly appreciate it.

Problem:
1) I want to store an array of integers somewhere in memory. Let this list be very simple such as:
Rich (BB code):
my_array:
	retlw 0x1
	retlw 0x2
	retlw 0x3
	retlw 0x4
2) I want to access the array using a counter.

So, I was wondering if it would be something like this...

Solution:
** - Indicate parts that I am really confused about
Rich (BB code):
INT_CNT res 1         ; variable for interrupt counter

org 0x1000       ; goto main on start-up
    goto main

org 0x1018       ; goto low interrupt service routine
    goto low_isr

displayW macro         ; displays contents of W onto a 7-segment display
      ;.....stuff that you dont need to know
      endm

main:
        bsf INTCON,TMR0IE      ; Enable Timer0 Interrupts
        bcf INTCON2,TMR0IP    ; TMR0 Interrupt Priority = LOW
        movlw 0x8F                 ; Timer0 Config (Timer Mode)
        movwf T0CON              ; 16-bit, internal clock, 1ms calling intervals
	movlw 0x0           	; Initialize INT_CNT to 0
        movwf INT_CNT
        movlw my_array           ; **Want to put address of my_array into FSR0
        movwf FSR0

main2 
        sleep                          ; Must be woken up from ISR
 	bra main2

my_array:
	retlw 0x1
	retlw 0x2
	retlw 0x3
	retlw 0x4

low_isr:
        incf INT_CNT,F                 ; INT_CNT = INT_CNT + 1
        movlw INDF0+INT_CNT        ; **Want to access my_array + offset
        displayW                          ; displays contents of W on screen
        movlw 0x4                       ; If INT_CNT == 4, reset to 0
        cpfseq INT_CNT                ; Else return
        retfie
        movlw 0x0
        movwf INT_CNT
        retfie
if you guys can manage to understand what i am confused about, then god bless you :D
 

Thread Starter

corsair

Joined Mar 6, 2010
51
things i've already found:
1) need to enable global interrupts: bsf INTCON,GIE
2) need to clear interrupt flag: bcf INTCON,TMR0IF in the ISR
3) saved W and STATUS before ISR and restored it
4) cant wake up from "sleep" since TMR0 interrupts are disabled (when sleeping)

but still not working :(. it seems like its just not even going to the ISR at all..
 
Last edited:

Thread Starter

corsair

Joined Mar 6, 2010
51
good god, after banging my head across my desk for a few days, i finally got the interrupts to work. its all about the configuration...
 
Top