16F1827 ASM Interrupt


Closed Thread
Results 1 to 5 of 5

Hybrid View

  1. #1
    Join Date
    Apr 2010
    Posts
    5


    Did you find this post helpful? Yes | No

    Default Re: 16F1827 ASM Interrupt

    Thanks Darrel that clears up why things were not working as I expected!

    Most things are working great now except one very strange thing. The LED that is to be used to indicate this interrupt state (on RB0) works fine when RB3 has initiated the interrupt however when RB2 has initiated the interrupt when I attempt to flash RB0 it somehow turns off RB2 which is the pin that was changed from an input to an output and made high.

    In the code shown below I am using the wrong LED (RA6) to indicate the RB2 interrupt condition and everything works fine other than the wrong LED flashing.

    I am thinking that there is some strange property that RB0 has but I am very confused why it doesn't mess up when RB3 has initiated the interrupt.


    Code:
    ;the following is the interrupt routine 
    ASM 
    intRoutine
    
        ;turn off interrupts
        MOVLW   b'00000000'
        MOVWF   INTCON
        
        ;disable all interrupts that were previously enabled
        MOVLB   0x07    ;select BANK 7
        MOVLW   b'00000000'
        MOVWF   IOCBP
        
        ;RB3 is currently an input, change it to an output and make it high
        ;prior to this operation TRISB would be 11111110
        MOVLB   0x01    ;select BANK 1
        MOVLW   b'11110110'
        MOVWF   TRISB
    
        ;turn on RB3  (doesn't go high)
        MOVLB   0x00    ;select BANK 0
        BSF PORTB,3
    
        ;turn off detection power (this is working fine)
        BCF PORTA,0
            
        ;check to see what tripped the interrupt 
        ;IOCBF.2 = detection 
        ;IOCBF.3 = lighting 
        MOVLB   0x07    ;select BANK 7
        BTFSS   IOCBF,3
        GOTO    detectionFlash
        GOTO    lightingFlash
    
    lightingFlash
        MOVLB   0x00    ;select BANK 0
        BSF    PORTB,0
        CALL    Delay
        BCF    PORTB,0
        CALL    Delay
        CALL    Delay
        GOTO    lightingFlash
        
    detectionFlash
        MOVLB   0x00    ;select BANK 0
        BSF    PORTA,6 ;this is the wrong LED but works properly when this one is selected instead of PORTB,0
        CALL    Delay
        BCF    PORTA,6
        CALL    Delay
        BSF    PORTA,6
        CALL    Delay
        BCF    PORTA,6
        CALL    Delay
        CALL    Delay
        GOTO    detectionFlash   
    
    endASM

  2. #2
    Join Date
    Apr 2010
    Posts
    5


    Did you find this post helpful? Yes | No

    Default Re: 16F1827 ASM Interrupt

    Thanks for the code example cncmachineguy.

    I have it working properly now. I am thinking there must be some type of race condition with the way I had it coded. I have added a delay right after B3 was made high and everything works fine. Without the delay B3 goes low as soon as B0 is made high.

    Thanks for the help guys!

Members who have read this thread : 0

You do not have permission to view the list of names.

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts