My Code get crazy after i add interrupt


Closed Thread
Results 1 to 3 of 3
  1. #1
    Join Date
    Jan 2005
    Location
    Puerto Rico
    Posts
    133

    Unhappy My Code get crazy after i add interrupt

    my Program is Working perfect after y add this code for counter
    and now all is crazy (pic18f252)

    ' Define interrupt handler
    DEFINE INTHAND myint 'Assembly language interrupt handler
    wsave VAR BYTE bankA system ' Saves W
    ssave VAR BYTE bankA system ' Saves STATUS

    TICK VAR BYTE bankA ' make sure that the variables are in bank 0 if they are to be used in the interrupt handler

    seconds VAR BYTE ' Elapsed seconds
    minutes VAR WORD ' Elapsed minutes

    minutes = 0 ' Clear time
    seconds = 0

    T1CON = $01 ' Turn on Timer1, prescaler = 1
    INTCON = $C0 ' Enable global interrupts, peripheral interrupts
    PIE1 = $01 ' Enable TMR1 overflow interrupt

    ' Assembly language interrupt handler
    Asm
    myint

    ; Save the state of critical registers
    movwf wsave ; Save W
    swapf STATUS, W ; Swap STATUS to W (swap avoids changingATUS)
    clrf STATUS ; Clear STATUS
    movwf ssave ; Save swapped STATUS


    ; Set the high register of Timer1 to cause an interrupt every
    ; 16384 counts (65536-16384=49152 or $C000). At 4MHz, prescale
    ; set to 1, this equates to a tick every 16384uS. This works
    ; out to about 61 ticks per second, with a slight error. The
    ; error could be reduced substantially by setting the TMR1L
    ; register and playing with different values for the prescaler
    ; and the ticks per second.

    movlw 0C0h ; Prepare to set TMR1 high register
    movwf TMR1H ; Set TMR1H to C0h
    incf _TICK,F ; INCREMENT TICK COUNT
    bcf PIR1, 0 ; Clear interrupt flag


    swapf ssave, W ; Retrieve the swapped STATUS value (swap to avoid anging STATUS)
    movwf STATUS ; Restore it to STATUS
    swapf wsave, F ; Swap the stored W value
    swapf wsave, W ; Restore it to W (swap to avoid changing STATUS)
    retfie ; Return from interrupt
    EndAsm

    get_time:
    ' Update the time when needed. The TICK variable will
    ' overflow if you don't update within 4 seconds. This could
    ' be done in the interrupt handler, but it's easier to do
    ' it in PicBasic, and you usually want the interrupt handler
    ' to be as short and fast as possible.

    PIE1 = 0 ' Mask the interrupt while we're messing with TICK
    seconds = seconds + (tick/61) ' Add the accumulated seconds
    tick = tick // 61 ' Retain the left-over ticks
    PIE1 = $01 ' Interrupt on again
    minutes = minutes + (seconds / 60) ' Add the accumulated minutes
    seconds = seconds // 60 ' Retain the left-over seconds
    Return ' Return to the main program

  2. #2
    Join Date
    Sep 2004
    Location
    montreal, canada
    Posts
    6,898


    Did you find this post helpful? Yes | No

    Default

    My question is probably stupid but, do you have any GOTO to jump over the interrupt subroutine when you power-up the PIC? BUT if i assume that is not the whole code... i'm out

    the whole code in attachement and a brief description of what it's suppose to do will be much appreciated.
    Last edited by mister_e; - 9th May 2005 at 04:35.
    Steve

    It's not a bug, it's a random feature.
    There's no problem, only learning opportunities.

  3. #3
    Join Date
    Jan 2005
    Location
    Puerto Rico
    Posts
    133


    Did you find this post helpful? Yes | No

    Smile thanks all

    i fix it i move the asm code to the top of my code and now work

Similar Threads

  1. ASM code
    By Bill Legge in forum mel PIC BASIC Pro
    Replies: 20
    Last Post: - 1st March 2010, 23:55
  2. Interrupt RPM and Taylors Elapsed time on 18F4620
    By Tobias in forum mel PIC BASIC Pro
    Replies: 70
    Last Post: - 3rd February 2010, 16:12
  3. Can't ID interrupt source with this IntHandler??
    By jellis00 in forum mel PIC BASIC Pro
    Replies: 7
    Last Post: - 3rd June 2009, 02:35
  4. Sleep Mode
    By Pesticida in forum mel PIC BASIC Pro
    Replies: 7
    Last Post: - 13th March 2008, 10:31
  5. I need help with Interrupt
    By wildbilly in forum mel PIC BASIC Pro
    Replies: 8
    Last Post: - 1st September 2007, 19:16

Members who have read this thread : 1

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