• AVR Freaks

Hot!External signal "5v" not activating INT0 on RB0

Author
Scott5566
New Member
  • Total Posts : 2
  • Reward points : 0
  • Joined: 2019/07/11 06:51:23
  • Location: 0
  • Status: offline
2019/07/13 18:40:46 (permalink)
0

External signal "5v" not activating INT0 on RB0

Hi there,
 
I am trying to inject a 5v signal from a pic12f683, into a pic18f2220, into RBO(INT0). Once the Pic12f683 is switched on the applied 5v should raise the INT0 interrupt flag, go into the high ISR, then go into "LIGHT_PATTERN" turning on an LED. This works when I use the MPLAB simulator, and manually set the interrupt flag in the Main program loop.
 
I have tried using VCC and a 1000ohm pullup resistor but the LED does not turn on. 
 
Here is the code
Thank you for your assistance
 
#include "p18f2220.inc"
 
  CONFIG  OSC = INTIO2          ; Oscillator Selection bits (Internal RC oscillator, port function on RA6 and port function on RA7)
  CONFIG  FSCM = OFF            ; Fail-Safe Clock Monitor Enable bit (Fail-Safe Clock Monitor disabled)
  CONFIG  IESO = OFF            ; Internal/External Switchover bit (Internal/External Switchover mode disabled)
  CONFIG  PWRT = OFF            ; Power-up Timer enable bit (PWRT disabled)
  CONFIG  BOR = OFF             ; Brown-out Reset enable bit (Brown-out Reset disabled)
  CONFIG  BORV = 20             ; Brown-out Reset Voltage bits (VBOR set to 2.0V)
  CONFIG  WDT = OFF             ; Watchdog Timer Enable bit (WDT disabled (control is placed on the SWDTEN bit))
  CONFIG  WDTPS = 32768         ; Watchdog Timer Postscale Select bits (1:32768)
  CONFIG  CCP2MX = ON           ; CCP2 MUX bit (CCP2 input/output is multiplexed with RC1)
  ;CONFIG  PBAD = ANA            ; PORTB A/D Enable bit (PORTB<4:0> pins are configured as analog input channels on Reset)
  CONFIG  PBAD = DIG
  CONFIG  MCLRE = OFF           ; MCLR Pin Enable bit (MCLR disabled; RE3 input is enabled in 40-pin devices only (PIC18F4X20))
  CONFIG  STVR = ON             ; Stack Full/Underflow Reset Enable bit (Stack full/underflow will cause Reset)
  CONFIG  LVP = ON             ; Single-Supply ICSP Enable bit (Single-Supply ICSP enabled)
  CONFIG  CP0 = OFF             ; Code Protection bit (Block 0 (000200-0007FFh) not code-protected)
  CONFIG  CP1 = OFF             ; Code Protection bit (Block 1 (000800-000FFFh) not code-protected)
  CONFIG  CPB = OFF             ; Boot Block Code Protection bit (Boot block (000000-0001FFh) is not code-protected)
  CONFIG  CPD = OFF             ; Data EEPROM Code Protection bit (Data EEPROM is not code-protected)
  CONFIG  WRT0 = OFF            ; Write Protection bit (Block 0 (000200-0007FFh) not write-protected)
  CONFIG  WRT1 = OFF            ; Write Protection bit (Block 1 (000800-000FFFh) not write-protected)
  CONFIG  WRTC = OFF            ; Configuration Register Write Protection bit (Configuration registers (300000-3000FFh) are not write-protected)
  CONFIG  WRTB = OFF            ; Boot Block Write Protection bit (Boot block (000000-0001FFh) is not write-protected)
  CONFIG  WRTD = OFF            ; Data EEPROM Write Protection bit (Data EEPROM is not write-protected)
  CONFIG  EBTR0 = OFF           ; Table Read Protection bit (Block 0 (000200-0007FFh) not protected from table reads executed in other blocks)
  CONFIG  EBTR1 = OFF           ; Table Read Protection bit (Block 1 (000800-000FFFh) not protected from table reads executed in other blocks)
  CONFIG  EBTRB = OFF           ; Boot Block Table Read Protection bit (Boot block (000000-0001FFh) is not protected from table reads executed in other blocks)
 
   RADIX HEX
   CBLOCK 0X0    ;DEFINE REGISTERS REQUIRED
       BIGDELAYCTR
       DELAYCTR
       TESTREG1 
       ENDC
  
 ORG 0X00 ; RESET VECTOR
   GOTO START
   ORG 0X08 ; HIGH PRIORITY INTERRUPT VECTOR
     GOTO TMR_ISRHIGH
   ORG 0X18 ; LOW PRIORITY INTERRUPT VECTOR
     GOTO TMR_ISRLOW
  
