Change variable allocation to save code space


+ Reply to Thread
Results 1 to 12 of 12
  1. #1
    Join Date
    Dec 2007
    Location
    Paris
    Posts
    101

    Default Change variable allocation to save code space

    Dear everyone,

    I have a quick question regarding what could be a trivial problem, I am driving a complex LED matrix which is fed through a series of shift registers. The output are out of order, so I have to reconstruct the correct sequence using a brightness array. I then used some modifiers to get the right order:

    Code:
    LEDPattern VAR BYTE[80]
    
    RedSegment1 VAR LEDPattern[23]
    RedSegment2 VAR LEDPattern[21]
    RedSegment3 VAR LEDPattern[15]
    RedSegment4 VAR LEDPattern[12]
    RedSegment5 VAR LEDPattern[6]
    RedSegment6 VAR LEDPattern[4]
    RedSegment7 VAR LEDPattern[26]
    ....
    Now I have a series of subroutines designed to display a series of patterns. Some are quite complex, but some are simple like this one to turn all the red segments on:

    Code:
    RedSegment1 = 8
    RedSegment2 = 8
    RedSegment3 = 8
    RedSegment4 = 8
    RedSegment5 = 8
    RedSegment6 = 8
    ....
    Is there a better solution for doing this to save some code space? I could use a FOR loop but I cannot refer to the variable change as with an array...

    Thanks for the help!

  2. #2
    Join Date
    Sep 2005
    Location
    Campbell, CA
    Posts
    1,107


    Did you find this post helpful? Yes | No

    Default Re: Change variable allocation to save code space

    I don't know if it will work in your case, but you can use an array to point to an index in another array.

    Something like

    Arraywrite OffsetArray,[0,23,21,15,12,6,4,26]

    For X = 1 to 8
    Temp = OffsetArray[X]
    LEDPattern[Temp] = 8
    Next X
    Charles Linquist

  3. #3
    Join Date
    Dec 2007
    Location
    Paris
    Posts
    101


    Did you find this post helpful? Yes | No

    Default Re: Change variable allocation to save code space

    Good point, I thought about doing this, but it just transfer the program memory overhead into the RAM right as it will mean creating another whole 80 byte array, right? Also I will have to fill OffsetArray with a series of 80 constants which will go right into program memory.

    I'm using a 16F648A with 256B of RAM and the compiler cannot fit two such large arrays into contiguous banks right now. Granted that I probably have some optimizations left on the program, I will not be able to free up much RAM space though...

  4. #4
    Join Date
    Sep 2005
    Location
    Campbell, CA
    Posts
    1,107


    Did you find this post helpful? Yes | No

    Default Re: Change variable allocation to save code space

    Is it fair to ask why you don't simply use a big 18F part to begin with? Optimizing code to fit a small device might be rewarding, but it generally isn't cost-effective from a time standpoint uless you are making several hundred or more.
    Charles Linquist

  5. #5
    Join Date
    Dec 2007
    Location
    Paris
    Posts
    101


    Did you find this post helpful? Yes | No

    Default Re: Change variable allocation to save code space

    Yes, I have looked in microchip catalog, but there is no SOIC 18 pin compatible parts with more code memory... The 16F88 does have 384B of RAM and is the only 18 pin with better features. Of course I have already made 60x13 cm double sized PCBs which were quite expensive, so I have to use the SOIC18 layout. It seems that the 18F family has discarded the 18pin footprint.

    I am reaching the 4k word limit which only restrain me from adding more animations. It is not a serious problem but I thought I could do a better job than having more than 200 lines of "Variable = Value" in my program.
    Last edited by aberco; - 3rd September 2011 at 22:40.

  6. #6
    Join Date
    Mar 2006
    Location
    China
    Posts
    266


    Did you find this post helpful? Yes | No

    Default Re: Change variable allocation to save code space

    With some creative thinking and some luck you might add an EEprom. It could be possible to solder it directly onto the PIC itself. Piggy-back the EEprom and set the i2c bus to drivven and you might even get away without adding the pullup resistors for sda and scl.

    It is only 4 pins (GND, VDD, SDA, SCL) you need to connect between the PIC and the eeprom, the other pins on the EEPROM you connect either to GND or VDD (address, RW). Microchip have alot of I2C eeproms in different sizes and packages so if you just have 2 un-used pins on the pic in a suitable position this might be an option.

    Then you can add alot of LED patterns and use the I2C command to load them into the RAM variables when you need to display the pattern.
    Last edited by Jumper; - 4th September 2011 at 04:06.

  7. #7
    Join Date
    Sep 2004
    Location
    Mentor, Ohio
    Posts
    347


    Did you find this post helpful? Yes | No

    Smile Re: Change variable allocation to save code space

    Hi Aberco,

    I use alot of 16F87s which has the same pinout as the 16F88. I needed more code space to do more things with my product without adding parts to the board. Microchip recently came out with the 16F1847 which has 8K of code space and 1024 bytes of ram and 256 bytes of EEPROM and is available in your SOIC format. You can only program it with PBP3 and if you are using an MELabs USB programming you will need to update the software on it. You will also need the latest MCS software that comes with PBP3.

    HTH,
    BobK
    Last edited by BobK; - 4th September 2011 at 14:41. Reason: Forgot something!

  8. #8
    Join Date
    Dec 2007
    Location
    Paris
    Posts
    101


    Did you find this post helpful? Yes | No

    Default Re: Change variable allocation to save code space

    EEPROM will not be possible as there is no footprint on the PCB.
    I have suppressed all the redundancy in the remaining of the code and managed to free more than 800 words (more than 20%!). I still have those long sequences of variable allocation though... but maybe it is not possible to do any better than that afteral.

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


    Did you find this post helpful? Yes | No

    Default Re: Change variable allocation to save code space

    Never say never. It's amazing how we could shrink it.... assuming we could see the code. BobK's advice seems fair too.
    Steve

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

  10. #10
    Join Date
    Dec 2007
    Location
    Paris
    Posts
    101


    Did you find this post helpful? Yes | No

    Default Re: Change variable allocation to save code space

    Oh yeah, coming from hardware development as a hobby I am very excited to start mastering a bit more microcontrollers. Makes a whole new world of possibilities!

    Now my code is working absolutely flawlessly. I have not much reason to change it but I'd like to learn about possibilities to further shrink the code as it seems to be very redundant right now... with my latest optimizations it compiles with around 3150 words so there is still some free space.

    Project is a LED sign that I have designed for a friend. There are now 52 different animations that are all listed in the table below. The names at the top of the matrix are the subroutine that needs to be called to execute the corresponding animation



    And the full program:

    Code:
    '***************************************************************************
    '*  Name    : Tattoosign.pbp                                               *
    '*  Author  : Antoine Bercovici                                            *
    '*  Date    : 08/08/2011                                                   *
    '*  Version : 1.0                                                          *  
    '***************************************************************************
    
    ASM
    __config _HS_OSC & _WDT_ON & _MCLRE_ON & _BOREN_OFF & _LVP_OFF & _CP_ON
    ENDASM
    
    DEFINE OSC 20          
    DEFINE LOADER_USED 1
    clear
    
    '*******************************************************
    'Init for PIC16F648A
    '*******************************************************
    CMCON = %00000111 'Disable comparator module
    TRISA = %00000000 'All PortA is output
    TRISB = %00000001 'All PortB is output, PortB.0 is input
    INTCON = %00010000 'Enable Interrupt on PortB.0
    OPTION_REG.6 = 0 'Interrupt on falling edge 1->0 transition
    
    '*******************************************************
    'I/O port declaration
    '*******************************************************
    DATShift    VAR PORTA.2
    CLKShift    VAR PortB.1
    STRShift    VAR PortB.3
    PushButton  VAR PortB.0
    
    '*******************************************************
    'Variable declaration
    '*******************************************************
    ShiftCounter VAR BYTE
    PWMCounter VAR Byte
    AnimationCounter VAR BYTE
    AnimationSpeed VAR WORD
    AnimationStyle VAR BYTE
    AnimationNumber VAR BYTE
    StoredAnimationSpeed VAR BYTE
    SpeedCounter VAR WORD
    ButtonCounter VAR BYTE
    PhaseCounter VAR BYTE
    Buffer VAR BYTE
    DemoMode VAR BIT
    DemoCounter VAR WORD
    
    LEDPattern VAR BYTE[76]
    Phase VAR BYTE[16]
    
    RedSegment1 VAR LEDPattern[23]
    RedSegment2 VAR LEDPattern[21]
    RedSegment3 VAR LEDPattern[15]
    RedSegment4 VAR LEDPattern[12]
    RedSegment5 VAR LEDPattern[6]
    RedSegment6 VAR LEDPattern[4]
    RedSegment7 VAR LEDPattern[26]
    RedSegment8 VAR LEDPattern[17]
    RedSegment9 VAR LEDPattern[19]
    RedSegment10 VAR LEDPattern[10]
    RedSegment11 VAR LEDPattern[8]
    RedSegment12 VAR LEDPattern[2]
    RedSegment13 VAR LEDPattern[0]
    RedSegment14 VAR LEDPattern[30]
    RedSegment15 VAR LEDPattern[28]
    RedSegment16 VAR LEDPattern[35]
    RedSegment17 VAR LEDPattern[38]
    RedSegment18 VAR LEDPattern[36]
    RedSegment19 VAR LEDPattern[33]
    RedSegment20 VAR LEDPattern[55]
    RedSegment21 VAR LEDPattern[53]
    RedSegment22 VAR LEDPattern[43]
    RedSegment23 VAR LEDPattern[46]
    RedSegment24 VAR LEDPattern[44]
    RedSegment25 VAR LEDPattern[41]
    RedSegment26 VAR LEDPattern[48]
    RedSegment27 VAR LEDPattern[56]
    RedSegment28 VAR LEDPattern[58]
    RedSegment29 VAR LEDPattern[62]
    RedSegment30 VAR LEDPattern[60]
    RedSegment31 VAR LEDPattern[74]
    RedSegment32 VAR LEDPattern[64]
    RedSegment33 VAR LEDPattern[66]
    RedSegment34 VAR LEDPattern[70]
    RedSegment35 VAR LEDPattern[68]
    
    GreenSegment1 VAR LEDPattern[24]
    GreenSegment2 VAR LEDPattern[22]
    GreenSegment3 VAR LEDPattern[20]
    GreenSegment4 VAR LEDPattern[13]
    GreenSegment5 VAR LEDPattern[7]
    GreenSegment6 VAR LEDPattern[5]
    GreenSegment7 VAR LEDPattern[27]
    GreenSegment8 VAR LEDPattern[25]
    GreenSegment9 VAR LEDPattern[18]
    GreenSegment10 VAR LEDPattern[11]
    GreenSegment11 VAR LEDPattern[9]
    GreenSegment12 VAR LEDPattern[3]
    GreenSegment13 VAR LEDPattern[1]
    GreenSegment14 VAR LEDPattern[31]
    GreenSegment15 VAR LEDPattern[29]
    GreenSegment16 VAR LEDPattern[51]
    GreenSegment17 VAR LEDPattern[39]
    GreenSegment18 VAR LEDPattern[37]
    GreenSegment19 VAR LEDPattern[32]
    GreenSegment20 VAR LEDPattern[50]
    GreenSegment21 VAR LEDPattern[54]
    GreenSegment22 VAR LEDPattern[52]
    GreenSegment23 VAR LEDPattern[47]
    GreenSegment24 VAR LEDPattern[45]
    GreenSegment25 VAR LEDPattern[40]
    GreenSegment26 VAR LEDPattern[49]
    GreenSegment27 VAR LEDPattern[72]
    GreenSegment28 VAR LEDPattern[59]
    GreenSegment29 VAR LEDPattern[63]
    GreenSegment30 VAR LEDPattern[61]
    GreenSegment31 VAR LEDPattern[75]
    GreenSegment32 VAR LEDPattern[73]
    GreenSegment33 VAR LEDPattern[67]
    GreenSegment34 VAR LEDPattern[71]
    GreenSegment35 VAR LEDPattern[69]
    
    TattooSegment1 VAR LEDPattern[14]
    TattooSegment2 VAR LEDPattern[16]
    TattooSegment3 VAR LEDPattern[34]
    TattooSegment4 VAR LEDPattern[42]
    TattooSegment5 VAR LEDPattern[57]
    TattooSegment6 VAR LEDPattern[65]
    
    Phase1 VAR Phase[1]
    Phase2 VAR Phase[2]
    Phase3 VAR Phase[3]
    Phase4 VAR Phase[4]
    Phase5 VAR Phase[5]
    Phase6 VAR Phase[6]
    Phase7 VAR Phase[7]
    Phase8 VAR Phase[8]
    Phase9 VAR Phase[9]
    Phase10 VAR Phase[10]
    Phase11 VAR Phase[11]
    Phase12 VAR Phase[12]
    Phase13 VAR Phase[13]
    Phase14 VAR Phase[14]
    Phase15 VAR Phase[15]
    Phase16 VAR Phase[16]
    
    '*******************************************************
    'Init the interrupt handling system
    '*******************************************************
    INCLUDE "DT_INTS-14.bas" 'Base Interrupt System
    INCLUDE "ReEnterPBP.bas" 'Include if using PBP interrupts
    
    ASM
    INT_LIST  macro     ; IntSource,          Label,  Type, ResetFlag?
            INT_Handler     INT_INT,   _ButtonInterrupt,   PBP,  Yes
        endm
        INT_CREATE ; Creates the interrupt processor
    ENDASM
    
    wsave VAR BYTE $70 SYSTEM 'alternate save location for W, for DT_INTS use
    
    '*******************************************************
    'Program start
    '*******************************************************
    ShiftCounter = 0
    AnimationCounter = 0
    SpeedCounter = 255
    ButtonCounter = 0
    DemoMode = 0
    DemoCounter = 0
    
    AnimationNumber = 51 
    
    READ 0, AnimationStyle
    READ 1, StoredAnimationSpeed
    
    IF PushButton = 0 THEN
        DemoMode = 1
        AnimationStyle = 0
        StoredAnimationSpeed = 5
    ENDIF
        
    @ INT_ENABLE INT_INT ; enable Button interrupt
    
    '*******************************************************
    'Main program loop
    '*******************************************************
    MainLoop:
    
    Gosub AnimationUpdate
    GOSUB DisplayLoop
    
    GOTO MainLoop
    
    '*******************************************************
    'Do one display loop
    '*******************************************************
    DisplayLoop:
    
    FOR PWMCounter = 0 TO 8 'There are 9 PWM shades from 0 (all off) to 8 (all on)
    
        FOR ShiftCounter = 79 TO 0 STEP - 1
        
            IF LedPattern[ShiftCounter] > PWMCounter THEN
                LOW DATShift
            ELSE
                HIGH DATShift
            ENDIF
    
            HIGH CLKShift   
            LOW CLKShift
    
        Next ShiftCounter
    
        HIGH STRShift
        LOW STRShift
    
    NEXT PWMCounter
    
    RETURN
    
    '*******************************************************
    'Update one step for animation status
    '*******************************************************
    AnimationUpdate:
    
    IF DemoMode = 1 THEN
        DemoCounter = DemoCounter + 1
        IF DemoCounter >= 1200 THEN
            DemoCounter = 0
            AnimationStyle = AnimationStyle + 1
            IF AnimationStyle > AnimationNumber THEN AnimationStyle = 0
        ENDIF
    ENDIF
    
    LOOKUP StoredAnimationSpeed, [6, 8, 10, 12, 14, 17, 21, 27, 33, 50, 80, 160, 0], AnimationSpeed
    IF AnimationStyle > 31 THEN AnimationSpeed = AnimationSpeed * 2
    
    IF SpeedCounter >= AnimationSpeed THEN
        SpeedCounter = 0
        IF AnimationSpeed > 0 THEN AnimationCounter = AnimationCounter + 1
        IF AnimationCounter >= 16 THEN AnimationCounter = 0 'There are 16 steps for an animation loop
    
    ENDIF
    
    SpeedCounter = SpeedCounter + 1
    
    IF AnimationStyle <= 27 THEN GOSUB MonoGradient
    IF AnimationStyle >= 28 AND AnimationStyle <= 31 THEN GOSUB PolyGradient
    IF AnimationStyle >= 32 AND AnimationStyle <= 37 THEN GOSUB NarrowColorBanding
    IF AnimationStyle >= 38 THEN GOSUB MediumColorBanding
    
    GOSUB TurnAllOff
    
    Select CASE AnimationStyle
        
        CASE 1
            GOSUB TurnRedON
        Case 2
            GOSUB TurnGreenON
        CASE 3
            GOSUB TurnRedON
            GOSUB TurnGreenON
        CASE 4, 5
            GOSUB RedGradient
        CASE 6, 7
            GOSUB GreenGradient
        CASE 8, 9
            GOSUB RedGradient        
            GOSUB GreenGradient
        CAsE 10, 11
            GOSUB TurnGreenON
            GOSUB RedGradient
        CASE 12, 13
            GOSUB TurnRedON
            GOSUB GreenGradient
        CASE 14, 15
            GOSUB VerticalRedGradient
        CASE 16, 17           
            GOSUB VerticalGreenGradient
        CASE 18, 19
            GOSUB VerticalRedGradient
            GOSUB VerticalGreenGradient
        CASE 20, 21
            GOSUB TurnGreenON
            GOSUB VerticalRedGradient
        CASE 22, 23
            GOSUB TurnRedON
            GOSUB VerticalGreenGradient
        CASE 24
            GOSUB MonoRedGradient
        CASE 25
            GOSUB MonoGreenGradient
        CASE 26
            GOSUB MonoRedGradient
            GOSUB MonoGreenGradient
        CASE 27
            GOSUB MonoGreenGradient
            GOSUB MonoRedAntiGradient
        Case 28, 29
            GOSUB GreenGradient
            GOSUB RedAntiGradient
        CASE 30, 31
            GOSUB VerticalGreenGradient
            GOSUB VerticalRedAntiGradient
        CASE 32
            GOSUB RedGradient
        CASE 33
            GOSUB GreenGradient
        CASE 34
            GOSUB RedGradient        
            GOSUB GreenGradient
        CASE 35
            GOSUB TurnGreenON
            GOSUB RedGradient
        CASE 36
            GOSUB TurnRedON
            GOSUB GreenGradient
        CASE 37, 38, 39
            GOSUB GreenGradient
            GOSUB RedShortAntiGradient
        CASE 40, 41
            GOSUB RedGradient
        CASE 42, 43
            GOSUB GreenGradient
        CASE 44, 45
            GOSUB RedGradient    
            GOSUB GreenGradient
        CASE 46, 47
            GOSUB TurnGreenON
            GOSUB RedGradient
        CASE 48, 49
            GOSUB TurnRedON
            GOSUB GreenGradient
        CASE 50, 51
            GOSUB GreenGradient
            GOSUB RedMediumAntiGradient    
                                
    END SELECT
    
    GOSUB TurnTATTOOon
    
    RETURN
    
    '*******************************************************
    'Monochromatic gradient Right
    '*******************************************************
    MonoGradient:
        
    FOR PhaseCounter = 0 TO 15
        LOOKUP AnimationCounter + PhaseCounter, [0, 1, 2, 3, 4, 5, 6, 7, 8, 7, 6, 5, 4, 3, 2, 1, 0, 1, 2, 3, 4, 5, 6, 7, 8, 7, 6, 5, 4, 3, 2, 1], Buffer
        GOSUB GradientDirection
    NEXT PhaseCounter
            
    RETURN
    
    '*******************************************************
    'Polychromatic gradient
    '*******************************************************
    PolyGradient:
        
    FOR PhaseCounter = 0 TO 15                   
        LOOKUP AnimationCounter + PhaseCounter, [0, 2, 4, 6, 8, 8, 8, 8, 8, 8, 8, 8, 8, 6, 4, 2, 0, 2, 4, 6, 8, 8, 8, 8, 8, 8, 8, 8, 8, 6, 4, 2], Buffer
        GOSUB GradientDirection
    NEXT PhaseCounter
            
    RETURN
    
    '*******************************************************
    'Narrow color banding
    '*******************************************************
    NarrowColorBanding:
        
    FOR PhaseCounter = 0 TO 15                   
        Buffer = AnimationCounter + PhaseCounter
        IF Buffer.0 = 0 THEN
            Buffer = 0
        ELSE
            Buffer = 8
        ENDIF
        Phase[PhaseCounter + 1] = Buffer
    NEXT PhaseCounter
            
    RETURN
    
    '*******************************************************
    'Medium color banding
    '*******************************************************
    MediumColorBanding:
        
    FOR PhaseCounter = 0 TO 15
        Buffer = AnimationCounter + PhaseCounter                   
        IF Buffer.1 = 0 THEN
            Buffer = 0
        ELSE
            Buffer = 8
        ENDIF
                
        GOSUB GradientDirection
    NEXT PhaseCounter
            
    RETURN
    
    '*******************************************************
    'Gradient Direction is left or right
    '*******************************************************
    GradientDirection:
    
    IF AnimationStyle.0 = 0 THEN 
        Phase[PhaseCounter + 1] = Buffer
    ELSE
        Phase[16 - PhaseCounter] = Buffer
    ENDIF
    
    RETURN
    
    '*******************************************************
    'Turn all LEDs off
    '*******************************************************
    TurnAllOff:
    
    FOR ShiftCounter = 0 TO 75
        LedPattern[ShiftCounter] = 0
    Next ShiftCounter
    
    RETURN
    
    '*******************************************************
    'Turn TATTOO on
    '*******************************************************
    TurnTATTOOon:
    
    TattooSegment1 = 8
    TattooSegment2 = 8
    TattooSegment3 = 8
    TattooSegment4 = 8
    TattooSegment5 = 8
    TattooSegment6 = 8
    
    RETURN
    
    '*******************************************************
    'TATTOO Gradient
    '*******************************************************
    'TATTOOGradient:
    
    'TattooSegment1 = Phase1
    'TattooSegment2 = Phase1
    'TattooSegment3 = Phase1
    'TattooSegment4 = Phase1
    'TattooSegment5 = Phase1
    'TattooSegment6 = Phase1
    
    RETURN
    
    '*******************************************************
    'TATTOO shift
    '*******************************************************
    'TATTOOShift:
    
    'TattooSegment1 = Phase1
    'TattooSegment2 = Phase2
    'TattooSegment3 = Phase3
    'TattooSegment4 = Phase4
    'TattooSegment5 = Phase5
    'TattooSegment6 = Phase6
    
    'RETURN
    
    '*******************************************************
    'Turn Green segments on
    '*******************************************************
    TurnGreenOn:
    
    GreenSegment1 = 8
    GreenSegment2 = 8
    GreenSegment3 = 8
    GreenSegment4 = 8
    GreenSegment5 = 8
    GreenSegment6 = 8
    GreenSegment7 = 8
    GreenSegment8 = 8
    GreenSegment9 = 8
    GreenSegment10 = 8
    GreenSegment11 = 8
    GreenSegment12 = 8
    GreenSegment13 = 8
    GreenSegment14 = 8
    GreenSegment15 = 8
    GreenSegment16 = 8
    GreenSegment17 = 8
    GreenSegment18 = 8
    GreenSegment19 = 8
    GreenSegment20 = 8
    GreenSegment21 = 8
    GreenSegment22 = 8
    GreenSegment23 = 8
    GreenSegment24 = 8
    GreenSegment25 = 8
    GreenSegment26 = 8
    GreenSegment27 = 8
    GreenSegment28 = 8
    GreenSegment29 = 8
    GreenSegment30 = 8
    GreenSegment31 = 8
    GreenSegment32 = 8
    GreenSegment33 = 8
    GreenSegment34 = 8
    GreenSegment35 = 8
    
    RETURN
    
    '*******************************************************
    'Turn Red segments on
    '*******************************************************
    TurnRedOn:
    
    RedSegment1 = 8
    RedSegment2 = 8
    RedSegment3 = 8
    RedSegment4 = 8
    RedSegment5 = 8
    RedSegment6 = 8
    RedSegment7 = 8
    RedSegment8 = 8
    RedSegment9 = 8
    RedSegment10 = 8
    RedSegment11 = 8
    RedSegment12 = 8
    RedSegment13 = 8
    RedSegment14 = 8
    RedSegment15 = 8
    RedSegment16 = 8
    RedSegment17 = 8
    RedSegment18 = 8
    RedSegment19 = 8
    RedSegment20 = 8
    RedSegment21 = 8
    RedSegment22 = 8
    RedSegment23 = 8
    RedSegment24 = 8
    RedSegment25 = 8
    RedSegment26 = 8
    RedSegment27 = 8
    RedSegment28 = 8
    RedSegment29 = 8
    RedSegment30 = 8
    RedSegment31 = 8
    RedSegment32 = 8
    RedSegment33 = 8
    RedSegment34 = 8
    RedSegment35 = 8
    
    RETURN
    
    '*******************************************************
    'Green gradient 45
    '*******************************************************
    GreenGradient:
    
    GreenSegment1 = Phase1
    GreenSegment2 = Phase2
    GreenSegment3 = Phase3
    GreenSegment4 = Phase4
    GreenSegment5 = Phase5
    GreenSegment6 = Phase6
    GreenSegment7 = Phase3
    GreenSegment8 = Phase4
    GreenSegment9 = Phase5
    GreenSegment10 = Phase6
    GreenSegment11 = Phase7
    GreenSegment12 = Phase8
    GreenSegment13 = Phase9
    GreenSegment14 = Phase9
    GreenSegment15 = Phase10
    GreenSegment16 = Phase11
    GreenSegment17 = Phase12
    GreenSegment18 = Phase13
    GreenSegment19 = Phase14
    GreenSegment20 = Phase13
    GreenSegment21 = Phase14
    GreenSegment22 = Phase15
    GreenSegment23 = Phase16
    GreenSegment24 = Phase1
    GreenSegment25 = Phase2
    GreenSegment26 = Phase16
    GreenSegment27 = Phase1
    GreenSegment28 = Phase2
    GreenSegment29 = Phase3
    GreenSegment30 = Phase4
    GreenSegment31 = Phase4
    GreenSegment32 = Phase5
    GreenSegment33 = Phase6
    GreenSegment34 = Phase7
    GreenSegment35 = Phase8
    
    RETURN
    
    '*******************************************************
    'Red gradient 45
    '*******************************************************
    RedGradient:
    
    RedSegment1 = Phase1
    RedSegment2 = Phase2
    RedSegment3 = Phase3
    RedSegment4 = Phase4
    RedSegment5 = Phase5
    RedSegment6 = Phase6
    RedSegment7 = Phase3
    RedSegment8 = Phase4
    RedSegment9 = Phase5
    RedSegment10 = Phase6
    RedSegment11 = Phase7
    RedSegment12 = Phase8
    RedSegment13 = Phase9
    RedSegment14 = Phase9
    RedSegment15 = Phase10
    RedSegment16 = Phase11
    RedSegment17 = Phase12
    RedSegment18 = Phase13
    RedSegment19 = Phase14
    RedSegment20 = Phase13
    RedSegment21 = Phase14
    RedSegment22 = Phase15
    RedSegment23 = Phase16
    RedSegment24 = Phase1
    RedSegment25 = Phase2
    RedSegment26 = Phase16
    RedSegment27 = Phase1
    RedSegment28 = Phase2
    RedSegment29 = Phase3
    RedSegment30 = Phase4
    RedSegment31 = Phase4
    RedSegment32 = Phase5
    RedSegment33 = Phase6
    RedSegment34 = Phase7
    RedSegment35 = Phase8
    
    RETURN
    
    '*******************************************************
    'Red gradient 45 Antiphase
    '*******************************************************
    RedAntiGradient:
    
    RedSegment1 = Phase9
    RedSegment2 = Phase10
    RedSegment3 = Phase11
    RedSegment4 = Phase12
    RedSegment5 = Phase13
    RedSegment6 = Phase14
    RedSegment7 = Phase11
    RedSegment8 = Phase12
    RedSegment9 = Phase13
    RedSegment10 = Phase14
    RedSegment11 = Phase15
    RedSegment12 = Phase16
    RedSegment13 = Phase1
    RedSegment14 = Phase1
    RedSegment15 = Phase2
    RedSegment16 = Phase3
    RedSegment17 = Phase4
    RedSegment18 = Phase5
    RedSegment19 = Phase6
    RedSegment20 = Phase5
    RedSegment21 = Phase6
    RedSegment22 = Phase7
    RedSegment23 = Phase8
    RedSegment24 = Phase9
    RedSegment25 = Phase10
    RedSegment26 = Phase8
    RedSegment27 = Phase9
    RedSegment28 = Phase10
    RedSegment29 = Phase11
    RedSegment30 = Phase12
    RedSegment31 = Phase12
    RedSegment32 = Phase13
    RedSegment33 = Phase14
    RedSegment34 = Phase15
    RedSegment35 = Phase16
    
    RETURN
    
    '*******************************************************
    'Red gradient 45 with 1 step Antiphase
    '*******************************************************
    RedShortAntiGradient:
    
    RedSegment1 = Phase2
    RedSegment2 = Phase3
    RedSegment3 = Phase4
    RedSegment4 = Phase5
    RedSegment5 = Phase6
    RedSegment6 = Phase7
    RedSegment7 = Phase4
    RedSegment8 = Phase5
    RedSegment9 = Phase6
    RedSegment10 = Phase7
    RedSegment11 = Phase8
    RedSegment12 = Phase9
    RedSegment13 = Phase10
    RedSegment14 = Phase10
    RedSegment15 = Phase11
    RedSegment16 = Phase12
    RedSegment17 = Phase13
    RedSegment18 = Phase14
    RedSegment19 = Phase15
    RedSegment20 = Phase14
    RedSegment21 = Phase15
    RedSegment22 = Phase16
    RedSegment23 = Phase1
    RedSegment24 = Phase2
    RedSegment25 = Phase3
    RedSegment26 = Phase1
    RedSegment27 = Phase2
    RedSegment28 = Phase3
    RedSegment29 = Phase4
    RedSegment30 = Phase5
    RedSegment31 = Phase5
    RedSegment32 = Phase6
    RedSegment33 = Phase7
    RedSegment34 = Phase8
    RedSegment35 = Phase9
    
    RETURN
    
    '*******************************************************
    'Red gradient 45 with 2 step Antiphase
    '*******************************************************
    RedMediumAntiGradient:
    
    RedSegment1 = Phase3
    RedSegment2 = Phase4
    RedSegment3 = Phase5
    RedSegment4 = Phase6
    RedSegment5 = Phase7
    RedSegment6 = Phase8
    RedSegment7 = Phase5
    RedSegment8 = Phase6
    RedSegment9 = Phase7
    RedSegment10 = Phase8
    RedSegment11 = Phase9
    RedSegment12 = Phase10
    RedSegment13 = Phase11
    RedSegment14 = Phase11
    RedSegment15 = Phase12
    RedSegment16 = Phase13
    RedSegment17 = Phase14
    RedSegment18 = Phase15
    RedSegment19 = Phase16
    RedSegment20 = Phase15
    RedSegment21 = Phase16
    RedSegment22 = Phase1
    RedSegment23 = Phase2
    RedSegment24 = Phase3
    RedSegment25 = Phase4
    RedSegment26 = Phase2
    RedSegment27 = Phase3
    RedSegment28 = Phase4
    RedSegment29 = Phase5
    RedSegment30 = Phase6
    RedSegment31 = Phase6
    RedSegment32 = Phase7
    RedSegment33 = Phase8
    RedSegment34 = Phase9
    RedSegment35 = Phase10
    
    Return
    
    '*******************************************************
    'Vertical Green gradient
    '*******************************************************
    VerticalGreenGradient:
    
    GreenSegment1 = Phase1
    GreenSegment2 = Phase1
    GreenSegment3 = Phase1
    GreenSegment4 = Phase1
    GreenSegment5 = Phase1
    GreenSegment6 = Phase1
    GreenSegment7 = Phase2
    GreenSegment8 = Phase2
    GreenSegment9 = Phase2
    GreenSegment10 = Phase2
    GreenSegment11 = Phase2
    GreenSegment12 = Phase2
    GreenSegment13 = Phase2
    GreenSegment14 = Phase3
    GreenSegment15 = Phase3
    GreenSegment16 = Phase3
    GreenSegment17 = Phase3
    GreenSegment18 = Phase3
    GreenSegment19 = Phase3
    GreenSegment20 = Phase4
    GreenSegment21 = Phase4
    GreenSegment22 = Phase4
    GreenSegment23 = Phase4
    GreenSegment24 = Phase4
    GreenSegment25 = Phase4
    GreenSegment26 = Phase5
    GreenSegment27 = Phase5
    GreenSegment28 = Phase5
    GreenSegment29 = Phase5
    GreenSegment30 = Phase5
    GreenSegment31 = Phase6
    GreenSegment32 = Phase6
    GreenSegment33 = Phase6
    GreenSegment34 = Phase6
    GreenSegment35 = Phase6
    
    RETURN
    
    '*******************************************************
    'Vertical Red gradient
    '*******************************************************
    VerticalRedGradient:
    
    RedSegment1 = Phase1
    RedSegment2 = Phase1
    RedSegment3 = Phase1
    RedSegment4 = Phase1
    RedSegment5 = Phase1
    RedSegment6 = Phase1
    RedSegment7 = Phase2
    RedSegment8 = Phase2
    RedSegment9 = Phase2
    RedSegment10 = Phase2
    RedSegment11 = Phase2
    RedSegment12 = Phase2
    RedSegment13 = Phase2
    RedSegment14 = Phase3
    RedSegment15 = Phase3
    RedSegment16 = Phase3
    RedSegment17 = Phase3
    RedSegment18 = Phase3
    RedSegment19 = Phase3
    RedSegment20 = Phase4
    RedSegment21 = Phase4
    RedSegment22 = Phase4
    RedSegment23 = Phase4
    RedSegment24 = Phase4
    RedSegment25 = Phase4
    RedSegment26 = Phase5
    RedSegment27 = Phase5
    RedSegment28 = Phase5
    RedSegment29 = Phase5
    RedSegment30 = Phase5
    RedSegment31 = Phase6
    RedSegment32 = Phase6
    RedSegment33 = Phase6
    RedSegment34 = Phase6
    RedSegment35 = Phase6
    
    RETURN
    
    '*******************************************************
    'Vertical Red gradient Antiphase
    '*******************************************************
    VerticalRedAntiGradient:
    
    RedSegment1 = Phase9
    RedSegment2 = Phase9
    RedSegment3 = Phase9
    RedSegment4 = Phase9
    RedSegment5 = Phase9
    RedSegment6 = Phase9
    RedSegment7 = Phase10
    RedSegment8 = Phase10
    RedSegment9 = Phase10
    RedSegment10 = Phase10
    RedSegment11 = Phase10
    RedSegment12 = Phase10
    RedSegment13 = Phase10
    RedSegment14 = Phase11
    RedSegment15 = Phase11
    RedSegment16 = Phase11
    RedSegment17 = Phase11
    RedSegment18 = Phase11
    RedSegment19 = Phase11
    RedSegment20 = Phase12
    RedSegment21 = Phase12
    RedSegment22 = Phase12
    RedSegment23 = Phase12
    RedSegment24 = Phase12
    RedSegment25 = Phase12
    RedSegment26 = Phase13
    RedSegment27 = Phase13
    RedSegment28 = Phase13
    RedSegment29 = Phase13
    RedSegment30 = Phase13
    RedSegment31 = Phase14
    RedSegment32 = Phase14
    RedSegment33 = Phase14
    RedSegment34 = Phase14
    RedSegment35 = Phase14
    
    RETURN
    
    '*******************************************************
    'Monochromatic Green gradient
    '*******************************************************
    MonoGreenGradient:
    
    GreenSegment1 = Phase1
    GreenSegment2 = Phase1
    GreenSegment3 = Phase1
    GreenSegment4 = Phase1
    GreenSegment5 = Phase1
    GreenSegment6 = Phase1
    GreenSegment7 = Phase1
    GreenSegment8 = Phase1
    GreenSegment9 = Phase1
    GreenSegment10 = Phase1
    GreenSegment11 = Phase1
    GreenSegment12 = Phase1
    GreenSegment13 = Phase1
    GreenSegment14 = Phase1
    GreenSegment15 = Phase1
    GreenSegment16 = Phase1
    GreenSegment17 = Phase1
    GreenSegment18 = Phase1
    GreenSegment19 = Phase1
    GreenSegment20 = Phase1
    GreenSegment21 = Phase1
    GreenSegment22 = Phase1
    GreenSegment23 = Phase1
    GreenSegment24 = Phase1
    GreenSegment25 = Phase1
    GreenSegment26 = Phase1
    GreenSegment27 = Phase1
    GreenSegment28 = Phase1
    GreenSegment29 = Phase1
    GreenSegment30 = Phase1
    GreenSegment31 = Phase1
    GreenSegment32 = Phase1
    GreenSegment33 = Phase1
    GreenSegment34 = Phase1
    GreenSegment35 = Phase1
    
    RETURN
    
    '*******************************************************
    'Monochromatic Red gradient
    '*******************************************************
    MonoRedGradient:
    
    RedSegment1 = Phase1
    RedSegment2 = Phase1
    RedSegment3 = Phase1
    RedSegment4 = Phase1
    RedSegment5 = Phase1
    RedSegment6 = Phase1
    RedSegment7 = Phase1
    RedSegment8 = Phase1
    RedSegment9 = Phase1
    RedSegment10 = Phase1
    RedSegment11 = Phase1
    RedSegment12 = Phase1
    RedSegment13 = Phase1
    RedSegment14 = Phase1
    RedSegment15 = Phase1
    RedSegment16 = Phase1
    RedSegment17 = Phase1
    RedSegment18 = Phase1
    RedSegment19 = Phase1
    RedSegment20 = Phase1
    RedSegment21 = Phase1
    RedSegment22 = Phase1
    RedSegment23 = Phase1
    RedSegment24 = Phase1
    RedSegment25 = Phase1
    RedSegment26 = Phase1
    RedSegment27 = Phase1
    RedSegment28 = Phase1
    RedSegment29 = Phase1
    RedSegment30 = Phase1
    RedSegment31 = Phase1
    RedSegment32 = Phase1
    RedSegment33 = Phase1
    RedSegment34 = Phase1
    RedSegment35 = Phase1
    
    RETURN
    
    '*******************************************************
    'Monochromatic Red gradient antiphase
    '*******************************************************
    MonoRedAntiGradient:
    
    RedSegment1 = Phase9
    RedSegment2 = Phase9
    RedSegment3 = Phase9
    RedSegment4 = Phase9
    RedSegment5 = Phase9
    RedSegment6 = Phase9
    RedSegment7 = Phase9
    RedSegment8 = Phase9
    RedSegment9 = Phase9
    RedSegment10 = Phase9
    RedSegment11 = Phase9
    RedSegment12 = Phase9
    RedSegment13 = Phase9
    RedSegment14 = Phase9
    RedSegment15 = Phase9
    RedSegment16 = Phase9
    RedSegment17 = Phase9
    RedSegment18 = Phase9
    RedSegment19 = Phase9
    RedSegment20 = Phase9
    RedSegment21 = Phase9
    RedSegment22 = Phase9
    RedSegment23 = Phase9
    RedSegment24 = Phase9
    RedSegment25 = Phase9
    RedSegment26 = Phase9
    RedSegment27 = Phase9
    RedSegment28 = Phase9
    RedSegment29 = Phase9
    RedSegment30 = Phase9
    RedSegment31 = Phase9
    RedSegment32 = Phase9
    RedSegment33 = Phase9
    RedSegment34 = Phase9
    RedSegment35 = Phase9
    
    RETURN
    
    '*******************************************************
    'Button Interrupt Handler
    '*******************************************************
    ButtonInterrupt:
    
    @ INT_DISABLE  INT_INT ; disable Button interrupts
    
    GOSUB TurnAllOff
    GOSUB DisplayLoop
    
    REPEAT
        PAUSE 100
        ButtonCounter = ButtonCounter + 1
    UNTIL PushButton = 1 OR ButtonCounter = 10
    
    IF ButtonCounter >= 10 THEN
        StoredAnimationSpeed = StoredAnimationSpeed + 1
        IF StoredAnimationSpeed > 12 THEN StoredAnimationSpeed = 0
        WRITE 1, StoredAnimationSpeed
    ELSE
        AnimationStyle = AnimationStyle + 1
        IF AnimationStyle > AnimationNumber THEN AnimationStyle = 0
        WRITE 0, AnimationStyle
    ENDIF
    
    ButtonCounter = 0
    
    SpeedCounter = 255
    Gosub AnimationUpdate
    
    @ INT_ENABLE  INT_INT ; enable Button interrupts
    
    @ INT_RETURN
    
    END
    Last edited by aberco; - 4th September 2011 at 20:35.

  11. #11
    Join Date
    Dec 2007
    Location
    Paris
    Posts
    101


    Did you find this post helpful? Yes | No

    Default Re: Change variable allocation to save code space

    And... I have missed BobK's comment. Using the 16F1847 would be the best solution... however I do not have PBP3 yet. I will keep that in mind though, as I may need to expand the project to drive 2 more LED boards from the same microcontroller (in order to keep the animation sequence in sync).

  12. #12
    Join Date
    Mar 2006
    Location
    China
    Posts
    266


    Did you find this post helpful? Yes | No

    Default Re: Change variable allocation to save code space

    And when it comes to EEprom I did not say you should put it on the already made PCB. I said solder it straight onto the top of the PIC. If you have pins available on the PIC it just takes a steady hand and some time.

Posting Permissions

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