Remove Text Formatting
Loading...

+ Reply to Thread
Results 1 to 37 of 37
  1. #1
    Join Date
    Dec 2007
    Posts
    7

    Default picbasic +12c508a+soft_stack error

    Hi
    I wrote a simple basic program for my PIC (12c508A) in a Picbasic Pro compiler
    but I have this error after compilation "unable to fit variable soft_stack"
    please see my program below and tell me the errors as I am beginner in PIC programming .
    Thanks


    lowinput VAR GPIO.0
    overtemprature VAR GPIO.1
    overload VAR GPIO.2
    outputpin VAR GPIO.3
    green VAR GPIO.4
    red VAR GPIO.5
    count1 var byte
    i var byte

    OUTPUT outputpin
    input lowinput
    input overtemprature
    input overload
    OUTPUT green
    OUTPUT red

    while i=0
    if (lowinput=0) and (overload=0) and (overtemprature=0) then

    outputpin =0
    High green
    Pause 500
    Low green
    Pause 500

    ENDIF


    if (lowinput=0) and (overload=1) and (overtemprature=0) then

    while count1<2
    gosub overloadmode
    count1=count1+1
    wend
    outputpin =1

    while count1<7
    gosub overloadmode
    count1=count1+1
    wend

    outputpin =0
    count1=0
    ENDIF

    if (lowinput=1) and (overload=0) and (overtemprature=0) then

    while count1<5
    gosub lowinputmode
    count1=count1+1
    wend
    outputpin =1
    count1=0
    ENDIF
    if (lowinput=0) and (overload=0) and (overtemprature=1) then

    while count1<5
    gosub overtempraturemode
    count1=count1+1
    wend
    outputpin =1
    count1=0
    ENDIF
    if (lowinput=1) and (overload=1) and (overtemprature=0) then

    while count1<5
    gosub overtempraturemode
    count1=count1+1
    wend
    outputpin =1
    count1=0


    endif


    wend


    overloadmode:
    High green
    low red
    Pause 500

    Low green
    high red
    Pause 500
    return

    lowinputmode:
    High green
    low red
    Pause 500

    Low green
    high red
    Pause 500
    return

    overtempraturemode:

    High green
    high red
    Pause 500

    Low green
    low red
    Pause 500

    return

    end

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

    Default

    you may need to move on a bigger RAM PIC such as PIC12C509. 12C508 have 25 bytes of RAM, while 12C509 have 41 + twice the program space size.

    The compiler use between 20 & 22 bytes of RAM itself.. so... no real space for more variables
    Steve

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

  3. #3
    Join Date
    Jul 2003
    Location
    Colorado Springs
    Posts
    4,959

    Default

    A 12F might be a good choice. Cheaper too.

    However, what you have should fit, with a little modification.


    The complex IF statements are creating 3 (T)emp vars, which are word sized. (even though it's only using 1 bit per WORD)
    So it's using 6 bytes that it doesn't really need too.

    If you change all the IF statements to something like this for the first one, I believe it should fit.

    Code:
        ;if (lowinput=0) and (overload=1) and (overtemprature=0) then
        if (lowinput=0) THEN
            if (overload=1) THEN
                if (overtemprature=0) THEN
                    while count1<2
                    gosub overloadmode
                    count1=count1+1
                    wend
                    outputpin =1
                    
                    while count1<7
                    gosub overloadmode
                    count1=count1+1
                    wend
                    
                    outputpin =0
                    count1=0
                ENDIF
            ENDIF
        ENDIF
    hth,
    DT

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

    Default

    i was thinking of a select case and GPIO mask. mmm...

    edit: Seems to work
    Code:
    lowinput VAR GPIO.0
    overtemprature VAR GPIO.1
    overload VAR GPIO.2
    outputpin VAR GPIO.3
    green VAR GPIO.4
    red VAR GPIO.5
    count1 var byte
    Mask var byte
    
    
    OUTPUT outputpin
    input lowinput
    input overtemprature
    input overload
    OUTPUT green
    OUTPUT red
    
    Start:
            mask=GPIO & 7
            select case mask
                    case %000 ;if (lowinput=0) and (overload=0) and (overtemprature=0) then
                        outputpin =0
                        High green
                        Pause 500
                        Low green
                        Pause 500
    
                    case %100 ;if (lowinput=0) and (overload=1) and (overtemprature=0) then
                        while count1<2
                            gosub overloadmode
                            count1=count1+1
                            wend
                        outputpin =1
                        
                        while count1<7
                            gosub overloadmode
                            count1=count1+1
                            wend
                        
                        outputpin =0
                        count1=0
    
                    case %001 ;if (lowinput=1) and (overload=0) and (overtemprature=0) then
                        while count1<5
                            gosub lowinputmode
                            count1=count1+1
                            wend
                        outputpin =1
                        count1=0
                    
                    case %010 ;if (lowinput=0) and (overload=0) and (overtemprature=1) then
                        while count1<5
                            gosub overtempraturemode
                            count1=count1+1
                            wend
                        outputpin =1
                        count1=0
    
                    case %101 ;if (lowinput=1) and (overload=1) and (overtemprature=0) then
                        while count1<5
                            gosub overtempraturemode
                            count1=count1+1
                            wend
                        outputpin =1
                        count1=0
                    end select
    
            goto Start
    
    
    overloadmode:
            High green
            low red
            Pause 500
    
            Low green
            high red
            Pause 500
            return
    
    lowinputmode:
            High green
            low red
            Pause 500
            
            Low green
            high red
            Pause 500
            return
    
    overtempraturemode:
            
            High green
            high red
            Pause 500
            
            Low green
            low red
            Pause 500
            
            return
    
            end
    Last edited by mister_e; - 16th December 2007 at 21:10.
    Steve

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

  5. #5
    Join Date
    Aug 2006
    Location
    Look, behind you.
    Posts
    2,810

    Default

    Quote Originally Posted by mister_e View Post
    . . . .

    The compiler use between 20 & 22 bytes of RAM itself.. so... no real space for more variables
    Hello Mister_E
    Could you please explain? This statement appears to me to mean PIC BASIC PRO is an intrepreted code, if not why would the compiler require any of the PIC's ram?
    Thank You
    JS
    If you do not believe in MAGIC, Consider how currency has value simply by printing it, and is then traded for real assets.
    .
    There simply is no "Happy Spam" If you do it you will disappear from this forum.

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

    Default

    Yeah but the library/compiler need to reserve some variable to work to not interfer with your code... euh.. that's my understanding

    support for 12 bit core is limited, and the real explanation can be found at the bottom of the folowiing page
    http://www.melabs.com/support/12-bit.htm

    so why 20-22... i don't know, seems hungry to me.. but, you have to deal with it.

    We already heard something like that for 10F and bring some weird/nasty/dangerous/clever alternate solutions, some who remind...
    http://www.picbasic.co.uk/forum/showthread.php?t=4789&

    HTH
    Last edited by mister_e; - 16th December 2007 at 23:41.
    Steve

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

  7. #7
    Join Date
    Jul 2003
    Location
    Colorado Springs
    Posts
    4,959

    Default

    After converting all the IF statements like I suggested above, it did fit in RAM,
    and it compiled to 313 WORDS.

    mister_e,
    Yours fit in RAM too, and compiled to 295 WORDS. (unexpected for Select Case)

    You know what that means RIGHT?
    Yup, this ain't over yet!

    172 WORDS
    Code:
    @ DEVICE WDT_OFF
    DEFINE NO_CLRWDT 1 ' Don't kick the Dog 
    
    lowinput       VAR GPIO.0
    overtemprature VAR GPIO.1
    overload       VAR GPIO.2
    outputpin      VAR GPIO.3
    green          VAR GPIO.4
    red            VAR GPIO.5
    FlashCount     var byte
    FlashPattern   var byte
    
    TRISIO = %000111
    
    Start:
        If (lowinput=0) then
            IF (overload=0) then             ; lowinput, overload, overtemprature
                if (overtemprature=0) then                      ; 000
                    outputpin = 0
                    FlashCount = 1 
                    FlashPattern = %0001  ; ModeOK
                    GOSUB FlashLEDs
                else                                            ; 001
                    FlashCount = 5
                    FlashPattern = %0011  ; overtempraturemode
                    gosub FlashLEDs
                    outputpin = 1
                endif
            else                                                ; 010
                if (overtemprature=0) then           
                    FlashCount = 2
                    FlashPattern = %1001  ; overloadmode
                    gosub FlashLEDs
                    outputpin =1
                    
                    FlashCount = 7
                    gosub FlashLEDs
                    outputpin =0
                else                                            ; 011
                    ; --- Action undefined ---
                endif
            endif
        else
            if (overload=0) then                     
                if (overtemprature=0) then                      ; 100
                    FlashCount = 5
                    FlashPattern = %1001  ; lowinputmode
                    gosub FlashLEDs
                    outputpin =1
                else                                            ; 101
                    ; --- Action undefined ---
                endif
            else                                                ; 110
                if (overtemprature=0) then           
                    FlashCount = 5
                    FlashPattern = %0011  ; overtempraturemode
                    gosub FlashLEDs
                    outputpin =1
                else                                            ; 111
                    ; --- Action undefined ---
                endif
            endif
        endif
    GOTO Start
    
    FlashLEDs:
        REPEAT
             green = FlashPattern.0
             red   = FlashPattern.1
             Pause 500
    
             green = FlashPattern.2
             red   = FlashPattern.3
             Pause 500
             FlashCount = FlashCount - 1
        UNTIL (FlashCount = 0)
    return
    However, omid_juve,

    There are 3 states that are not accounted for

    lowinput=0 overload=1 overtemprature=1
    lowinput=1 overload=0 overtemprature=0
    lowinput=1 overload=1 overtemprature=1

    It may be intentional. Maybe they aren't needed. But normally, unchecked states will cause havoc in your program.

    If we knew what was supposed to happen in those states, I think mister_e ..., uh I mean, I could probably reduce it further.
    DT

  8. #8
    Join Date
    Dec 2007
    Posts
    7

    Default

    it a program for 24v to 12v converter that has 3 input 1.over temperature 2.low input 3.overload and we have 3 output that 2 of them is just indicator and one (outputpin)
    is the output for controlling the output voltage according to the situation of inputs.
    and just the modes that you saw in the program can occur .
    thanks for all of your help. my problem is solved .

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

    Default

    You know what that means RIGHT?
    Yup, this ain't over yet!
    yup.. sounds like a challenge... 100% PBP??? Maybe doable... scratch, scratch...mmm...
    Steve

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

  10. #10
    Join Date
    Jul 2003
    Location
    Colorado Springs
    Posts
    4,959

    Default

    12C508A's bad enough,
    you want 100% PBP??? too?

    Did you know it doesn't even have an overflow flag on timer0?
    I didn't, Oi vey!

    I had so much fun this time last year with what ended up as the 12-byte cylon scanner,
    perhaps I'm a bit over zealous.

    The OP is satisfied, and probably wouldn't use it anyways,
    So even if the program size was only 83 words, like I have it now,
    It'll never be used.

    We need a real Optimization contest.
    They're just too fun.
    <br>
    DT

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

    Default

    yup, no eeprom either... so nothing interesting. Think it's like a 16F84A, 16C54... but in 8 pin package

    There's always place for an optimization contest, next time, no rules (pic, language etc etc )... agreed?
    Steve

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

  12. #12
    skimask's Avatar
    skimask Guest

    Default

    Quote Originally Posted by mister_e View Post
    yup, no eeprom either... so nothing interesting. Think it's like a 16F84A, 16C54... but in 8 pin package
    There's always place for an optimization contest, next time, no rules (pic, language etc etc )... agreed?
    Make it tough...use a 10F200...no SOT->DIP adapters allowed, only hand soldering, dead bug style. In fact, no soldering, hand wrap wires around the legs....
    and no power supply, hand crank a motor to charge up a cap...

  13. #13
    Join Date
    Jul 2003
    Posts
    2,405

    Default

    Any chance we can see that 12-byte cylon scanner?
    Regards,

    -Bruce
    tech at rentron.com
    http://www.rentron.com

  14. #14
    Join Date
    Jul 2003
    Location
    Colorado Springs
    Posts
    4,959

    Default

    Sure,

    The 12-byte version is toward the end on page 2.
    http://www.sfcompiler.co.uk/forum/viewtopic.php?t=72

    Edit: Hey, you were there to.
    <br>
    DT

  15. #15
    Join Date
    Jul 2003
    Posts
    2,405

    Default

    Yipes I totally forgot that one. That was way interesting and the end result was really creative.

    Nice work DT..;o}

    Tim B and I got into one of these a long time back, and here's one he came up with.

    Can we beat this without EEPROM?

    Standard cyclone thingie moving the LED back & forth with ~1S delay periods.
    Code:
      	list      p=16F628A
    	#include "P16F628A.inc"
    	errorlevel  -302        ; suppress message 302 from list file
    	__CONFIG _CP_OFF & _BODEN_ON & _MCLRE_ON & _WDT_ON & _PWRTE_ON & _LVP_OFF & _INTOSC_OSC_NOCLKOUT
    
    	movlw	0x01
    	movwf	PORTB	     ; Set Portb,0
    	bsf	STATUS,RP0   ; Bank 1
    	clrf	TRISB	     ; RB all outputs
    	bcf	OPTION_REG,0 ; 1:64 prescaler to WDT
    	bcf	STATUS,RP0   ; Bank 0
    
    Left
    	sleep		    ; go to sleep for 64 * 18mS ~1 second
    	rlf	PORTB,F     ; rotate bit across portb from lsb to msb
    	btfss	PORTB,7     ; jump to Right after Portb,7 = 1
    	goto	Left
    	
    Right
    	sleep		    ; go to sleep for 64 * 18mS ~1 second
    	rrf	PORTB,F     ; rotate bit across Portb from msb to lsb
    	btfss	PORTB,0     ; jump back to left after Portb,0 = 1
    	goto	Right       ; loop until Portb,0 = 1
    	goto	Left        ; now rotate back to the left.
    	
        End
    Regards,

    -Bruce
    tech at rentron.com
    http://www.rentron.com

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

    Default

    seems to be hardly optimized to me

    food for thought... let's see...
    Steve

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

  17. #17
    Join Date
    Jul 2003
    Location
    Colorado Springs
    Posts
    4,959

    Default

    Tim's compiled to 15 words.

    Here's 13 ... &nbsp; Note: LED's go to VDD
    Code:
        list      p=16F628A
        #include "P16F628A.inc"
        errorlevel  -302        ; suppress message 302 from list file
        __CONFIG _CP_OFF & _BODEN_ON & _MCLRE_ON & _WDT_ON & _PWRTE_ON & _LVP_OFF & _INTOSC_OSC_NOCLKOUT
    
        clrf    PORTB         ; PORTB all 0's
        bsf	    STATUS,RP0    ; Bank 1
        bcf	    OPTION_REG, 0 ; 1:64 prescaler to WDT
        bcf     TRISB, 0      ; set RB0 to output
        bsf     STATUS, C     ; set carry flag for rotation
    Loop
        btfss   TMR2, 3       ; switch Left/Right every 8 times
        rlf	    TRISB,F       ; rotate Left across TRISB
        btfsc   TMR2, 3
        rrf     TRISB,F       ; rotate Right across TRISB
        btfsc   STATUS, C     ; No sleep if output rotated into carry
        sleep                 ; nite nite
        incf    TMR2          ; Timer2 used for it's 00 value on reset.
        goto    Loop          ; Repeat
    EDIT: Rats!
    While it works in MPSIM, it's not going to do it on the real thing.
    Time for a breadboard.

    <br>
    DT

  18. #18
    Join Date
    Jul 2003
    Location
    Colorado Springs
    Posts
    4,959

    Default

    OK, ignore the last one. That's what I get for using a simulator.

    This is 14 WORDS, 1 less than Tim's.
    At least it beats him

    Code:
        list      p=16F88
        #include "P16F88.inc"
        errorlevel  -302        ; suppress message 302 from list file
        __CONFIG  _CONFIG1, _XT_OSC & _CP_OFF & _BODEN_ON & _MCLR_ON & _WDT_ON & _PWRTE_ON & _LVP_OFF
    
        clrf    PORTB         ; PORTB all 0's
        bsf     STATUS,RP0    ; Bank 1
        bcf     OPTION_REG, 0 ; 1:64 prescaler to WDT
        bcf     TRISB, 0      ; RB0 output
    Loop
        sleep                 ; nite nite
    
        btfss   SPBRG,0       ; SPBRG used for it's 00 reset value   
        rlf     TRISB,F       ; rotate Left across TRISB
        btfsc   SPBRG,0
        rrf     TRISB,F       ; rotate Right across TRISB
        
        btfss   TRISB, 7      ; At LED7? - go the other way
        incf    SPBRG,F
        btfss   TRISB, 0      ; At LED0? - go the other way
        incf    SPBRG,F 
        
        goto    Loop          ; Repeat
    LED's go to VDD.
    Tested, working on 16F88, should be the same (except configs) on 16F628A.
    <br>
    DT

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

    Default

    yup.. hence why i never trust sim...
    Steve

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

  20. #20
    Join Date
    Jul 2003
    Posts
    2,405

    Default

    Nice work DT.

    Here's one at 13 words.
    Code:
      list      p=16F628A
      #include "P16F628A.inc"
      errorlevel  -302
      __CONFIG _CP_OFF & _BODEN_ON & _MCLRE_OFF & _WDT_ON & _PWRTE_ON & _LVP_OFF & _INTOSC_OSC_NOCLKOUT
    
       clrf  PORTB        ; clear port
       bsf   STATUS,RP0   ; Bank 1
       bcf   TRISB,0      ; RB0 = output
       bcf   OPTION_REG,0 ; 1:64 prescaler to WDT
    
    Left
       sleep             ; go to sleep for 64 * 18mS ~1 second
       rlf   TRISB,F     ; rotate bit across portb from lsb to msb
       btfsc TRISB,7    
       goto  Left
    	
    Right
       sleep          ; go to sleep for 64 * 18mS ~1 second
       rrf   TRISB,F  ; rotate bit across Portb from msb to lsb
       btfsc TRISB,0
       goto  Right
       goto  Left     ; now rotate back to the left.
    	
       End
    Last edited by Bruce; - 19th December 2007 at 19:17.
    Regards,

    -Bruce
    tech at rentron.com
    http://www.rentron.com

  21. #21
    Join Date
    Jul 2003
    Location
    Colorado Springs
    Posts
    4,959

    Default

    Oh Yeah! Very nice Bruce.

    Now that's going to be hard to beat.
    If you don't hear from me for a month.
    You'll know what happened.
    DT

  22. #22
    skimask's Avatar
    skimask Guest

    Default

    Quote Originally Posted by Darrel Taylor View Post
    Oh Yeah! Very nice Bruce.

    Now that's going to be hard to beat.
    If you don't hear from me for a month.
    You'll know what happened.
    I just checked on my '628A on my breadboard...about a ba-zillion times...
    I set up code/hardware to do nothing but RESET, and put Port B onto a bank of LEDs, Vdd on the other side of the LED.
    EACH time, Port B came up ZERO...no LEDs lit up, until I set a TRIS bit for output.
    So, my submission...
    Coming in at 12 bytes...

    Code:
      list      p=16F628A
      #include "P16F628A.inc"
      errorlevel  -302
      __CONFIG _CP_OFF & _BODEN_ON & _MCLRE_OFF & _WDT_ON & _PWRTE_ON & _LVP_OFF & _INTOSC_OSC_NOCLKOUT
    
    ;   clrf  PORTB        ; clear port - not required on my breadboard, might be different on others
       bsf   STATUS,RP0   ; Bank 1
       bcf   TRISB,0      ; RB0 = output
       bcf   OPTION_REG,0 ; 1:64 prescaler to WDT
    
    Left
       sleep             ; go to sleep for 64 * 18mS ~1 second
       rlf   TRISB,F     ; rotate bit across portb from lsb to msb
       btfsc TRISB,7    
       goto  Left
    	
    Right
       sleep          ; go to sleep for 64 * 18mS ~1 second
       rrf   TRISB,F  ; rotate bit across Portb from msb to lsb
       btfsc TRISB,0
       goto  Right
       goto  Left     ; now rotate back to the left.
    	
       End

    Somebody else check this out and see what happens.
    As I stated, maybe it's my breadboard, maybe it's my 628A (I've only got 1 left), maybe it's the rise time on my PSU.

    EDIT: Datasheet says that the port registers come up in an unknown state. Apparently, in this case, I now know my state...
    Last edited by skimask; - 19th December 2007 at 21:23.

  23. #23
    Join Date
    Jul 2003
    Posts
    2,405

    Default

    It might work on one series, but I wouldn't count on it as being reliable across the board.
    I have seen various PICs come up with totally random values in port latches at POR, so
    you really do need to clear portb latches first if it's to be reliable.
    Regards,

    -Bruce
    tech at rentron.com
    http://www.rentron.com

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

    Default

    i'm thinking of something using interrupt.. not sure if it could reduce things to 8-10 words... mmm..
    Steve

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

  25. #25
    Join Date
    Jul 2003
    Posts
    2,405

    Default

    I had considered that approach too, but more than half of your code space (or more) would
    be eaten up with interrupt configuration setup.

    Making it "reliable" with less than 13 words is going to be a real task.
    Regards,

    -Bruce
    tech at rentron.com
    http://www.rentron.com

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

    Default

    yup, but where is it stated that it has to be reliable, where it is stated that we need to use the same PIC and hardware ?

    i still believe it's doable... but with some hair lost
    Steve

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

  27. #27
    skimask's Avatar
    skimask Guest

    Default

    Quote Originally Posted by Bruce View Post
    It might work on one series, but I wouldn't count on it as being reliable across the board.
    I have seen various PICs come up with totally random values in port latches at POR, so
    you really do need to clear portb latches first if it's to be reliable.
    I don't doubt that at all...
    I just checked the CARRY bit, datasheet says unknown on POR, mine come's up cleared every time (at least every time I've check anyways). That shoots that idea down...

  28. #28
    Join Date
    Jul 2003
    Location
    Colorado Springs
    Posts
    4,959

    Default

    Quote Originally Posted by mister_e View Post
    yup, but where is it stated that it has to be reliable?
    I think that's a given. It has to work when you turn on the power.
    As for the rest of the rules, well, I'm assuming No EEPROM is the only one. Edit: with a 16F628A
    i still believe it's doable... but with some hair lost
    I'm starting to believe NO.
    But I haven't given up yet.

    I've got 3 completely different versions at 13 words now.
    1 using external circuitry to TMR0
    1 using external circuitry to a comparator
    and another that simply shaves a word off my 14 word program. (wish I'd done that to begin with)

    It seems that no matter what you do to save a word, you end up having to add something to make it work.

    I'm sure getting some "Quality Time" in with the datasheets though. All kinds of stuff I didn't know before.
    <br>
    Last edited by Darrel Taylor; - 21st December 2007 at 02:24. Reason: 628a
    DT

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

    Default

    yup all good points.. the only thing i've never dare to mess with is the stack overflow behaviour and ORG... 8 bit stack seems nice... but not sure how bad/good it behave...mmm

    interesting how a led chaser can be a food for thought
    Last edited by mister_e; - 21st December 2007 at 02:21.
    Steve

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

  30. #30
    skimask's Avatar
    skimask Guest

    Default

    Quote Originally Posted by mister_e View Post
    yup all good points.. the only thing i've never dare to mess with is the stack overflow behaviour and ORG... 8 bit stack seems nice... but not sure how bad/good it behave...mmm
    interesting how a led chaser can be a food for thought
    Something tells me that somebody is about to break the law...
    The law of diminishing returns!

    Does this 'thing' have to have 8 LEDs? Or can it have 16 LEDs?
    I'm thinking something along the lines of 2 LEDs per pin, back-to-back, with the common for all running to another pin...don't know what I'm thinking yet...

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

    Default

    Yeah maybe breaking the law, but as i said, i didn't test it...it just looks good in my mind... 8 deep level stack, 8 leds... mmm
    Steve

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

  32. #32
    skimask's Avatar
    skimask Guest

    Default

    Quote Originally Posted by mister_e View Post
    Yeah maybe breaking the law, but as i said, i didn't test it...it just looks good in my mind... 8 deep level stack, 8 leds... mmm
    Great...now you got me thinking...and I was about ready to sleep...
    Flip a bit...recursive call's without return's, slide a bit over...wash/lather/rinse/repeat/STACK OVERFLOW...flip a bit...repeat...

  33. #33
    Join Date
    Jul 2003
    Location
    Colorado Springs
    Posts
    4,959

    Cool

    Ladies and Gentlemen!

    Please direct your attention to the Center Ring ....

    12 WORDs
    Code:
     	list      p=16F628A
    	#include "P16F628A.inc"
    	errorlevel  -302        ; suppress message 302 from list file
    	__CONFIG _CP_OFF & _BODEN_ON & _MCLRE_ON & _WDT_ON & _PWRTE_ON & _LVP_OFF & _INTOSC_OSC_NOCLKOUT
    
    Init
        clrf    PORTB         ; PORTB all 0's
        rlf     STATUS, F     ; sets Bank1 and clears carry
        bcf     OPTION_REG, 2 ; 1:8 prescaler to WDT
        comf    SPBRG,F       ; Make SPBRG all 1's
    Loop
        btfsc   STATUS,C      ; no sleep if rotated into carry
        sleep                 
    
        rlf     SPBRG,F       ; rotate SPBRG left msb to carry
        rrf     PR2, F        ; rotate carry into PR2, lsb to carry
        movf    SPBRG, W      ; put SPBRG into W reg
        andwf   PR2, W        ; and it with PR2
        movwf   TRISB         ; result goes to TRISB
    
        goto    Loop          ; Repeat
    Bwwaaa Haaa Haaa!

    Added:
    <script language="javascript" src="http://www.pbpgroup.com/files/CylonRotate.js"></script><br>
    DT

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

    Default

    Woohoo, now if we see this code example somewhere, we will know where it come from PR2, SPBRG... euh in a light 'chaser' ,deuh, doh... hein???

    Nice one.... smell of the burned brain-cells, but nice ;o}
    Last edited by mister_e; - 22nd December 2007 at 13:20.
    Steve

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

  35. #35
    Join Date
    Jul 2003
    Posts
    2,405

    Default

    Well, that's going to be tough to beat. Nice work Darrel.

    Interesting side note: Using your rlf STATUS,F approach reduced my 13 word version to
    only 12 words..;o}
    Code:
      	list      p=16F628A
    	#include <P16F628A.inc>
    	errorlevel  -302    ; suppress message 302 from list file
    	__CONFIG _CP_OFF & _BODEN_ON & _MCLRE_OFF & _WDT_ON & _PWRTE_ON & _LVP_OFF & _INTOSC_OSC_NOCLKOUT
    
    	clrf  PORTB	   ; clear port
    	rlf   STATUS,F     ; Bank1, clear carry for 1st rotate
    	bcf   OPTION_REG,2 ; 1:8 prescaler to WDT
    
    Left
    	sleep              ; go to sleep for ~1 second
    	rlf	TRISB,F    ; rotate 0 from carry into lsb, then left across trisb
    	btfsc	TRISB,7    ; jump to Right once trisb,7 = 0
    	goto	Left
    	
    Right
    	sleep              ; go to sleep for ~1 second
    	rrf	TRISB,F    ; rotate bit right across trisb
    	btfsc	TRISB,0    ; jump to left once trisb,0 = 0
    	
    	goto	Right       ; loop until trisb,0 = 0
    	goto	Left        ; now rotate back to the left
    
            end
    Regards,

    -Bruce
    tech at rentron.com
    http://www.rentron.com

  36. #36
    Join Date
    Jul 2003
    Location
    Colorado Springs
    Posts
    4,959

    Default

    OMG! How HORRIBLE!

    That means yours doesn't pause at each end like mine.
    Which makes your 12, better than my 12.



    Actually, it's awesome,
    I'm crying because now I have to spend the next week trying to beat it.
    <br>
    DT

  37. #37
    Join Date
    Jul 2003
    Posts
    2,405

    Default

    Oh I wouldn't call it better since your version is WAY more creative, and your nifty rotate STATUS thing was the only reason mine was reduced.

    Man that was some clever & creative problem solving, and that's really what it's all about...;o}
    Regards,

    -Bruce
    tech at rentron.com
    http://www.rentron.com

Similar Threads

  1. Loop with two motor and 2 sensors
    By MrRoboto in forum mel PIC BASIC
    Replies: 4
    Last Post: - 9th December 2008, 00:40
  2. Optimizing DIV
    By skimask in forum mel PIC BASIC Pro
    Replies: 41
    Last Post: - 22nd September 2008, 04:58
  3. pbp245 compliation error
    By Woodzy in forum mel PIC BASIC Pro
    Replies: 9
    Last Post: - 25th July 2006, 05:59
  4. 16F88 Compile error
    By Toley00 in forum mel PIC BASIC Pro
    Replies: 6
    Last Post: - 2nd November 2005, 01:22
  5. Compiler/Assembler Error
    By LT_Pic in forum General
    Replies: 7
    Last Post: - 21st July 2005, 09:47

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