Multiple if then optimization


Closed Thread
Results 1 to 36 of 36

Hybrid View

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


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by skimask View Post
    It's monday! What'd you expect?
    Wait 'till DT comes online...
    Figure maybe down to...what...25 words total?
    Thanks for the vote of confidence ski.

    But sadly, all I could muster was a slim 335 words

    Code:
    <font color="#000000"><b>CMCON </b>= <font color="#800000"><b>7                </b></font><font color="#0000FF"><b><i>' Disable Comparators
    
    </i></b></font><font color="#008000"><b>DEFINE </b></font><b>DEBUG_BAUD </b><font color="#800000"><b>2400   </b></font><font color="#0000FF"><b><i>'Debug baud rate 
    </i></b></font><font color="#008000"><b>DEFINE </b></font><b>DEBUGIN_REG PORTB </b><font color="#0000FF"><b><i>'Debugin pin port 
    </i></b></font><font color="#008000"><b>DEFINE </b></font><b>DEBUGIN_BIT </b><font color="#800000"><b>0     </b></font><font color="#0000FF"><b><i>'Debugin pin bit 
    </i></b></font><font color="#008000"><b>DEFINE </b></font><b>DEBUGIN_MODE </b><font color="#800000"><b>1    </b></font><font color="#0000FF"><b><i>'Debugin mode: 0 = True, 1 = Inverted 
    
    </i></b></font><b>Uin       </b><font color="#008000"><b>VAR WORD
    </b></font><b>B0        </b><font color="#008000"><b>VAR BYTE 
    </b></font><b>BarCount  </b><font color="#008000"><b>VAR BYTE
    </b></font><b>BarValue  </b><font color="#008000"><b>VAR WORD
    </b></font><b>MsgAddr   </b><font color="#008000"><b>VAR WORD
    </b></font><b>Carry     </b><font color="#008000"><b>VAR </b></font><b>STATUS</b>.<font color="#800000"><b>0        </b></font><font color="#0000FF"><b><i>; Hardware carry flag
    
    </i></b></font><font color="#008000"><b>GOTO </b></font><b>Main                     </b><font color="#0000FF"><b><i>; Jump over data
    ;=============================================================================
     </i></b></font><b>BarSteps</b>:  <b>POKECODE   </b><font color="#800000"><b>10</b></font>,<font color="#800000"><b>15</b></font>,<font color="#800000"><b>19</b></font>,<font color="#800000"><b>24</b></font>,<font color="#800000"><b>29</b></font>,<font color="#800000"><b>34</b></font>,<font color="#800000"><b>43</b></font>,<font color="#800000"><b>53</b></font>,<font color="#800000"><b>62</b></font>,<font color="#800000"><b>72</b></font>,<font color="#800000"><b>81</b></font>,<font color="#800000"><b>86</b></font>,<font color="#800000"><b>91</b></font>,<font color="#800000"><b>96</b></font>,<font color="#800000"><b>100</b></font>,<font color="#800000"><b>105
    </b></font><b>_BarSteps   </b><font color="#008000"><b>CON </b></font><b>EXT           </b><font color="#0000FF"><b><i>; create a PBP constant that points to the Table
    
     </i></b></font><b>TooLow</b>:  <b>POKECODE </b><font color="#800000"><b>$FE</b></font>,<font color="#800000"><b>1</b></font>,<font color="#FF0000">&quot;TOO LOW &quot;</font>,<font color="#800000"><b>0
    </b></font><b>_TooLow   </b><font color="#008000"><b>CON </b></font><b>EXT             </b><font color="#0000FF"><b><i>; PBP constant pointing to the &quot;Too Low &quot; string
      
     </i></b></font><b>TooRich</b>: <b>POKECODE </b><font color="#800000"><b>$FE</b></font>,<font color="#800000"><b>$C0</b></font>,<font color="#FF0000">&quot;TOO RICH&quot;</font>,<font color="#800000"><b>0
    </b></font><b>_TooRich  </b><font color="#008000"><b>CON </b></font><b>EXT             </b><font color="#0000FF"><b><i>; PBP constant pointing to the &quot;Too Rich&quot; string
      
    </i></b></font><b>FlashSize </b><font color="#008000"><b>CON </b></font><b>EXT
    </b><font color="#008000"><b>ASM
       </b></font><font color="#000080">ifdef BSR
    FlashSize = 2                 </font><font color="#0000FF"><b><i>; 18F has byte addressing (2)
       </i></b></font><font color="#000080">else
    FlashSize = 1                 </font><font color="#0000FF"><b><i>; 12F/16F has words (1)
       </i></b></font><font color="#000080">endif
    </font><font color="#008000"><b>ENDASM
    
    </b></font><b>MidChar   </b><font color="#008000"><b>CON </b></font><b>EXT             </b><font color="#0000FF"><b><i>; MidChar is the border between
    </i></b></font><font color="#000080">@MidChar = 8 * FlashSize      </font><font color="#0000FF"><b><i>; 8 char segments of the 1x16 LCD being used
    
    ;=============================================================================
    </i></b></font><b>Main</b>:
        <font color="#008000"><b>DEBUGIN </b></font>[<b>Uin</b>.<b>LowByte</b>]     <font color="#0000FF"><b><i>; Serial Input
        </i></b></font><b>Uin </b>=  <b>Uin </b>*/ <font color="#800000"><b>124         </b></font><font color="#0000FF"><b><i>; same as (* 100 / 207)
        </i></b></font><font color="#008000"><b>LCDOUT </b></font><font color="#800000"><b>$FE</b></font>, <font color="#800000"><b>2             </b></font><font color="#0000FF"><b><i>; LCD Home Cursor
    
        </i></b></font><font color="#008000"><b>FOR </b></font><b>BarCount </b>= <font color="#800000"><b>0 </b></font><font color="#008000"><b>TO </b></font>(<font color="#800000"><b>15 </b></font>* <b>FlashSize</b>) <font color="#008000"><b>STEP </b></font><b>FlashSize
            </b><font color="#008000"><b>IF </b></font>(<b>BarCount </b>= <b>MidChar</b>) <font color="#008000"><b>THEN LCDOUT </b></font><font color="#800000"><b>$FE</b></font>,<font color="#800000"><b>$C0  </b></font><font color="#0000FF"><b><i>; Second half of 1x16 LCD
            </i></b></font><b>PEEKCODE </b>(<b>_BarSteps</b>+<b>BarCount</b>),<b>BarValue       </b><font color="#0000FF"><b><i>; Get BarValue from Table
            </i></b></font><b>R0</b>.<b>LowByte </b>= <b>Uin</b>.<b>LowByte </b>- <b>BarValue
            </b><font color="#008000"><b>IF </b></font><b>Carry </b><font color="#008000"><b>THEN                                </b></font><font color="#0000FF"><b><i>; Uin &gt;= BarValue
                </i></b></font><font color="#008000"><b>LCDOUT </b></font><font color="#800000"><b>255                               </b></font><font color="#0000FF"><b><i>;  show a Full char
            </i></b></font><font color="#008000"><b>ELSE                                         </b></font><font color="#0000FF"><b><i>; Uin &lt; BarValue
                </i></b></font><font color="#008000"><b>LCDOUT </b></font><font color="#FF0000">&quot; &quot;                               </font><font color="#0000FF"><b><i>;  show a blank
            </i></b></font><font color="#008000"><b>ENDIF
        NEXT </b></font><b>BarCount
        
        R0</b>.<b>LowByte </b>= <b>Uin</b>.<b>LowByte </b>- <font color="#800000"><b>10                    </b></font><font color="#0000FF"><b><i>; if Uin &lt; 10
        </i></b></font><font color="#008000"><b>IF </b></font>!<b>Carry </b><font color="#008000"><b>THEN </b></font><b>MsgAddr </b>= <b>_TooLow </b>: <font color="#008000"><b>GOSUB </b></font><b>ShowMsg
    
        R0</b>.<b>LowByte </b>= <b>Uin</b>.<b>LowByte </b>+ <font color="#800000"><b>145                   </b></font><font color="#0000FF"><b><i>; if Uin &gt; 110
        </i></b></font><font color="#008000"><b>IF </b></font><b>Carry </b><font color="#008000"><b>THEN </b></font><b>MsgAddr </b>= <b>_TooRich </b>: <font color="#008000"><b>GOSUB </b></font><b>ShowMsg
    </b><font color="#008000"><b>GOTO </b></font><b>Main
    
    </b><font color="#0000FF"><b><i>;=============================================================================
    </i></b></font><b>ShowMsg</b>:
        <b>PEEKCODE MsgAddr</b>, <b>B0
        </b><font color="#008000"><b>IF </b></font><b>B0 </b>= <font color="#800000"><b>0 </b></font><font color="#008000"><b>THEN RETURN
        LCDOUT </b></font><b>B0
        MsgAddr </b>= <b>MsgAddr </b>+ <b>FlashSize
    </b><font color="#008000"><b>GOTO </b></font><b>ShowMsg
    </b>
    cheers,
    DT

  2. #2
    Join Date
    Jan 2008
    Location
    Selm, Germany
    Posts
    116


    Did you find this post helpful? Yes | No

    Smile Its Guru time

    Hi Darrel,

    looks impressive to me like a motorcycle to a small boy.....

    Whats this command:

    Uin = Uin */ 124 ; same as (* 100 / 207)

    |
    |
    |
    the above means two mathematic orders in one? something like shifting bits?

    there would be a small mistake but thats totally acceptable because the bargraph is that crude which is really fine enough.

    will test that of course although there should be no need.....

    regards

    Mugel

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


    Did you find this post helpful? Yes | No

    Default

    The */ operator first multiplies the 2 values (Uin * 124).
    Then it discards the low byte, and returns the rest.
    So effectively, it divides the result by 256, without having to do the divide part.

    100 / 207 = 0.48309178
    124 / 256 = 0.484375 ; not exact, but pretty close

    You're correct that there are small differences between the 2 formulas, but the error is less than +/- 1. And, you will never see a difference with the resolution of a 16 block bargraph.

    And, there probably is a need to test it.
    I was using a 16F877 with a 4x20 LCD. Could have missed something for your 16F628A and 1x16 LCD.
    <br>
    DT

  4. #4
    Join Date
    May 2004
    Location
    NW France
    Posts
    3,653


    Did you find this post helpful? Yes | No

    Question

    Hi, Darrel

    Could you tell us for LCD Initialization at powerup ...If Uin first value is > 10 ... I do not see any ???

    you just suppose exhaust is air filled ???

    Alain
    ************************************************** ***********************
    Why insist on using 32 Bits when you're not even able to deal with the first 8 ones ??? ehhhhhh ...
    ************************************************** ***********************
    IF there is the word "Problem" in your question ...
    certainly the answer is " RTFM " or " RTFDataSheet " !!!
    *****************************************

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


    Did you find this post helpful? Yes | No

    Default

    I'm not sure what you mean Alain.

    If the first value is > 10, it will just draw the bargraph like normal.
    It doesn't do anything until a serial byte is received.
    <br>
    DT

  6. #6
    Join Date
    May 2004
    Location
    NW France
    Posts
    3,653


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by Darrel Taylor View Post
    I'm not sure what you mean Alain.

    If the first value is > 10, it will just draw the bargraph like normal.
    It doesn't do anything until a serial byte is received.
    <br>
    Hi,Darrel

    What I ment is you initialize the LCD ... ONLY if the value is < 10 ... ( when writing TOO LOW )

    What if you stop the engine and start it again ??? ... first value will be > 10 , due to the exhaust gases still in the exhaust tubing ... and I do not see any LCDOUT $FE,1 in this figure.

    Alain
    Last edited by Acetronics2; - 4th March 2008 at 15:35.
    ************************************************** ***********************
    Why insist on using 32 Bits when you're not even able to deal with the first 8 ones ??? ehhhhhh ...
    ************************************************** ***********************
    IF there is the word "Problem" in your question ...
    certainly the answer is " RTFM " or " RTFDataSheet " !!!
    *****************************************

  7. #7
    skimask's Avatar
    skimask Guest


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by Acetronics View Post
    What if you stop the engine and start it again ??? ... first value will be > 10 , due to the exhaust gases still in the exhaust tubing ... and I do not see any LCDOUT $FE,1 in this figure.
    Alain
    Exhaust gases might still be in the tubing, but I wonder how quickly the sensor will cool off and not make a decent output. In my experience, those things cool off fairly quick. But then again, the 3/4 wire ones heat up pretty fast too...

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


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by Acetronics View Post
    What I ment is you initialize the LCD ... ONLY if the value is < 10 ... ( when writing TOO LOW )

    What if you stop the engine and start it again ??? ... first value will be > 10 , due to the exhaust gases still in the exhaust tubing ... and I do not see any LCDOUT $FE,1 in this figure.
    Oh, you mean the "Clear Screen".
    Since it writes to all 16 characters on each pass, I used "Home Cursor" ($FE,2) instead of "Clear Screen" ($FE,1) to prevent blinking of the display during updates.

    Or, if you're referring to the Power-On initialization that gets rid of the black blocks and makes the LCD work in the first place .... Mugel didn't have any specific initialization sequences in his original program and reported it to be working. So I assumed his display didn't need it.

    The first character sent to the LCD will cause PBP to initialize the display (if it hasn't already). It doesn't have to be $FE,1.
    <br>
    DT

Similar Threads

  1. Multiple PICS from Same Crystal?
    By WOZZY-2010 in forum General
    Replies: 2
    Last Post: - 6th February 2010, 16:18
  2. Multiple analog inputs ?
    By rngd in forum mel PIC BASIC Pro
    Replies: 5
    Last Post: - 25th February 2008, 16:13
  3. Multiple PIC programming
    By Nicholas in forum mel PIC BASIC Pro
    Replies: 0
    Last Post: - 8th May 2007, 00:47
  4. Multiple PIC's with 1 crystal
    By puma in forum Schematics
    Replies: 11
    Last Post: - 20th March 2007, 18:02
  5. Multiple IR LEDs from 1 port using transistor
    By belpe123 in forum General
    Replies: 3
    Last Post: - 20th May 2005, 23: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