This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

Interrupts, flags and functions

Hello, I need to know the exact moment when an input is set.

I'm using XC167CI and I have fast interrupts. This way is full, I mean I have used all fast interrupts.

I don't know how I can know when an input por is set and reset.

What can I do? I which file can I paste the code? Maybe in MAIN.C? Maybe in IO.C?

Please, help me.

Parents
  • The XC167 has many interrupts that can come from port pins and you are not limited to the fast external interrupts. You could also use the CAPCOM's as interrupts. Please be aware that when you use a fast interrupt you give up the CAPCOM interrupt for the associated channel. Given that you have asked for an example of a fast interrupt on P3.0. So here it is… You will vector to fast external interrupt 1 (EX1IN) whenever there is a change on the P3.0 that for more than two CPU clocks.

    If you did not protect the registers then you can go ahead and modify the registers directly without the unlock sequence. This code snippet is only for reference as you need to decide on the exact configuration and interrupt level you want. You are free to decide what group and level for any interrupt but make sure you make sure that they are all unique. I won't go into local and global register banks or cached interrupts since they are advance concepts.

    So to the code…

    #include <xc167.h>
    #include <intrins.h>
    
    void main(void) {
    
      EXISEL0 = 0x0020; /*input from alternate pin AltB*/
      EXICON = 0x000C; /*trigger on either edge*/
    
      /*note EX1IN uses the CC9 interrupt vector */
      CC1_CC9IC =  0x0070; /*enable the ISR and choose a group and level */
    
      PSW_IEN = 1; /*globally enable interrupts*/
    
      for(;;) {
        _nop_(); /*loop forever*/
      }
    }
    
    /*here is the interrupt entry*/
    void Ex1in_ISR (void) interrupt 0x19 {
     /*place your ISR code in here */
    }
    
    Kind regards, Chris

Reply
  • The XC167 has many interrupts that can come from port pins and you are not limited to the fast external interrupts. You could also use the CAPCOM's as interrupts. Please be aware that when you use a fast interrupt you give up the CAPCOM interrupt for the associated channel. Given that you have asked for an example of a fast interrupt on P3.0. So here it is… You will vector to fast external interrupt 1 (EX1IN) whenever there is a change on the P3.0 that for more than two CPU clocks.

    If you did not protect the registers then you can go ahead and modify the registers directly without the unlock sequence. This code snippet is only for reference as you need to decide on the exact configuration and interrupt level you want. You are free to decide what group and level for any interrupt but make sure you make sure that they are all unique. I won't go into local and global register banks or cached interrupts since they are advance concepts.

    So to the code…

    #include <xc167.h>
    #include <intrins.h>
    
    void main(void) {
    
      EXISEL0 = 0x0020; /*input from alternate pin AltB*/
      EXICON = 0x000C; /*trigger on either edge*/
    
      /*note EX1IN uses the CC9 interrupt vector */
      CC1_CC9IC =  0x0070; /*enable the ISR and choose a group and level */
    
      PSW_IEN = 1; /*globally enable interrupts*/
    
      for(;;) {
        _nop_(); /*loop forever*/
      }
    }
    
    /*here is the interrupt entry*/
    void Ex1in_ISR (void) interrupt 0x19 {
     /*place your ISR code in here */
    }
    
    Kind regards, Chris

Children
No data