Welcome to our site!

Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

  • Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

Interrupt on change, Fresh problem

Status
Not open for further replies.
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??


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
 

jbmillard

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.

The only PIC I've ever used is the PIC24. With it, you have to specifically enable the change notification interrupts by setting _CNXIE = TRUE where "X" is the pin/port number. Is it the same with the PIC16?

Brad
 
No I have not heard of that with the 16 range.

I have read the datasheet inside out and tried about 114.7 different things.
still nothing.
Maybe ill start fresh tomorrow.
maybe its the hardware.
maybe ill rip the breadboard apart so theres nothing on it, get a new micro and hope i go better than today..
 

RayVT

New Member
I don't know if this will help, I very new to this (Pic Programming) but I copied my help file for you (Proton IDE Basic Compiler)

Code:
[COLOR=black][B][FONT=Verdana]SLEEP [/FONT][/B][B][FONT=Verdana]12[/FONT][/B][B][FONT=Verdana]14[/FONT][/B][B][FONT=Verdana]16[/FONT][/B][/COLOR]
[SIZE=2][FONT=Verdana][B]Syntax[/B][/FONT][/SIZE]
 
[FONT=Courier New][SIZE=2][B]SLEEP [/B]{ [I]Length [/I]} [/SIZE][/FONT]
 
[SIZE=2][FONT=Verdana][B]Overview[/B][/FONT][/SIZE]
 
[SIZE=2][FONT=Verdana]Places the PICmicro into low power mode for approx [I]n [/I]seconds. i.e. power down but leaves the port pins in their previous states. [/FONT][/SIZE]
 
 

[SIZE=2][FONT=Verdana][B]Operators[/B][I]
[LIST]
[*]Length[B] -[/B]
[/LIST][/I]
[LIST]
[*]an optional variable or constant (1-65535) that specifies the duration of sleep in seconds. If length is omitted, then the SLEEP command is assumed to be the assembler mnemonic, which means the PICmicro will sleep continuously, or until the Watchdog timer wakes it up.
[/LIST][B]Example[/B][/FONT][/SIZE]
 
