908lj12_interrupt_problem

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

908lj12_interrupt_problem

2,671 Views
mohammed
Contributor III
Dear All
 
i face a strange error; iam using two buttons PTD6 & PTD7,,,,,when i press any one of them, it goes for the interrupt serviseroutine, and do the same action,  the question is how can i distinguish between the two sources of Intrrupt;, 
 
my init.
Init_KBI:
      ; /;* Keyboard Interrupt KBI7 and KBI6 */
        mov #2,KBSCR;     /;* Falling edges only MODEK = 0 */
        ; /;* Enable 7 & 6 Keyboard interrupts */
       mov #$C0,KBIER;      
        BSET KBSCR_ACKK,KBSCR
          BCLR KBSCR_IMASKK,KBSCR
        rts
 
my ISR
 
KB_ISR:
  psha
       brclr PTD_PTD7,PTD,kbout7   ; I distinguish bet. the two Interrupts here
       BCLR KBIER_KBIE7,KBIER;
       mov #$FF ,LDAT9
        bra kbout

  kbout7:   
         brclr PTD_PTD6,PTD,kbout ; I distinguish bet. the two Interrupts here

        BCLR KBIER_KBIE6,KBIER;
        mov #1,ButtonFlag  
        bra kbout
    
      kbout:
   BCLR KBSCR_ACKK,KBSCR
    pula   
      rti
 
 
best regards
hasan
Labels (1)
0 Kudos
Reply
6 Replies

1,108 Views
peg
Senior Contributor IV
Hi Hasan,
 
Most likely you are testing for which switch was activated during the "switch bounce" period of the switch. This would give random results. Try searching the forum for maybe "debounce". This has been discussed here many times before.
 
0 Kudos
Reply

1,108 Views
mohammed
Contributor III
Hi peg;
 
thanks for replay; my problem isn't ((debounce)); my problem is easier;;;;;;
 
i need to know how to get the source of interrupt  ((is it pin6 or pin7))
 
another meaning for example two switches one at pin6 and another at pin7 of PORT D;
if i pressed on pin6  the led ON
if i pressed on pin7 the led OFF;
 
how can i make this, how can i know the source of interrupt; how can i know is it pin6 or pin7
 
i make it by this command but it doesn't work probably
 
brclr PTD_PTD7,PTD,kbout7
 
and the whole code is previously noted
 
i searched on DataSheet but i saw only one flag for keyboard interrupt;
 
please advice
 
regards
hasan
 
 
0 Kudos
Reply

1,108 Views
peg
Senior Contributor IV
Hi again hasan,
 
There is no inbuilt functionality to do this within the KBI. A fairly bit shortcoming I think!
You need to do basically what you are already doing, that is, work it out for yourself.
 
0 Kudos
Reply

1,108 Views
mohammed
Contributor III
Hi Peg
 
i tried alot but the problem still exist 
 
how can i get the source of interrupt,
 
i saw that in a sample code but i didn't
 
regards
hasan
0 Kudos
Reply

1,108 Views
bigmac
Specialist III
Hello Hasan,
 
How do you have the switches connected to the inputs - do they cause a closure to ground (Vss) when activated?  This is required for the KBI module to detect a closure.  However, for this arrangement the bit test instructions are incorrect - BRCLR should be changed to BRSET (since you need to branch if the switch is inactive).
 
A further problem - to clear the KEYF flag within KBSCR, you need to write a 1 to the ACKK bit (refer to the data sheet).
 
Yet another minor point - the presence of the PSHA and PULA instructions within the ISR is unnecessary, since this is automatically done when an interrupt occurs.  The H-register is the one that is not automatically saved, and this needs to be done manually.  However, it isn't mandatory unless you alter the H-register value within the ISR code.
 
KB_ISR:
       brset PTD_PTD7,PTD,kbout7 ; Branch if switch is inactive
       BCLR KBIER_KBIE7,KBIER;
       mov #$FF ,LDAT9
       bra kbout
kbout7:   
       brset PTD_PTD6,PTD,kbout ; Branch if switch is inactive
       BCLR KBIER_KBIE6,KBIER;
       mov #1,ButtonFlag  
kbout:
       BSET KBSCR_ACKK,KBSCR
       rti
 
Regards,
Mac
 
0 Kudos
Reply

1,108 Views
mohammed
Contributor III
Hi Mac
 
thanks alot for the reply, and sorry for late response;
 
i solve the problem, but i add two lines more; both alines are similar
 
after cheacking the state of the flag in the middle of the code, if it high i add this line
BSET KBIER_KBIE6,KBIER;  
and if another flag is high i added this line too
BSET KBIER_KBIE7,KBIER;
 
 
best regards
hasan
0 Kudos
Reply