PBP array in ASM statements


Closed Thread
Results 1 to 20 of 20

Hybrid View

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


    Did you find this post helpful? Yes | No

    Default Re: PBP array in ASM statements

    BANKSEL is an MPASM directive, and PBP compiler doesn't keep track of it.

    CHK?RP is an equivalent Macro to use with PBP.
    Steve

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

  2. #2
    Join Date
    Sep 2009
    Posts
    755


    Did you find this post helpful? Yes | No

    Default Re: PBP array in ASM statements

    I tried, but problem stays....
    Maybe with DT_int will work.
    I will test now, and come back with the results.

  3. #3
    Join Date
    Sep 2009
    Posts
    755


    Did you find this post helpful? Yes | No

    Default Re: PBP array in ASM statements

    Same with DT_INT...
    Code:
    INCLUDE "DT_INTS-18.bas"     ; Base Interrupt System
    INCLUDE "ReEnterPBP-18.bas"     ; Include if using PBP interrupts
    
    ASM
    INT_LIST  macro    ; IntSource,        Label,  Type, ResetFlag?
            INT_Handler    TMR1_INT,  _RTC,   PBP,  yes
            INT_Handler    TMR3_INT,  _CNT,   PBP,  yes
        endm
        INT_CREATE               ; Creates the interrupt processor
    ENDASM
    
    
    DEFINE        OSC 4         ' We're using a 10MHz oscillator
    'Define        INTHAND myint    ' Define interrupt handler
    DEFINE HSER_BAUD 2400
            OSCCON=%01010110
            OSCCON2.2=0
            OSCTUNE.7=1
            OSCTUNE.6=1
            REFCON0=0
            REFCON1=0
            ADCON1=0
            ADCON2=0
            ANSEL =0           
            ANSELH=0
            CM1CON0=0
            CM2CON0=0
            SRCON0=0
            SRCON1=0
            WPUA=0
            WPUB=0
            WDTCON=0   
            SLRCON=0           
            RCON.7=0
            RCON.6=0   
            UCON=0  
            IOCA=0
            IOCB=0
            T0CON=0
            T1CON=%00001111  
            T2CON=0
            T3CON=%00000110
            INTCON=192  
            INTCON2=0  
            INTCON3=0 
            PIR1=0
            PIR2=0
            PIE1=1
            PIE2=2
            IPR1=0
            IPR2=0
            porta=0
            portb=0
            portc=0
            trisa=255
            trisb=255
            trisc=255
    'RTC_________________________
    Seconds        VAR BYTE bankA  ' variables within myint must be in bank 0.
    Minutes        VAR Byte bankA       ' Elapsed minutes
    Hours          var byte bankA
    Day            var byte bankA     
    Month          var byte bankA
    Year           var byte bankA
    Ticks          var byte bankA
    DMonth         var byte bankA
    'IO________________
    SYMBOL Ul1  =PORTB.5
    SYMBOL Ul2  =PORTB.6
    SYMBOL Pull =PORTC.4
    SYMBOL UWp  =PORTC.3
    'TRIS______________
    INPUT  Ul1
    INPUT  Ul2
    OUTPUT Pull
    INPUT  uwp
    'Brojaci___________
    Brojac  VAR LONG[3] bankA
    PomBroj VAR WORD[2] bankA
    Mtp1    VAR BYTE[2] bankA
    Mtp2    VAR BYTE[2] bankA
    Add     VAR BYTE[2] bankA
    Xn      VAR BYTE    bankA
    Xs      VAR BYTE    bankA
    
    Wp      VAR BIT     bankA
    Trf     VAR BIT     bankA
    Smpl    VAR BIT     bankA
    
    
    
        year=0
        month=0
        day=0
        hours = 4
        minutes = 0       ' Pre Set time here then add seconds to clock using button
        seconds = 0
        ticks=0
        smpl=0  
        PomBroj[0]=0
        PomBroj[1]=0
        Brojac[0]=0
        Brojac[1]=0
        mtp1[0]=1
        mtp1[1]=1
        mtp2[0]=1
        mtp2[1]=1
        add[0]=1
        add[1]=1
        Trf=0
    @    INT_ENABLE  TMR3_INT     
    @    INT_ENABLE  TMR1_INT 
    GoTo mainloop          ' jump over the interrupt handler and sub
                           
    RTC:
       TMR1H=252
    @  INCF _Ticks,F           
       if ticks=32 then 
    @     INCF _Seconds,F  
    @     CLRF _Ticks
          if seconds > 59 then
    @        CLRF _Seconds   
    @        INCF _Minutes,F
             if minutes > 59 then
    @          CLRF _Minutes
    @          INCF _Hours,F
               if hours > 23 then 
    @             CLRF _Hours
    @             INCF _Day,F
                  If month=2 then
                     If year//4<>0 then
                        DMonth=29
                     else
                        DMonth=28
                     endif
                  else
                  Dmonth=30+month.0 
                  endif   
                  If day>Dmonth then
    @                CLRF _Day
    @                INCF _Month,F
                     If month>12 then
    @                   CLRF _Month
    @                   INCF _Year,F
                        if year>99 then year=0
                     endif
                  endif
               endif
             endif
        endif 
       endif
       Pull=1
       TMR3H=255
       IF Smpl=1 then
          TMR3L=207
       else
          TMR3L=240
       endif
       T3CON=%00000111
    @ INT_RETURN
    
    CNT:
       T3CON=%00000110
       Wp= Wp & uwp
       Xn.0=ul1
       Xn.1=ul2
       Pull=0
        
       IF (Xn.0<Xs.0 AND Trf=0) OR  (Xn.0<Xs.0 AND Xn.1=1 AND Trf=1) THEN
    @     INCF _PomBroj,F 'PomBroj[0] = PomBroj[0] + 1 
          IF PomBroj[0] = Mtp2[0] OR (PomBroj=256 AND Mtp2[0]=0)THEN
           Brojac[0]=Brojac[0] + Add[0]
    @      CLRF _PomBroj'PomBroj[0]=0
          ENDIF
       ENDIF
        
       IF (Xn.1<Xs.1 AND Trf=0) OR (Xn.0<Xs.0 AND Trf=1 AND Xn.1=0) THEN
          PomBroj[1] = PomBroj[1] + 1    '  @     INCF _PomBroj+1,F '
          IF PomBroj[1] = Mtp2[1] OR (PomBroj[1]=256 AND Mtp2[1]=0)THEN
           Brojac[1]=Brojac[1]+Add[1]
    @      CLRF _PomBroj+1         'PomBroj[1]=0  
          ENDIF
       ENDIF
       Xs=Xn
    @ INT_RETURN
    
    mainloop:
    if ticks = 0 then
     trisb.7=0      
      ' 2 portb.7,84,
     hserout ["B1: ",dec9 brojac[0]," B2: ",dec9 brojac[1],13,10]'["Time: ",DEC hours, ":", DEC2 minutes, ":", DEC2 seconds,13,10]
    
    endif
    
    GoTo mainloop       ' Repeat main loop
    
    End
    Edit:
    With the DT_INT code is twice bigger than it was. Maybe I could try to get rid of arrays.
    But it complicates the rest of my code... But on the other hand we will slightly extend the battery life...
    Last edited by pedja089; - 29th May 2011 at 00:04.

  4. #4
    Join Date
    Aug 2010
    Location
    Maryland, USA
    Posts
    869


    Did you find this post helpful? Yes | No

    Default Re: PBP array in ASM statements

    It is likely when you enter your ISR, BSR is not 0. You can use PBP stuff in your ASM interrupt as long as you don't use any PBP stuff that uses system variables. These are things like serin/out, adcin, debug etc.

    The thing you MUST do when you first enter is BSR =0. Doesn't matter if you have all ASM or a mix. PBP assumes it is set to bank 0, when it needs a different bank, it will change to it, then change back when done that command. When your interrupt occurs, you may be in a different bank. Then none of you interrupt stuff will work correct. In fact, you may not even be able to clear the interrupt flag.

    This MAY not be the problem right now, but it will be. I spent 2 weeks trying to figure this out. Since then my interrupts work great! Give this a try.

    Now no need to worry if using on interrupt or DT_INT.
    -Bert

    The glass is not half full or half empty, Its twice as big as needed for the job!

    http://foamcasualty.com/ - Warbird R/C scratch building with foam!

  5. #5
    Join Date
    Sep 2009
    Posts
    755


    Did you find this post helpful? Yes | No

    Default Re: PBP array in ASM statements

    I know that I can't use any PBP stuff that uses system variables. In myint I'm only using PBP If's and basic math function...
    Now I'm back to Define INTHAND. And I added BSR = 0 after @myint
    I didn't know how pbp handle banks. Thank you for your notification
    Is there need to return to the bank where he was?
    eg:
    Code:
    @myint
    BSR_Save=BSR
    BSR=0
    ISR routine
    BSR=BSR_Save

  6. #6
    Join Date
    Aug 2010
    Location
    Maryland, USA
    Posts
    869


    Did you find this post helpful? Yes | No

    Default Re: PBP array in ASM statements

    If you are using 1 of the cool autocontex saving chips (interrupt section of the datasheet) BSR should be one of the registers saved and restored. If not, add it in to where you save w, status, and pcl. Then restore it with them.
    -Bert

    The glass is not half full or half empty, Its twice as big as needed for the job!

    http://foamcasualty.com/ - Warbird R/C scratch building with foam!

  7. #7
    Join Date
    Sep 2009
    Posts
    755


    Did you find this post helpful? Yes | No

    Default Re: PBP array in ASM statements

    From datasheet:
    During interrupts, the return PC address is saved on
    the stack. Additionally, the WREG, STATUS and BSR
    registers are saved on the fast return stack.
    I have not thought before I asked that... Sorry...
    But I still can not find what causes problemon CLRF and INCF

Members who have read this thread : 0

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