Instant Interrupts - Revisited


Results 1 to 40 of 773

Threaded View

  1. #11
    Join Date
    Jul 2009
    Posts
    23


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by mackrackit View Post
    Dave here

    in MCS -view-program options-assembler tab. Check the box for using MPASM. The hex will be created when you compile with MCS.

    You do not need to start MPLAB. MCS will start MPASM for you.
    Dave
    I am using MPASM.

    Code:
     ; Initialize your hardware first.
    
    INCLUDE "DT_INTS-18.bas"     ' Base Interrupt System
    INCLUDE "ReEnterPBP-18.bas"     ' Include if using PBP interrupts
    DEFINE OSC 4  'Define the Osc to 4 MHz
         
    asm
                bsf      OSCCON, SCS1        ; 1x = Internal Block
                bcf      OSCCON, SCS0        ; 00 = Primary Oscillator (20Mhz?)
                bsf      OSCCON, IRCF2       ; 111=8000  110=4000  101=2000
                bsf      OSCCON, IRCF1       ; 100=1000  011=0500  010=0250
                bcf      OSCCON, IRCF0       ; 001=0125  000=0032
    MSTABLE010 btfss    OSCCON, IOFS
                bra      MSTABLE010           ; wait until Oscillator is stable
    endasm
    LED1       VAR PORTB.2
    DutyCycle  VAR BYTE
    
    TotalCount CON 50000
    ONcount    VAR WORD
    OFFcount   VAR WORD
    
    ASM
    INT_LIST  macro    ; IntSource,        Label,  Type, ResetFlag?
            INT_Handler   TMR1_INT,  _ToggleLED1,   PBP,  yes
        endm
        INT_CREATE               ; Creates the interrupt processor
    ENDASM
    
    T1CON = $00                ; Prescaler = 1:1, TMR OFF
    @ INT_ENABLE  TMR1_INT     ; enable Timer 1 interrupts
    
    Main:
        FOR DutyCycle = 0 TO 255           ; Ramp up
            GOSUB  SetDutyCycle
            PAUSE  5
        NEXT DutyCycle
    
        FOR DutyCycle = 254 TO 1 STEP -1   ; Ramp down
            GOSUB  SetDutyCycle
            PAUSE  5
        NEXT DutyCycle
    GOTO Main
    
    
    SetDutyCycle:
        ONcount = TotalCount*/DutyCycle
        OFFcount = TotalCount - ONcount
        IF DutyCycle = 0 THEN
            T1CON.0 = 0    ; turn off timer
            LOW  LED1      ; idle LOW
        ELSE
            T1CON.0 = 1    ; timer on if DutyCycle > 0
        ENDIF 
    RETURN
    
    DISABLE DEBUG
    '---[TMR1 - interrupt handler]------------------------------------------------
    @Timer1 = TMR1L             ; map timer registers to a word variable
    Timer1 VAR WORD EXT
    
    ToggleLED1:
        IF LED1 THEN
            LOW LED1
            T1CON.0 = 0         ; stop the timer
            Timer1  = OFFcount  ; Load OFF count
            T1CON.0 = 1         ; start timer
        ELSE
            HIGH LED1
            T1CON.0 = 0         ; stop the timer
            Timer1  = ONcount   ; Load ON count
            T1CON.0 = 1         ; start timer
        ENDIF
    @ INT_RETURN
    ENABLE DEBUG
    This code produces errors when I attempt to Build
    Last edited by wbubel; - 31st July 2009 at 21:38.

Similar Threads

  1. Clock using Instant Interrupts
    By PICpocket in forum mel PIC BASIC Pro
    Replies: 3
    Last Post: - 16th February 2009, 21:43
  2. DT instant interrupts with mister_e keypad
    By Tomexx in forum mel PIC BASIC Pro
    Replies: 5
    Last Post: - 26th November 2008, 20:02
  3. DT's Instant Interrupts trouble
    By Tomexx in forum mel PIC BASIC Pro
    Replies: 7
    Last Post: - 24th November 2008, 20:48
  4. Keypad and DT's Instant Interrupts
    By Homerclese in forum General
    Replies: 11
    Last Post: - 27th April 2007, 06:32
  5. Replies: 1
    Last Post: - 1st November 2006, 03:11

Members who have read this thread : 6

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

Tags for this Thread

Posting Permissions

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