DT interrupt and 12f683


Closed Thread
Results 1 to 3 of 3
  1. #1
    Join Date
    May 2008
    Location
    Italy
    Posts
    825

    Default DT interrupt and 12f683

    Code:
    '-------------------------------------------------------------------------------
    '|             Name    : Light_12F683.BAS                                      |
    '|             Author  :                                                       |
    '|             Notice  : Copyright (c) 2010  All Rights Reserved               |
    '|                     :                                                       |
    '|             Date    : 18/12/2014                                            |
    '|             Version : 1.0                                                   |
    '|             Notes   : Pic 12F683 light controller                           |                   
    '-------------------------------------------------------------------------------
    ' P12F683 (pin usage)
    '
    ' pin # 1 = Vdd     (+ 5 Volts)
    ' pin # 2 = GPIO.5  (Digital output [Led])
    ' pin # 3 = GPIO.4  (N/U)
    ' pin # 4 = GPIO.3  (MCLR)
    ' pin # 5 = GPIO.2  (Digital output)
    ' pin # 6 = GPIO.1  (input chan B)
    ' pin # 7 = GPIO.0  (input chan A)
    ' pin # 8 = Vss     (ground)
    '
    '-------------------------------------------------------------------------------
    ;----[12F683 Hardware Configuration]--------------------------------------------
    #IF __PROCESSOR__ = "12F683"
      #DEFINE MCU_FOUND 1
    #CONFIG
    cfg = _INTOSCIO               ; INTOSCIO oscillator: I/O function 
    cfg&= _WDT_OFF                ; WDT disabled
    cfg&= _PWRTE_OFF              ; PWRT disabled
    cfg&= _MCLRE_ON               ; MCLR pin function is MCLR
    cfg&= _CP_OFF                 ; Program memory code protection is disabled
    cfg&= _CPD_OFF                ; Data memory code protection is disabled
    cfg&= _BOD_ON                 ; BOR enabled
    cfg&= _IESO_ON                ; Internal External Switchover mode is enabled
    cfg&= _FCMEN_ON               ; Fail-Safe Clock Monitor is enabled
      __CONFIG cfg
    
    #ENDCONFIG
    
    #ENDIF
    
    ;----[Verify Configs have been specified for Selected Processor]----------------
    ;       Note: Only include this routine once, after all #CONFIG blocks
    #IFNDEF MCU_FOUND
      #ERROR "No CONFIGs found for [" + __PROCESSOR__ +"]"
    #ENDIF
    '
    '-------------------------------------------------------------------------------
    '                                   '
    include "ALLDIGITAL.pbp"
    DEFINE  SHOWDIGITAL 1
    INCLUDE "DT_INTS-14.bas"     ; Base Interrupt System
    INCLUDE "ReEnterPBP.bas"     ; Include if using PBP interrupts
    DEFINE OSC 8                        ' Oscillator frequency
    '                                   '
    '-------------------------------------------------------------------------------
    '
        OSCCON = %01110111              ' oscillator setting internal 8 MHz
    '   ANSEL  = %00100000              ' set all digital
    '   CMCON0 = 7                      ' comparator off
    OPTION_REG = %11100000              ' weak pullup enabled
          GPIO = %00000000              ' set all pins to zero
    '                                   '
        TRISIO = %00001011              ' configure direction  1=input 0=output
    '                                   '
    '-------------------------------------------------------------------------------
    '                                   '
    Led             var GPIO.5          ' Alias for GPIO.5 pin # 2 
    A_opto          var GPIO.0          ' Alias for GPIO.0 pin # 7 
    B_Opto          var GPIO.1          ' Alias for GPIO.1 pin # 6 
    Luce            var GPIO.2          ' Alias for GPIO.2 pin # 5
    '
    '-------------------------------------------------------------------------------
    '
    wsave           VAR BYTE $20     SYSTEM
    wsave1          var byte $A0     SYSTEM
    A0              var byte
    B0              var byte
    C0              var byte
    F0              var byte
    Flag_Count      var byte
    Flag_In         var bit
    Flag_Out        var bit
    '                                   '
    '-------------------------------------------------------------------------------
    '
    Flag_Count = 0
      Flag_Out = 0
       Flag_In = 0 
            A0 = 0
            B0 = 0
            F0 = 0
    '                                   '
    asm
    INT_LIST  macro             ; IntSource,        Label,  Type, ResetFlag?                    
            INT_Handler    GPC_INT,  _Opto_Read,    PBP,  yes                         
        endm
        INT_CREATE              ; Creates the interrupt processor
    ENDASM
    
    @     INT_ENABLE GPC_INT
    '
    '-------------------------------------------------------------------------------
    '
    goto Main                           
    '
    '---------------------------------- Ini ISR ------------------------------------
    '                                                 
    Opto_Read:
    A0 = GPIO & %00000011
    
    If A0 = 1 Then Flag_In = 1
    If A0 = 3 and Flag_In = 1 Then Flag_Count = Flag_Count + 1
    If A0 = 2 Then Flag_Out = 1
    If A0 = 3 and Flag_Out = 1 Then Flag_Count = Flag_Count - 1
    @  INT_RETURN
    '
    '-------------------------------------------------------------------------------
    '
    Main:                               
    If Flag_In = 1 and Flag_Count > 0 Then 
    Luce = 1
    Flag_In = 0
    endif
    If Flag_Count > 100 then Flag_Count = 0
    '                                   
    If Flag_Out = 1 and Flag_Count = 0 Then 
    Luce = 0
    Flag_Out = 0
    endif
    '
    Pause 1
    F0 = F0 + 1
    If F0 > 200 then
    Led = !Led
    F0 = 0
    endif
    goto Main                           ' goes back to main loop  
    '
    '-------------------------------------------------------------------------------
    '
    end                                 ' end program
    I am not able to trigger the interrupt, can Somebody enlight me on what is wrong in the above code?

    Thank you

    Al.
    All progress began with an idea

  2. #2
    Join Date
    Oct 2005
    Location
    Sweden
    Posts
    3,521


    Did you find this post helpful? Yes | No

    Default Re: DT interrupt and 12f683

    Hi,
    Try setting IOC = %00000011 to enable IOC interrupt on GPIO.0 and GPIO.1

    /Henrik.

  3. #3
    Join Date
    May 2008
    Location
    Italy
    Posts
    825


    Did you find this post helpful? Yes | No

    Default Re: DT interrupt and 12f683

    Thank you Henrik , that was the trouble now the interrupt works as it shoud!

    Cheers

    Al.
    All progress began with an idea

Similar Threads

  1. 12F683, TMR1 and ON INTERRUPT revisited
    By AvionicsMaster1 in forum PBP3
    Replies: 1
    Last Post: - 17th September 2013, 19:07
  2. 12f683 ADC help
    By retepsnikrep in forum mel PIC BASIC Pro
    Replies: 3
    Last Post: - 26th November 2009, 21:37
  3. 12f683 help!!!! L@@K!!!
    By thm ov3rkill in forum mel PIC BASIC Pro
    Replies: 0
    Last Post: - 2nd December 2008, 22:46
  4. 12F683 Startup
    By GregK in forum mel PIC BASIC Pro
    Replies: 4
    Last Post: - 19th March 2005, 00:25
  5. Replies: 0
    Last Post: - 27th August 2004, 07:20

Members who have read this thread : 4

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