MIBAM and Array Variables in FOR-NEXT Loops


+ Reply to Thread
Results 1 to 2 of 2
  1. #1
    Join Date
    Oct 2005
    Posts
    35

    Question MIBAM and Array Variables in FOR-NEXT Loops

    Hello

    I'm trying to write a set of universal subroutines that I can transfer different predefined output pins into as opposed to writing a number of subs that except for pin designations and variables look almost the same. I'm using the "MIBAM" setup but this could be applied to any regular code. I tried to alias the pin names. That made all of the outputs sequentially active but I couldn't find a way to "un" alias those pins and so have no program control.

    I also tried to use the original sample array variables in the for next loops (a piece of the code is shown below) but got an error message saying that

    "array variables are not allowed in for next loops". That was a surprise.

    Is there anyway of doing what I think that I may have explained here?


    THANKS


    'using MPASM and array variables
    'does not work
    x = 1
    N = 0
    FOR objectb[x] = Brightness to N STEP -1 ; Ramp down 1 by 1

    PAUSE Speed
    NEXT objectb[x]


    ----------------------------------------------------------------


    'MIBAM CODE
    ' array removed test

    @__config_HS_OSC ;& _WDT_OFF & _PWRTE_ON & _LVP_OFF & _BODEN_OFF

    ;----[ MIBAM Setup ]--------------------------------------------------------

    ;____[ For 12F/16F only - Interrupt Context save locations]_________________
    wsave var byte $20 SYSTEM ' location for W if in bank0
    ;wsave var byte $70 SYSTEM ' Alternate save location for W
    ' if using $70, comment out wsave1-3
    ' --- IF any of these next three lines cause an error ?? -------------------
    ' Comment them out to fix the problem ----
    ' -- The chip being used determines which variables are needed -------------
    wsave1 VAR BYTE $A0 SYSTEM ' location for W if in bank1
    wsave2 VAR BYTE $120 SYSTEM ' location for W if in bank2
    'wsave3 VAR BYTE $1A0 SYSTEM ' location for W if in bank3
    '---DO NOT change these-----------------------------------------------------
    ssave VAR BYTE BANK0 SYSTEM ' location for STATUS register
    psave VAR BYTE BANK0 SYSTEM ' location for PCLATH register


    BAM_COUNT CON 13 ; How many BAM Pins are used?
    INCLUDE "MIBAM.pbp" ; Mirror Image BAM module
    CMCON = 7
    DEFINE OSC 20
    mybyte var byte
    K var byte
    B var byte
    W var byte
    J var byte
    N var byte
    'Speed var byte
    X var word
    CenterSW VAR PORTB.0 'input switch


    Uni0 var byte
    Uni1 var byte
    Uni2 var byte
    Uni3 var byte
    Uni4 var byte
    Uni5 var byte
    Uni6 var byte
    Uni7 var byte
    Uni8 var byte
    Uni9 var byte
    Uni10 var byte

    TRISB = %00000001 'SW INPUT
    TRISA = %00000000


    ASM
    BAM_LIST macro ; Define PIN's to use for BAM
    ;BAM_PIN PORTB, 0, _
    BAM_PIN PORTB, 1, _RaR
    ;BAM_PIN PORTB, 2, _
    BAM_PIN PORTB, 3, _RaL
    BAM_PIN PORTB, 4, _NosLR
    BAM_PIN PORTB, 5, _RaC
    BAM_PIN PORTB, 6, _RaH
    BAM_PIN PORTB, 7, _Mo

    BAM_PIN PORTA, 0, _LgC
    BAM_PIN PORTA, 1, _LgB
    BAM_PIN PORTA, 2, _LgA
    BAM_PIN PORTA, 3, _WinR
    BAM_PIN PORTA, 4, _WinL






    endm
    BAM_INIT BAM_LIST ; Initialize the Pins
    ENDASM
    Speed CON 1 ; Smaller = Fasterspeed
    Brightness CON 255 ; Max DutyCycle

    Main: 'initialize



    RAbank:
    RaR var uni1 'do Rabank
    RaC var Uni2
    RaL var Uni3
    RaH var Uni4

    gosub Universalsub:


    LGbank: 'do LGbank
    LgA var uni1
    LgB var Uni2
    LgC var Uni3


    gosub Universalsub:

    WINbank:
    WinL var uni8 'do WINbank
    WinR var Uni9
    NosLR var Uni10
    Mo var uni10

    goto main



    Universalsub: 'universal routine

    For J = 1 to 60


    FOR Uni1 = Brightness to N STEP -1 ; Ramp down 1 by 1
    gosub check
    PAUSE Speed
    NEXT Uni1

    FOR Uni2 = Brightness to N STEP -1
    gosub check
    PAUSE Speed
    NEXT Uni2

    FOR Uni3 = Brightness to N STEP -1
    gosub check
    PAUSE Speed
    NEXT Uni3





    FOR Uni1 = N to Brightness -1 ; Ramp up 1 by 1
    gosub check
    PAUSE Speed
    NEXT Uni1

    FOR Uni2 = N to Brightness -1

    gosub check
    PAUSE Speed
    NEXT Uni2

    FOR Uni3 = N to Brightness -1
    gosub check
    PAUSE Speed
    NEXT Uni3


    Next J


    return



    check: 'dummied out for now

    return
    GOTO Main
    Thanks,
    Homerclese

  2. #2
    Join Date
    Nov 2005
    Location
    Perth, Australia
    Posts
    429

    Default

    How about this:

    Code:
    x = 1
    N = 0
    FOR temp = Brightness to N STEP -1 ; Ramp down 1 by 1
        objectb[x] = temp
    
        PAUSE Speed
    NEXT temp
    "I think fish is nice, but then I think that rain is wet, so who am I to judge?" - Douglas Adams

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