The Best Solution


Closed Thread
Results 1 to 18 of 18

Hybrid View

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


    Did you find this post helpful? Yes | No

    Default

    Yup but this should return a syntax or modifier error. Summe_alarm.0[temp]=x should cure the problem
    Steve

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

  2. #2
    skimask's Avatar
    skimask Guest


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by mister_e View Post
    Summe_alarm.0[temp]=x
    DOH! I just woke up, that's my excuse and I'm sticking to it.

  3. #3


    Did you find this post helpful? Yes | No

    Default

    Thank you for the very good solution !
    Another Question :-)
    Why I need Zero for : Summe_Alarm.0[Temp] and why not just
    Summe_Alarm.[Temp] ?
    I know that I receive a syntax but I dont understand what is the reason for use Zero !

    Regard Pesti
    Last edited by Pesticida; - 26th May 2007 at 21:00.

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


    Did you find this post helpful? Yes | No

    Default

    kind of fussy writing stuff i guess.

    further reference:
    http://www.picbasic.co.uk/forum/showthread.php?t=544
    Steve

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

  5. #5


    Did you find this post helpful? Yes | No

    Default

    Thank you Mister.

    Regard Pesti

  6. #6
    T.Jackson's Avatar
    T.Jackson Guest


    Did you find this post helpful? Yes | No

    Post

    I think your original code would work marginally faster. However, it would also consume much more code space. So that's the compromise I guess. Out of interest, (DO's & Whiles) are significantly much faster than (For Nexts) in Visual Basic.

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


    Did you find this post helpful? Yes | No

    Default

    This has picked my curiosity, so here's a little benchmark test
    IF-THEN-ELSE: 432 WORDS, 1608 UsEC
    FOR-TO-NEXT: 103 WORDS, 2241 UsEC
    REPEAT - UNTIL: 99 WORDS, 2200 UsEC
    WHILE - WEND: 101 WORDS, 2225 UsEC
    Interesting eh!

    and the code to evaluate it, Darrel may recognize some of his tricks
    Code:
    <font color="#000000">        @   __CONFIG _XT_OSC &amp; _LVP_OFF
    
        <font color="#000080">DEFINE </font>HSER_RCSTA 90h <font color="#008000">' Enable serial port &amp; continuous receive
        </font><font color="#000080">DEFINE </font>HSER_TXSTA 24h <font color="#008000">' Enable transmit, BRGH = 1
        </font><font color="#000080">DEFINE </font>HSER_SPBRG 25  <font color="#008000">' 9600 Baud @ 4MHz, 0.16%
    
        </font>@TMR1=TMR1L
        TMR1    <font color="#000080">VAR WORD </font>EXT
        T1CON = 0
    
        ML_Value        <font color="#000080">VAR BYTE</font>[8]
        Summe_Alarm     <font color="#000080">VAR BYTE
        </font>TEMP            <font color="#000080">VAR BYTE
        </font>ADDR            <font color="#000080">VAR WORD
        </font>TWOCHAR         <font color="#000080">VAR WORD
        </font>CHAR            <font color="#000080">VAR BYTE
        </font>size <font color="#000080">VAR WORD
    
        GOTO </font>START        
    
    <font color="#000080">ASM
    SIZESTART macro
        MOVE?CT 0,T1CON,TMR1ON              </font><font color="#008000">; Stop timer
        </font><font color="#000080">MOVE?CW 0,TMR1                      </font><font color="#008000">; clear Timer value
    </font><font color="#000080">BLOCKSTART = $                          </font><font color="#008000">; set CodeBlock Start address
        </font><font color="#000080">MOVE?CT 1,T1CON,TMR1ON              </font><font color="#008000">; start Timer
        </font><font color="#000080">ENDM
    
    SIZEEND MACRO BLOCKNAME
        MOVE?CT 0, T1CON,TMR1ON             </font><font color="#008000">; stop timer
        </font><font color="#000080">MOVE?CW ($ - BLOCKSTART - 2), _size </font><font color="#008000">; calculate code block size
                                            ; remove 2 word for timerstart/stop
        </font><font color="#000080">LOCAL STRING,JUMPSTRING
        GOTO JUMPSTRING
    STRING    DA  BLOCKNAME,0               </font><font color="#008000">; store codeblock name
    </font><font color="#000080">JUMPSTRING
        CHK?RP _ADDR
        MOVE?CW STRING,_ADDR                </font><font color="#008000">; get string sddress
        </font><font color="#000080">L?CALL _DisplayResult               </font><font color="#008000">; show results via serial comm
        </font><font color="#000080">endm
    ENDASM
    
    </font>START:
    <font color="#000080">@    SIZESTART
        IF </font>(ML_Value[0] &lt;= $5A) <font color="#000080">OR </font>(ML_Value[0] =&gt; $82) <font color="#000080">THEN </font>Summe_Alarm.0 = 1
        <font color="#000080">IF </font>(ML_Value[1] &lt;= $5A) <font color="#000080">OR </font>(ML_Value[1] =&gt; $82) <font color="#000080">THEN </font>Summe_Alarm.1 = 1
        <font color="#000080">IF </font>(ML_Value[2] &lt;= $5A) <font color="#000080">OR </font>(ML_Value[2] =&gt; $82) <font color="#000080">THEN </font>Summe_Alarm.2 = 1
        <font color="#000080">IF </font>(ML_Value[3] &lt;= $5A) <font color="#000080">OR </font>(ML_Value[3] =&gt; $82) <font color="#000080">THEN </font>Summe_Alarm.3 = 1
        <font color="#000080">IF </font>(ML_Value[4] &lt;= $5A) <font color="#000080">OR </font>(ML_Value[4] =&gt; $82) <font color="#000080">THEN </font>Summe_Alarm.4 = 1
        <font color="#000080">IF </font>(ML_Value[5] &lt;= $5A) <font color="#000080">OR </font>(ML_Value[5] =&gt; $82) <font color="#000080">THEN </font>Summe_Alarm.5 = 1
        <font color="#000080">IF </font>(ML_Value[6] &lt;= $5A) <font color="#000080">OR </font>(ML_Value[6] =&gt; $82) <font color="#000080">THEN </font>Summe_Alarm.6 = 1
        <font color="#000080">IF </font>(ML_Value[7] &lt;= $5A) <font color="#000080">OR </font>(ML_Value[7] =&gt; $82) <font color="#000080">THEN </font>Summe_Alarm.7 = 1
        
        <font color="#000080">IF </font>(ML_Value[0] &gt; $5A) <font color="#000080">AND </font>(ML_Value[0] &lt; $82) <font color="#000080">THEN </font>Summe_Alarm.0 = 0
        <font color="#000080">IF </font>(ML_Value[1] &gt; $5A) <font color="#000080">AND </font>(ML_Value[1] &lt; $82) <font color="#000080">THEN </font>Summe_Alarm.1 = 0
        <font color="#000080">IF </font>(ML_Value[2] &gt; $5A) <font color="#000080">AND </font>(ML_Value[2] &lt; $82) <font color="#000080">THEN </font>Summe_Alarm.2 = 0
        <font color="#000080">IF </font>(ML_Value[3] &gt; $5A) <font color="#000080">AND </font>(ML_Value[3] &lt; $82) <font color="#000080">THEN </font>Summe_Alarm.3 = 0
        <font color="#000080">IF </font>(ML_Value[4] &gt; $5A) <font color="#000080">AND </font>(ML_Value[4] &lt; $82) <font color="#000080">THEN </font>Summe_Alarm.4 = 0
        <font color="#000080">IF </font>(ML_Value[5] &gt; $5A) <font color="#000080">AND </font>(ML_Value[5] &lt; $82) <font color="#000080">THEN </font>Summe_Alarm.5 = 0
        <font color="#000080">IF </font>(ML_Value[6] &gt; $5A) <font color="#000080">AND </font>(ML_Value[6] &lt; $82) <font color="#000080">THEN </font>Summe_Alarm.6 = 0
        <font color="#000080">IF </font>(ML_Value[7] &gt; $5A) <font color="#000080">AND </font>(ML_Value[7] &lt; $82) <font color="#000080">THEN </font>Summe_Alarm.7 = 0
    <font color="#000080">@   SIZEEND &quot;IF-THEN-ELSE&quot;
    
    @   SIZESTART
        FOR </font>TEMP = 0 <font color="#000080">TO </font>7
            <font color="#000080">IF </font>(ML_Value[TEMP] &lt;= $5A) <font color="#000080">OR </font>(ML_Value[TEMP] =&gt; $82) <font color="#000080">THEN </font>Summe_Alarm.0[TEMP] = 1
            <font color="#000080">IF </font>(ML_Value[TEMP] &gt; $5A) <font color="#000080">AND </font>(ML_Value[TEMP] &lt; $82) <font color="#000080">THEN </font>Summe_Alarm.0[TEMP] = 0
            <font color="#000080">NEXT </font>TEMP
    <font color="#000080">@   SIZEEND &quot;FOR-TO-NEXT&quot;
     
    @   SIZESTART
        </font>TEMP = 0
        <font color="#000080">REPEAT
            IF </font>(ML_Value[TEMP] &lt;= $5A) <font color="#000080">OR </font>(ML_Value[TEMP] =&gt; $82) <font color="#000080">THEN </font>Summe_Alarm.0[TEMP] = 1
            <font color="#000080">IF </font>(ML_Value[TEMP] &gt; $5A) <font color="#000080">AND </font>(ML_Value[TEMP] &lt; $82) <font color="#000080">THEN </font>Summe_Alarm.0[TEMP] = 0
            TEMP=TEMP+1
            <font color="#000080">UNTIL </font>TEMP = 8
    <font color="#000080">@  SIZEEND &quot;REPEAT - UNTIL&quot;
    
    @   SIZESTART
        </font>TEMP = 0
        <font color="#000080">WHILE </font>TEMP!=8
            <font color="#000080">IF </font>(ML_Value[TEMP] &lt;= $5A) <font color="#000080">OR </font>(ML_Value[TEMP] =&gt; $82) <font color="#000080">THEN </font>Summe_Alarm.0[TEMP] = 1
            <font color="#000080">IF </font>(ML_Value[TEMP] &gt; $5A) <font color="#000080">AND </font>(ML_Value[TEMP] &lt; $82) <font color="#000080">THEN </font>Summe_Alarm.0[TEMP] = 0
            TEMP=TEMP+1
            <font color="#000080">WEND
    @   SIZEEND &quot;WHILE - WEND&quot;
    
    </font>here: <font color="#000080">GOTO </font>here
    
    DisplayResult:
        <font color="#000080">READCODE </font>ADDR, TWOCHAR
        CHAR = TWOCHAR &gt;&gt; 7
            <font color="#000080">IF </font>CHAR =0 <font color="#000080">THEN </font>EndString
            <font color="#000080">HSEROUT</font>[CHAR]
            
        CHAR = TWOCHAR &amp; $7F
            <font color="#000080">IF </font>CHAR = 0 <font color="#000080">THEN </font>EndString
            <font color="#000080">HSEROUT </font>[CHAR]
            
        ADDR=ADDR+1
        <font color="#000080">GOTO </font>DisplayResult
    
        EndString:
        <font color="#000080">HSEROUT </font>[&quot;: &quot;,<font color="#000080">DEC </font>size,&quot; WORDS, &quot;,<font color="#000080">DEC </font>TMR1, &quot; UsEC&quot;,13,10]
        
        <font color="#000080">RETURN           
    
    </font>
    Is it me, or i see some interrogation mark over some head?
    Last edited by mister_e; - 28th May 2007 at 00:00.
    Steve

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

Similar Threads

  1. Strange I2C problem (and solution)
    By brid0030 in forum mel PIC BASIC Pro
    Replies: 2
    Last Post: - 5th December 2008, 19:14
  2. Replies: 6
    Last Post: - 20th September 2008, 12:28
  3. Replies: 7
    Last Post: - 7th February 2008, 09:46
  4. Need PC software solution
    By mister_e in forum Off Topic
    Replies: 9
    Last Post: - 27th November 2005, 02:18
  5. Battery Solution
    By Keith in forum mel PIC BASIC Pro
    Replies: 1
    Last Post: - 22nd July 2005, 06:07

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