Menu

16F690 Pin Interrupt

Help
Anobium
2012-01-14
2013-05-30
  • Anobium

    Anobium - 2012-01-14

    I have a 16F690.

    I have a tactile switch on RA3.  This is the Microchip demo board.

    How do I raise an interrupt on RA3?

    My current code is.

    #chip 16F690, 4
    #config Osc = XT, MCLRE_OFF
    'Set the input pin direction
        #define SwitchIn1 PORTa.3
        Dir SwitchIn1 In
    #define LedPort PORTc
    DIR PORTC OUT
    'Set the input pin direction
    Dir PORTA.0 In
    dim ADCreading as word
    dim ccount as byte
    dim leddir as byte
    ccount = 8
    leddir = 1
    On Interrupt PORTABChange  Call Setir
    main:
        ADCreading = ReadAD(AN0)
    
            Set PortC = ccount
    
            if leddir = 0 then 
                ccount = ccount * 2
    
                if ccount = 16 then
                    ccount = 1
                end if
    
            end if
            if leddir = 1 then 
                ccount = ccount / 2
    
                if ccount = 0 then
                    ccount = 8
                end if
    
            end if
    
            wait ADCreading ms
    goto main
    sub Setir
        ;if SwitchIn1 = 0 then
            for tt = 1 to 2
             Set PortC = 9
            wait 250 ms
             Set PortC = 0
            wait 250 ms
             Set PortC = 6
            wait 250 ms
             Set PortC = 0
            wait 250 ms
    
            next
    
            if leddir = 0 then
                leddir = 1 
                ccount  = 8
            else
                leddir = 0 
                ccount = 1
            end if
        ;end if
        On Interrupt PORTABChange  Call Setir
    
    end sub
    

    How do I raise the event ?

    Thank you.

     
  • Anobium

    Anobium - 2012-01-15

    So, I have figured out.. that RA2 is the only External Interrupt and I can use 'ExtInt0' to call the handler.

    On Interrupt ExtInt0  Call Setir

    How do I set up  an interrupt using any PORTA pin using the an interrupt-on-change (IOC) option? I want to use RA3.

     
  • kent_twt4

    kent_twt4 - 2012-01-15

    1)  There is an extra PORTABChange in the Setir sub that is not needed.

    2)  While everything is set up for the PORTABChange, you still need to say which pin(s) will be used.  By default the SFR IOCA register bits are '-00 0000' on BOR, POR (see pg. 33 of data sheet).  So "Set IOCA3 On" should do it prior to main.  The demo board already has a 10k pullup, so good to go.

     
  • Nobody/Anonymous

    Works a treat!  thank you.

    I need to get used to mapping  the datasheet to the GCB dialog and syntax.

    Thank you.

     
  • Anobium

    Anobium - 2012-01-17

    The working code is shown below.  This is not optimised but it works…

    #chip 16F690, 4
    #config Osc = XT, MCLRE_ON
    'Set the input pin direction
        #define SwitchIn1 PORTa.3
        Dir SwitchIn1 In
    #define LedPort PORTc
        DIR PORTC OUT
    'Setup the ADC  pin direction
        Dir PORTA.0 In
        dim ADCreading as word
    'Setup the input pin direction
        #define IntPortA PORTA.1
        Dir IntPortA In
        #define intstate as byte
        intstate = 0
        #define minwait 1
        dim ccount as byte
        dim leddir as byte
        dim pushcount as byte
        dim madestart as byte
    
        ccount = 8
        leddir = 0
        pushcount = 0
    
    'Setup the intertupt - see page 33 of the 16F690 datasheet
        Set IOCA1 on
        On Interrupt PORTABCHANGE Call Setir
    
        initx:
            ' setup start values 
            if leddir = 0 then
                leddir = 1 
                ccount  = 8
                goto main
            end if
    
            if leddir = 1 then
                leddir = 0 
                ccount = 1
                goto main
            end if
    
        main:
    
                    IntOn
    
                    ADCreading = ReadAD10(AN0)
                    if ADCreading < minwait then ADCreading = minwait
    
                    Set PortC = ccount
                    wait ADCreading ms
                    intstate = 0
    
                if leddir = 0 then 
                    ccount = ccount * 2
    
                    if ccount = 16 then
                        ccount = 1
                    end if
                end if
    
                if leddir = 1 then 
                    ccount = ccount / 2
    
                    if ccount = 0 then
                        ccount = 8
                    end if
    
                end if
    
        goto main
    
        sub Setir
            if IntPortA  = 0 and intstate = 0 then 
                intstate = 1
                goto initx
            end if
        end sub
    
     

Log in to post a comment.

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.