Understanding PIC18F4550 interrupts and indirect addressing mode

Discussion in 'Embedded Systems and Microcontrollers' started by corsair, Mar 29, 2010.

  1. corsair

    Thread Starter Member

    Mar 6, 2010
    51
    1
    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:
    Code ( (Unknown Language)):
    1. my_array:
    2.     retlw 0x1
    3.     retlw 0x2
    4.     retlw 0x3
    5.     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
    Code ( (Unknown Language)):
    1. INT_CNT res 1         ; variable for interrupt counter
    2.  
    3. org 0x1000       ; goto main on start-up
    4.     goto main
    5.  
    6. org 0x1018       ; goto low interrupt service routine
    7.     goto low_isr
    8.  
    9. displayW macro         ; displays contents of W onto a 7-segment display
    10.       ;.....stuff that you dont need to know
    11.       endm
    12.  
    13. main:
    14.         bsf INTCON,TMR0IE      ; Enable Timer0 Interrupts
    15.         bcf INTCON2,TMR0IP    ; TMR0 Interrupt Priority = LOW
    16.         movlw 0x8F                 ; Timer0 Config (Timer Mode)
    17.         movwf T0CON              ; 16-bit, internal clock, 1ms calling intervals
    18.     movlw 0x0               ; Initialize INT_CNT to 0
    19.         movwf INT_CNT
    20.         movlw my_array           ; **Want to put address of my_array into FSR0
    21.         movwf FSR0
    22.  
    23. main2
    24.         sleep                          ; Must be woken up from ISR
    25.     bra main2
    26.  
    27. my_array:
    28.     retlw 0x1
    29.     retlw 0x2
    30.     retlw 0x3
    31.     retlw 0x4
    32.  
    33. low_isr:
    34.         incf INT_CNT,F                 ; INT_CNT = INT_CNT + 1
    35.         movlw INDF0+INT_CNT        ; **Want to access my_array + offset
    36.         displayW                          ; displays contents of W on screen
    37.         movlw 0x4                       ; If INT_CNT == 4, reset to 0
    38.         cpfseq INT_CNT                ; Else return
    39.         retfie
    40.         movlw 0x0
    41.         movwf INT_CNT
    42.         retfie
    if you guys can manage to understand what i am confused about, then god bless you :D
     
  2. corsair

    Thread Starter Member

    Mar 6, 2010
    51
    1
    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: Mar 29, 2010
  3. corsair

    Thread Starter Member

    Mar 6, 2010
    51
    1
    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...
     
Loading...