START
  
       MOVLW B'00000000'
          MOVWF TRISA
   MOVWF LATA
   MOVWF TRISC
   MOVWF LATC
       MOVLW B'00000001'   ;PORT C  
          MOVWF TRISB
          MOVLW B'00000000'
          MOVWF LATB
   CLRF INTCON,0
   CLRF INTCON2,0
   CLRF INTCON3,0
   BCF TESTREG1,0,1
  
   ;BSF INTCON2,RBPU; PORTB pull-up enable bit
   BSF INTCON,INT0IE,A
   BSF INTCON2,INTEDG0,0
   BCF INTCON,INT0IF,0
   BSF INTCON,GIE,A 
  
MAIN_LOOP
       BRA MAIN_LOOP
       BCF TESTREG1,0,1
    BRA MAIN_LOOP
  
LIGHT_PATTERN
       MOVLW B'00000001'
       MOVWF LATA
          CALL BIGDELAY
          CALL BIGDELAY
       MOVLW B'00000000'
       MOVWF LATA
       BRA BIGDELAY
       BRA BIGDELAY
       BCF INTCON,INT0IF,0  
       RETFIE FAST
   TMR_ISRHIGH  ;HIGH INT SERVICE ROUTINE  
       MOVF PORTB,0,A
       BRA LIGHT_PATTERN
       BCF INTCON,INT0IF,0   
    RETFIE FAST
 
TMR_ISRLOW  ;LOW INT SERVICE ROUTINE  
  
      RETFIE FAST   
BIGDELAY 
         MOVLW    .50; ORIGINALLY .255
         MOVWF    BIGDELAYCTR,0
OUTERDELAY
         MOVLW    .50; ORIGINALLY .255
         MOVWF    DELAYCTR,0
INNERDELAY
         DECFSZ   DELAYCTR,1,0
         GOTO     INNERDELAY
         DECFSZ   BIGDELAYCTR,1,0
         GOTO     OUTERDELAY
         RETURN
      
 END
 
 
#1

3 Replies Related Threads

    ric
    Super Member
    • Total Posts : 23221
    • Reward points : 0
    • Joined: 2003/11/07 12:41:26
    • Location: Australia, Melbourne
    • Status: online
    Re: External signal "5v" not activating INT0 on RB0 2019/07/15 18:48:33 (permalink)
    +1 (1)
    Switch pin RA0/INT0 from analog to digital mode by writing 0x0F to ADCON1 (as the PORTA section of the datasheet tells you to).

    I also post at: PicForum
    Links to useful PIC information: http://picforum.ric323.co...opic.php?f=59&t=15
    NEW USERS: Posting images, links and code - workaround for restrictions.
    To get a useful answer, always state which PIC you are using!
    #2
    Scott5566
    New Member
    • Total Posts : 2
    • Reward points : 0
    • Joined: 2019/07/11 06:51:23
    • Location: 0
    • Status: offline
    Re: External signal "5v" not activating INT0 on RB0 2019/07/16 06:12:13 (permalink)
    0
    Hi there, 
    I added (MOVLW 0x0F, MOVWF ADCON1) to my code, I set up a pull up resistor (1000ohms), then tried it as a pull down resistor, I'm still not able to get my LED to turn on. Do I need a capacitor in the mix? This is the code for a pic18f2220. I'm not sure how to get this thing working.
    #3
    ric
    Super Member
    • Total Posts : 23221
    • Reward points : 0
    • Joined: 2003/11/07 12:41:26
    • Location: Australia, Melbourne
    • Status: online
    Re: External signal "5v" not activating INT0 on RB0 2019/07/16 13:22:07 (permalink)
    +1 (1)
    Personally, I would ditch the interrupt to start with, and just write a simple loop to copy RB0 to the LED pin, just to confirm that your input is working at all.
    Also, I notice that you have "RETFIE FAST " at the end of both your ISRs.
    You can't do that. If the high priority one is activated, it can use FAST, but the low one can't.
    This is because there is only one set of context save registers. If a HP interrupt occurs while a LP interrupt is being serviced, it will overwrite those registers, causing garbage to be restored when the LP interrupt exits.
     
    It probably doesn't matter yet, as I don't think you have enabled interrupt priorities (in which case you don't need the LP interrupt routine at all)

    I also post at: PicForum
    Links to useful PIC information: http://picforum.ric323.co...opic.php?f=59&t=15
    NEW USERS: Posting images, links and code - workaround for restrictions.
    To get a useful answer, always state which PIC you are using!
    #4
    Jump to:
    © 2019 APG vNext Commercial Version 4.5