[B][FONT=Courier New][SIZE=2]SYMBOL [/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#ff0000]LED [/COLOR][/SIZE][/FONT][/B][FONT=Courier New][SIZE=2]= [/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#008000]PORTA[/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][B].[/B][/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#ff0000]0 [/COLOR][/SIZE][/FONT]
[SIZE=2][FONT=Courier New]Again: [/FONT][/SIZE]
[SIZE=2][FONT=Courier New][B]HIGH [/B][/FONT][/SIZE][FONT=Courier New][SIZE=2][COLOR=#ff0000][B]LED  [/B][/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2]    ' [/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#000080]Turn LED on. [/COLOR][/SIZE][/FONT]
[SIZE=2][FONT=Courier New][B]DELAYMS [/B][/FONT][/SIZE][FONT=Courier New][SIZE=2][COLOR=#ff0000]1000  [/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2]' [/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#000080]Wait 1 second. [/COLOR][/SIZE][/FONT]
[B][FONT=Courier New][SIZE=2]LOW [/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#ff0000]LED  [/COLOR][/SIZE][/FONT][/B][FONT=Courier New][SIZE=2]     ' [/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#000080]Turn LED off. [/COLOR][/SIZE][/FONT]
[SIZE=2][FONT=Courier New][B]SLEEP [/B][/FONT][/SIZE][FONT=Courier New][SIZE=2][COLOR=#ff0000]60      [/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2]' [/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#000080]Sleep for 1 minute. [/COLOR][/SIZE][/FONT]
[SIZE=2][FONT=Courier New][B]GOTO [/B]Again [/FONT][/SIZE]
 
[SIZE=2][FONT=Verdana][B]Notes[/B][/FONT][/SIZE]
 
[SIZE=2][FONT=Verdana][B]Sleep [/B]will place the PICmicro into a low power mode for the specified period of seconds. Period is 16 bits, so delays of up to 65,535 seconds are the limit (a little over 18 hours) [B]Sleep [/B]uses the Watchdog Timer so it is independent of the oscillator frequency. The smallest units is about 2.3 seconds and may vary depending on specific environmental conditions and the device used. [/FONT][/SIZE]
 
[SIZE=2][FONT=Verdana]The [B]Sleep [/B]command is used to put the PICmicro in a low power mode without resetting the registers. Allowing continual program execution upon waking up from the [B]Sleep [/B]period. [/FONT][/SIZE]
 
[SIZE=2][FONT=Verdana][B]Waking the PICmicro from SLEEP[/B][/FONT][/SIZE]
 
[SIZE=2][FONT=Verdana]All the PICmicro range have the ability to be placed into a low power mode, consuming micro Amps of current. The command for doing this is SLEEP. The compiler's SLEEP command or the assembler's SLEEP instruction may be used. The compiler's SLEEP command differs somewhat to the assembler's in that the compiler's version will place the PICmicro into low power mode for [I]n [/I]seconds ([I]where n is a value from 0 to 65535[/I]). The assembler's version still places the PICmicro into low power mode, however, it does this forever, or until an internal or external source wakes it. This same source also wakes the PICmicro when using the compiler's command. Many things can wake the PICmicro from its sleep, the WATCHDOG TIMER is the main cause and is what the compiler's SLEEP command uses. [/FONT][/SIZE]
 
[SIZE=2][FONT=Verdana]Another method of waking the PICmicro is an external one, a change on one of the port pins. We will examine more closely the use of an external source. There are two main ways of waking the PICmicro using an external source. One is a change on bits 4..7 of [URL="https://javascript<b></b>:popuplink('hs2784.htm')"]PORTB[/URL]. Another is a change on bit-0 of [URL="https://javascript<b></b>:popuplink('hs2784.htm')"]PORTB[/URL]. We shall first look at the wake up on change of [URL="https://javascript<b></b>:popuplink('hs2784.htm')"]PORTB[/URL],bits-4..7. [/FONT][/SIZE]
 
[SIZE=2][FONT=Verdana]As its name suggests, any change on these pins either high to low or low to high will wake the PICmicro. However, to setup this mode of operation several bits within registers [URL="https://javascript<b></b>:popuplink('hs2668.htm')"]INTCON [/URL]and OPTION_REG need to be manipulated. One of the first things required is to enable the weak [URL="https://javascript<b></b>:popuplink('hs2784.htm')"]PORTB[/URL][/FONT][/SIZE][FONT=Verdana][SIZE=2]pull-up resistors. This is accomplished by clearing the RBPU bit of OPTION_REG ([I]OPTION_REG.7[/I]). If this was not done, then the pins would be floating and random input states would occur waking the PICmicro up prematurely. [/SIZE][/FONT]
 
[SIZE=2][FONT=Verdana]Although technically we are enabling a form of interrupt, we are not interested in actually running an interrupt handler. Therefore, we must make sure that GLOBAL interrupts are disabled, or the PICmicro will jump to an interrupt handler every time a change occurs on [URL="https://javascript<b></b>:popuplink('hs2784.htm')"]PORTB[/URL]. This is done by clearing the [URL="https://javascript<b></b>:popuplink('hs2666.htm')"]GIE [/URL]bit of [URL="https://javascript<b></b>:popuplink('hs2668.htm')"]INTCON [/URL]([I]INTCON.7[/I]). [/FONT][/SIZE]
 
[SIZE=2][FONT=Verdana]The interrupt we are concerned with is the RB port change type. This is enabled by setting the RBIE bit of the [URL="https://javascript<b></b>:popuplink('hs2668.htm')"]INTCON [/URL]register ([I]INTCON.3[/I]). All this will do is set a flag whenever a change occurs ([I]and of course wake up the PICmicro[/I]). The flag in question is RBIF, which is bit-0 of the [URL="https://javascript<b></b>:popuplink('hs2668.htm')"]INTCON [/URL]register. For now we are not particularly interested in this flag, however, if global interrupts were enabled, this flag could be examined to see if it was the cause of the interrupt. The RBIF flag is not cleared by hardware so before entering SLEEP it should be cleared. It must also be cleared before an interrupt handler is exited. [/FONT][/SIZE]
 
[SIZE=2][FONT=Verdana]The SLEEP command itself is then used. Upon a change of [URL="https://javascript<b></b>:popuplink('hs2784.htm')"]PORTB[/URL], bits 4..7 the PICmicro will wake up and perform the next instruction ([I]or command[/I]) after the SLEEP command was used. [/FONT][/SIZE]
 
[SIZE=2][FONT=Verdana]A second external source for waking the PICmicro is a pulse applied to [URL="https://javascript<b></b>:popuplink('hs2784.htm')"]PORTB[/URL].0. This interrupt is triggered by the edge of the pulse, high to low or low to high. The INTEDG bit of OPTION_REG ([I]OPTION_REG.6[/I]) determines what type of pulse will trigger the interrupt. If it is set, then a low to high pulse will trigger it, and if it is cleared then a high to low pulse will trigger it. [/FONT][/SIZE]
 
[SIZE=2][FONT=Verdana]To allow the [URL="https://javascript<b></b>:popuplink('hs2784.htm')"]PORTB[/URL].0 interrupt to wake the PICmicro the INTE bit must be set, this is bit-4 of the [URL="https://javascript<b></b>:popuplink('hs2668.htm')"]INTCON [/URL]register. This will allow the flag INTF ([I]INTCON.1[/I]) to be set when a pulse with the right edge is sensed. [/FONT][/SIZE]
 
[SIZE=2][FONT=Verdana]This flag is only of any importance when determining what caused the interrupt. However, it is not cleared by hardware and should be cleared before the SLEEP command is used ([I]or the interrupt handler is exited[/I]). The program below will wake the PICmicro when a change occurs on [URL="https://javascript<b></b>:popuplink('hs2784.htm')"]PORTB[/URL], bits 4-7. [/FONT][/SIZE]
 
[B][FONT=Courier New][SIZE=2][COLOR=#800000]XTAL [/COLOR][/SIZE][/FONT][/B][FONT=Courier New][SIZE=2]= [/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#ff0000]4     [/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#000080]' Set Xtal Frequency [/COLOR][/SIZE][/FONT]
 
[B][FONT=Courier New][SIZE=2]SYMBOL [/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#ff0000]LED [/COLOR][/SIZE][/FONT][/B][FONT=Courier New][SIZE=2]= [/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#008000]PORTB[/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][B].[/B][/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#ff0000]0   [/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#000080]' Assign the LED's pin [/COLOR][/SIZE][/FONT]
[SIZE=2][FONT=Courier New][B]SYMBOL [/B][/FONT][/SIZE][FONT=Courier New][SIZE=2][COLOR=#008000]RBIF [/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2]= [/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#008000]INTCON[/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][B].[/B][/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#ff0000]0  [/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#000080]' PORTB[4..7] Change Interrupt Flag [/COLOR][/SIZE][/FONT]
[SIZE=2][FONT=Courier New][B]SYMBOL [/B][/FONT][/SIZE][FONT=Courier New][SIZE=2][COLOR=#008000]RBIE [/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2]= [/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#008000]INTCON[/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][B].[/B][/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#ff0000]3  [/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#000080]' PORTB[4..7] Change Interrupt Enable [/COLOR][/SIZE][/FONT]
[SIZE=2][FONT=Courier New][B]SYMBOL [/B][/FONT][/SIZE][FONT=Courier New][SIZE=2][COLOR=#008000]RBPU [/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2]= [/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#008000]OPTION_REG[/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][B].[/B][/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#ff0000]7  [/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#000080]' PortB pull-ups [/COLOR][/SIZE][/FONT]
[SIZE=2][FONT=Courier New][B]SYMBOL [/B][/FONT][/SIZE][FONT=Courier New][SIZE=2][COLOR=#008000]GIE [/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2]= [/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#008000]INTCON[/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][B].[/B][/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#ff0000]7   [/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#000080]' Global interrupt enable/disable [/COLOR][/SIZE][/FONT]
 
[FONT=Courier New][SIZE=2][COLOR=#000080]' ** THE MAIN PROGRAM STARTS HERE ** [/COLOR][/SIZE][/FONT]
[SIZE=2][FONT=Courier New]Main:  [/FONT][/SIZE]
[FONT=Courier New][SIZE=2][COLOR=#008000]GIE [/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2]= [/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#ff0000]0      [/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#000080]' Turn OFF global interrupts [/COLOR][/SIZE][/FONT]
[SIZE=2][FONT=Courier New][B]WHILE [/B][/FONT][/SIZE][FONT=Courier New][SIZE=2][COLOR=#008000]GIE [/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2]= [/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#ff0000]1 [/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][B]: [/B][/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#008000]GIE [/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2]= [/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#ff0000]0 [/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][B]: WEND  [/B][/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#000080]' And make sure they are off [/COLOR][/SIZE][/FONT]
[FONT=Courier New][SIZE=2][COLOR=#008000]TRISB[/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][B].[/B][/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#ff0000]4 [/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2]= [/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#ff0000]1     [/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#000080]' Set PORTB.4 as an Input [/COLOR][/SIZE][/FONT]
[FONT=Courier New][SIZE=2][COLOR=#008000]RBPU [/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2]= [/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#ff0000]0     [/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#000080]' Enable PORTB Pull-up Resistors [/COLOR][/SIZE][/FONT]
[FONT=Courier New][SIZE=2][COLOR=#008000]RBIE [/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2]= [/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#ff0000]1      [/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#000080]' Enable PORTB[4..7] interrupt [/COLOR][/SIZE][/FONT]
 
[SIZE=2][FONT=Courier New]Again:[/FONT][/SIZE]
[SIZE=2][FONT=Courier New][B]DELAYMS [/B][/FONT][/SIZE][FONT=Courier New][SIZE=2][COLOR=#ff0000]100 [/COLOR][/SIZE][/FONT]
[B][FONT=Courier New][SIZE=2]LOW [/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#ff0000]LED     [/COLOR][/SIZE][/FONT][/B][FONT=Courier New][SIZE=2][COLOR=#000080]' Turn off the LED [/COLOR][/SIZE][/FONT]
[FONT=Courier New][SIZE=2][COLOR=#008000]RBIF [/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2]= [/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#ff0000]0      [/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#000080]' Clear the PORTB[4..7] interrupt flag [/COLOR][/SIZE][/FONT]
[SIZE=2][FONT=Courier New][B]SLEEP      [/B][/FONT][/SIZE][FONT=Courier New][SIZE=2][COLOR=#000080]' Put the PICmicro to sleep [/COLOR][/SIZE][/FONT]
[SIZE=2][FONT=Courier New][B]DELAYMS [/B][/FONT][/SIZE][FONT=Courier New][SIZE=2][COLOR=#ff0000]100     [/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#000080]' When it wakes up, delay for 100ms [/COLOR][/SIZE][/FONT]
[B][FONT=Courier New][SIZE=2]HIGH [/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#ff0000]LED     [/COLOR][/SIZE][/FONT][/B][FONT=Courier New][SIZE=2][COLOR=#000080]' Then light the LED [/COLOR][/SIZE][/FONT]
[SIZE=2][FONT=Courier New][B]GOTO [/B]Again     [/FONT][/SIZE][FONT=Courier New][SIZE=2][COLOR=#000080]' Do it forever [/COLOR][/SIZE][/FONT]

Hope it helps!!!
 

AllVol

New 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??


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 ;
; ____ ____ ;
 
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’.
 
[COLOR=red]MOVLW B'11110000' ; Value used to initialize data direction            ??????????[/COLOR]
[COLOR=red]MOVWF TRISB ; Set RB<7:4> as outputs[/COLOR]
[COLOR=red]; RB<3:0> as inputs[/COLOR]
 
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
 
 
 
END

Might the portion highlighted in red be part of the problem?
 
oh, naa.. the comments are backwards.
RB4,5,6,7 should be inputs and RB,0,1,2,3 are the outputs.

Im starting fresh.
I think that whole program is plagued with errors.
Thanks all for your input though and i will those notes RayVT provided into account too.
 
Status
Not open for further replies.

Latest threads

EE World Online Articles

Loading
Top