Hello, I'm having problems with the interrupt on PORT B feature of the 16C84. I've read the microchip Ap Note on using the 'port b change interrupt' but it doesn't help much. I have a rotary encoder from a motor connected to bits 6 and 7 of PORTB. The output from the rotary encoder is a 2 bit gray code, and I would like the pic to enter the Interrupt service routine whenever the pattern changes. I then need the pic to read PORTB to store the values of bit 6 and 7 in a register. The output from the rotary encoder just changes logic level, it does not provide a pulse output. I presume that microchip refers to this as a 'wide pulse' in there Ap note. From what I can make out the PIC isn't reading PORTB correctly if at all. Does anyone have any idea where I'm going wrong ? I think that it enters the ISR correctly. but wont get the value on PORTB. Why does the Ap note include MOVF PORTB,1 as this doesn't seem to change any of the special function registers in the simulator. What does this instruction do, and do I have it in the correct place in my code ? I have managed to simulate the rest of the programme successfully in the MPLAB simulator, using the clocked stimulus dialogue to get it into the Interrupt service routine. When I use the modify window to change the contents of PORTB it only allows me to write to the output bits. Is there some simple way of getting around this so that I can simulate the input from the rotary encoder ? Thanks in advance, any help would be greatly appreciated. Hamish TITLE "MOTOR CONTROL" ; Hamish Dublon 1998 FILE intpc.ASM ; provide basic directional control PROCESSOR PIC16C84 LIST P=PIC16C84 INCLUDE P16C84.INC ORG 00 #define bank0 BCF STATUS,RP0 #define bank1 BSF STATUS,RP0 GOTO SETUP ;----------------------------------HANDLE INTERUPT---------- ORG 04H INTERUPT MOVWF W_SAVE SWAPF STATUS,W bank0 ; change to bank 0 MOVWF S_SAVE LOOPINT BCF INTCON,GIE ;disable global interupt BTFSC INTCON,GIE ;is GIE flag disabled, if not do again GOTO LOOPINT BTFSS INTCON,RBIF ;check if it is RB[0] or RB[7..4] GOTO OTHER_INT ;RB[0] interupt MOVF PORTB,1 ;read port b to itself to end ;the mismatch condition BCF INTCON,RBIF ;clear the port b interupt flag BCF PORTA,DONE ;set led BSF PORTA,GOT_INT ;set led ;interupt code for a port B 7..4 change goes here MOVF PORTB,W ;copy portb to w <--- ; **** doesnt seem to work ANDLW B'11000000' ;Mask to select bits 6 and 7 ;----------All code from here on simulated corectly------------- ; lots of code here to determine the motor position ;--------------------------------------------------- GOTO ENDINT OTHER_INT ;RB[0] interupt ;interupt code for RB[0] change goes here MOVF PORTB,1 ;read port b to itself to end the mismatch condi tion BCF INTCON,INTF ;clear the RB[0] interupt flag CLRF PORTB ;Clear port B CLRF GLOBAL_POS ENDINT SWAPF S_SAVE,W ;restore w register MOVWF STATUS ;restore status register SWAPF W_SAVE,W BSF INTCON,INTE ;ENABLE INTF interupt *************** BSF INTCON,RBIE ;ENABLE interupt on port b change BCF INTCON,T0IF ;FLAG 0, timer did not overflow BCF INTCON,INTF ;FLAG 0, RB0 interupt did not occur BCF INTCON,RBIF ;FLAG 0, portb 7..4 have not changed BSF INTCON,GIE ;1 Enable global interupts RETFIE ;return from interupt SETUP MOVLW B'10000' ; SET BIT 4 INPUT, 0,1,2,3 OUTPUTS TRIS PORTA ; SET DDR CLRF PORTA ; CLEAR THE PORT MOVLW B'11110001' ; SET PORT B 7,6,5,4,0 inputs, 3,2,1 outputs TRIS PORTB ; SET DDR CLRF PORTB