Can't get IOC on pin change working


+ Reply to Thread
Results 1 to 6 of 6
  1. #1
    Join Date
    Sep 2024
    Posts
    1

    Default Can't get IOC on pin change working

    Can't get IOC on pin change working
    Code:
    #CONFIG
        __config _CONFIG1, _FEXTOSC_OFF & _RSTOSC_HFINT32 & _CLKOUTEN_OFF & _CSWEN_OFF & _FCMEN_ON
        __config _CONFIG2, _MCLRE_ON & _PWRTE_OFF & _LPBOREN_OFF & _BOREN_ON & _BORV_LO & _ZCD_OFF & _PPS1WAY_OFF & _STVREN_ON & _DEBUG_OFF
        __config _CONFIG3, _WDTCPS_WDTCPS_11 & _WDTE_ON & _WDTCWS_WDTCWS_7 & _WDTCCS_LFINTOSC
        __config _CONFIG4, _WRT_OFF & _SCANE_available & _LVP_OFF
        __config _CONFIG5, _CP_OFF & _CPD_OFF
    #ENDCONFIG
    
    
    DEFINE OSC 32
    
    
    include    "DT_INTS-14.bas"
    include    "ReEnterPBP.bas"
    
    
    ASM
    INT_LIST  macro      ;IntSource,  Label,    Type, ResetFlag?
            INT_Handler  IOC_INT,    _IOCinterrupts,    PBP,  yes
        endm
        INT_CREATE                      ;Creates the interrupt processor
    ENDASM
    
    
    INTCON = 000000
    '          bit 7  GIE        Global Interrupt Enable bit
    '                                  1 = Enables all active interrupts
    '          bit 6  PEIE        Peripheral Interrupt Enable bit
    '          bit 5-1    Unimplemented: Read as ‘0’
    '          bit 0  INTEDG      Interrupt Edge Select bit
    
    
    PIE0 = 010000    ' PERIPHERAL INTERRUPT ENABLE REGISTER 0
    '          bit 7-6 Unimplemented: Read as ‘0’
    '          bit 5 TMR0IE: TMR0 Overflow Interrupt Enable bit
    '          bit 4 IOCIE: Interrupt-on-Change Interrupt Enable bit
    '                                  1 = Enables the IOC change interrupt
    '          bit 3-1 Unimplemented: Read as ‘0’
    '          bit 0 INTE: INT External Interrupt Flag bit
    
    
    IOCCP = 010000  ' INTERRUPT-ON-CHANGE PORTC POSITIVE EDGE REGISTER
    '          bit 7-0 IOCCP<7:0>  Interrupt-on-Change PORTC Positive Edge Enable bits
    '                                  1 = Interrupt-on-Change enabled on the pin
    '                                      for a positive-going edge. IOCCFx bit
    '                                      and IOCIF flag will be set upon detecting an edge.
    
    
    IOCCN = 000000  ' INTERRUPT-ON-CHANGE PORTC NEGATIVE EDGE REGISTER
    '          bit 7-0 IOCCP<7:0>  Interrupt-on-Change PORTC Negative Edge Enable bits
    '                                  1 = Interrupt-on-Change enabled on the pin
    '                                      for a Negative-going edge. IOCCFx bit
    '                                      and IOCIF flag will be set upon detecting an edge.
    
    
    ANSELA = 000000
    ANSELB = 000000
    ANSELC = 000000
    ANSELD = 000000
    ANSELE = 000000
    
    
    TRISA = 000000
    TRISB = 000000
    TRISC = 010000
    TRISD = 000000
    TRISE = 000000
    
    
    PushSwitch      VAR PortC.4
    InterruptLED    VAR LatC.2
    HeartbeatLED    VAR LatC.3
    
    
    ButtonWasPressed VAR byte
    
    
        Pause 500                                      ' Let PIC and LCD stabilize
        InterruptLED = 0
        ButtonWasPressed = 0
    
    
        IOCCF.4 = 0
       
    @ INT_ENABLE IOC_INT
           
        goto Mainloop
    
    
    IOCinterrupts:
        if IOCCF.4 = 1 then
            ButtonWasPressed = 1                        ' set a flag
            IOCCF.4 = 0
        endif
    @ INT_RETURN
    
    
    Mainloop:
        if ButtonWasPressed = 1 then                    ' Check flag
            InterruptLED = 1
        endif
    
    
        HeartbeatLED = 1
        pause 500
        HeartbeatLED = 0   
        pause 500
       
        goto mainloop
    end
    InterruptLED never lights up when I press PushSwitch, and the HeartbeatLED seems to hang for 2-3 seconds when I press.

  2. #2


    Did you find this post helpful? Yes | No

    Default Re: Can't get IOC on pin change working

    You appear to have forgotten the % for bit definitions

    eg variable = %10100110

    not variable = 10100110

  3. #3
    Join Date
    May 2013
    Location
    australia
    Posts
    2,451


    Did you find this post helpful? Yes | No

    Default Re: Can't get IOC on pin change working

    congrats on posting your code in code tags
    while its unfortunate that the forum mangles % notation i guess that mangled binary notation is not your trouble

    you have neglected to tell us what pic chip you are using but looking at the config section it has PPS
    therefore dt-ints will not in all likelihood function for your chip without modifications
    secondly you have not set up the internal osc at all, that will cause a very slow default int osc to be used. depending on the pic chip you are using of course
    Warning I'm not a teacher

  4. #4
    Join Date
    Dec 2010
    Location
    Melbourne Australia
    Posts
    159


    Did you find this post helpful? Yes | No

    Default Re: Can't get IOC on pin change working

    Quote Originally Posted by richard View Post
    congrats on posting your code in code tags
    you have neglected to tell us what pic chip you are using but looking at the config section it has PPS
    therefore dt-ints will not in all likelihood function for your chip without modifications
    Richard,
    can you elaborate or provide some pointers for that? You're suggesting there's more mods needed than to simply assign the appropriate PPSs ?

    Troy

  5. #5
    Join Date
    May 2013
    Location
    australia
    Posts
    2,451


    Did you find this post helpful? Yes | No

    Default Re: Can't get IOC on pin change working

    can you elaborate
    nobody keeps dt-ints upto date, the pic world has moved on - pic int flags and enable bits have been changed/modified added to and relocated for enhanced core chips pic16f 1xxxxx
    see this
    https://www.picbasic.co.uk/forum/sho...change-working
    Warning I'm not a teacher

  6. #6
    Join Date
    Dec 2010
    Location
    Melbourne Australia
    Posts
    159


    Did you find this post helpful? Yes | No

    Default Re: Can't get IOC on pin change working

    Thanks Richard,

    Troy

Similar Threads

  1. IOC on pin going HIGH and LOW
    By Demon in forum Code Examples
    Replies: 7
    Last Post: - 30th August 2024, 20:30
  2. Replies: 8
    Last Post: - 30th August 2024, 19:45
  3. IOC on a ACD pin ?
    By longpole001 in forum mel PIC BASIC Pro
    Replies: 5
    Last Post: - 28th August 2013, 01:11
  4. Replies: 1
    Last Post: - 12th May 2012, 12:37
  5. A Simple IOC Routine (Interrupt On Change)
    By lugo.p in forum mel PIC BASIC Pro
    Replies: 6
    Last Post: - 8th March 2010, 19:53

Members who have read this thread : 8

You do not have permission to view the list of names.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts