jakeselectronics
Member
I cant get my interrupt on change to work. STILL!
This is what I reduced the program down to. I just want to get the interrupt to work.
I have an LED on PORTA, 2.
I have a keypad on PORTB. (4x4 c1c2c3c4r1r2r3r4 pluged stright into the PORT. c1=bit 7, c2=bit6 and so on.)
Internal weak pull ups are turned on.
This is what the program should do but doesnt.
1. Everything set up on power up.
2. Go to SLEEP
3. Interrupt on change, goto ISR
4. invert LED state.
5. RETFIE, go back to sleep
Can anyone see anything obvious??
This is what I reduced the program down to. I just want to get the interrupt to work.
I have an LED on PORTA, 2.
I have a keypad on PORTB. (4x4 c1c2c3c4r1r2r3r4 pluged stright into the PORT. c1=bit 7, c2=bit6 and so on.)
Internal weak pull ups are turned on.
This is what the program should do but doesnt.
1. Everything set up on power up.
2. Go to SLEEP
3. Interrupt on change, goto ISR
4. invert LED state.
5. RETFIE, go back to sleep
Can anyone see anything obvious??
Code:
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; ;
; ISD 4002 Programmer ;
; Author: Jake Sutherland ;
; ;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
list p=pic16f72
include "P16F72.INC"
__config _BOREN_OFF & _CP_OFF & _PWRTEN_ON & _WDTEN_OFF & _WDT_OFF & _XT_OSC
errorlevel -302 ;Eliminate bank warning
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; ;
; PIC16F72 Microcontroller ;
; ____ ____ ;
; MCLR -| - |- RB7 Keypad Column 1 I ;
; O RA0 -| |- RB6 Keypad Column 2 I ;
; O RA1 -| |- RB5 Keypad Column 3 I ;
; O LED RA2 -| |- RB4 Keypad Column 4 I ;
; I RA3 -| |- RB3 Keypad Row 1 O ;
; O RA4 -| |- RB2 Keypad Row 2 O ;
; O RA5 -| |- RB1 Keypad Row 3 O ;
; VSS -| |- RB0 Keypad Row 4 O ;
; OSC1 -| |- VDD ;
; OSC2 -| |- VSS ;
; O RC0 -| |- RC7 O ;
; O RC1 -| |- RC6 O ;
; O RC2 -| |- RC5 O ;
; O RC3 -|_________|- RC4 O ;
; ;
; ;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; Set EQU vales and registers
CBLOCK 0x20
DELAYGPR1
DELAYGPR2
ENDC
W_TEMP EQU 0X7F
STATUS_TEMP EQU 0X7E
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
ORG 0x00 ; Program starts at 0x00
GOTO START
ORG 0x04 ; Interupt vector jumps here
GOTO ISR
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
START
SETIO ; This rountine sets up the chips Inputs and Outputs
BCF STATUS,RP0 ; Bank 0
BCF STATUS,RP1 ; Bank 0
CLRF PORTA ; Initialize PORTA by clearing output data latches
CLRF PORTB ; Initialize PORTB by clearing output data latches
CLRF PORTC ; Initialize PORTC by clearing output data latches
BSF STATUS,RP0 ; Bank 1
BCF STATUS,RP1 ; Bank 1
MOVLW 0x06 ; Configure all pins
MOVWF ADCON1 ; as digital inputs
MOVLW B'00001000' ; Value used to initialize data direction
MOVWF TRISA ; Set RA<1:0> as outputs
; RA<3> as inputs
; RA<5:4> as outputs
; TRISA<7:6> are always
; read as ‘0’.
MOVLW B'11110000' ; Value used to initialize data direction
MOVWF TRISB ; Set RB<7:4> as outputs
; RB<3:0> as inputs
MOVLW B'00000000' ; Value used to initialize data direction
MOVWF TRISC ; Set RC<7:0> as outputs
BCF OPTION_REG, NOT_RBPU; Set PORTB weak pull-ups on
BCF STATUS,RP0 ; Bank 0
BCF STATUS,RP1 ; Bank 0
GOTO MAIN_PROGRAM
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; Interrupt Sevice Routine
ISR
; MOVWF W_TEMP ;
; SWAPF STATUS, W ; Save registers
; CLRF STATUS ;
; MOVWF STATUS_TEMP ;
BTFSS PORTA, 2 ;
BSF PORTA, 2 ; This routine inverts the state of the LED.
BTFSC PORTA, 2 ;
BCF PORTA, 2 ;
; SWAPF STATUS_TEMP, W ;
; MOVWF STATUS ; Reload regisiters
; SWAPF W_TEMP, F ;
; SWAPF W_TEMP, W ;
BCF INTCON, RBIF ; Clear Flag
RETFIE
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
MAIN_PROGRAM
BSF INTCON, GIE
BSF INTCON, RBIE
BCF INTCON, RBIF
CLRF PORTB
CALL DELAY_50mS
SLEEP
NOP
GOTO MAIN_PROGRAM
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; DELAY ROUTINES
; Actual delay = 0.05 seconds = 50000 cycles
DELAY_50mS
MOVLW 0x0E ;
MOVWF DELAYGPR1 ;
MOVLW 0x28 ;
MOVWF DELAYGPR2 ;
DELAY_50mS_0 ;
DECFSZ DELAYGPR2, f ;
GOTO $+2 ;
DECFSZ DELAYGPR2, f ;
GOTO DELAY_50mS_0 ; 49993 cycles
GOTO $+1 ;
NOP ; 3 cycles
RETURN ; 4 cycles (including call)
END