Multiple if then optimization


Closed Thread
Results 1 to 36 of 36

Hybrid View

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


    Did you find this post helpful? Yes | No

    Cool 20 if then

    yes the 20 if then work, no problem. Assembling took maybe 3 times longer then those blinky codes and it uses nearly 3/5 of the code space in my 16F628..but works flawlessly.

    to Joe:

    oh man I tried to use DTs bargraph routines but only got the error "coulndīt open bargraph.bas" or something. Copied it in a "dozen" directories around the main PBP main and my project directories...didnīt work, always the same error.
    But I uses DTs instant interrupt blinky program and that worked....so I donīt know a bone about how to work around "include" problems.

    On the other my bargraph is quite crude with its big bars....but a fine bargraph isnīt an option here...way to hard to see while driving the car or bike, you need only sort of lean/rich tendencies and the lambda sensor it VERY jumpy around the stochiometric area.

    8 leds would do but I did it mainly because of 3 reasons:

    1.: I COULD do it.......with a little help of my friends....greetings to you all!
    2.: One of my employees is sort of colour blind and wanted something to recocnize
    without colours.
    3.: we do a lot around sportscars engines and we test drive them mainly when the sun shines and a LED bargraph is hard to read while driving 100km/h in corners and the sun shining all over....

    Yeah......Iīm telling junk. Here in Germany the sunīs just a rumour you know, seen last time in june 2007 or so....
    Last edited by Mugelpower; - 3rd March 2008 at 07:13.

  2. #2
    Join Date
    Jan 2006
    Location
    Istanbul
    Posts
    1,185


    Did you find this post helpful? Yes | No

    Default

    Here it is
    982 words

    Code:
    <font color="#008000">@__config _XT_OSC &amp; _WDT_ON &amp; _MCLRE_ON &amp; _LVP_OFF &amp; _CP_OFF
    
    </font><font color="#000080"><b>INCLUDE </b></font><font color="#008000"><b>&quot;modedefs.bas&quot;
    </b></font><font color="#000080"><b>DEFINE </b></font>OSC <font color="#FF0000"><b>4
    </b></font>Uin        <font color="#000080"><b>VAR WORD
    </b></font>B0         <font color="#000080"><b>VAR WORD </b><i>' Cnt is a word variable
    </i></font>InputData  <font color="#000080"><b>VAR WORD </b><i>' variable to receive data into
    </i></font>RepNo      <font color="#000080"><b>VAR BYTE
    
    </b><i>' START OF MAIN PROGRAM
    '
    </i></font>CMCON = <font color="#FF0000"><b>7 </b></font><font color="#000080"><i>' RA0-RA3 are digital I/O
    </i></font>TRISA = <font color="#FF0000"><b>0 </b></font><font color="#000080"><i>' PORT A is output
    </i></font>TRISB = <font color="#FF0000"><b>1 </b></font><font color="#000080"><i>' RB0 is Input others output
    
    </i></font>Main:
    
         <font color="#000080"><b>SERIN </b></font>PORTB.<font color="#FF0000"><b>0</b></font>,N2400,B0
         B0 = <font color="#FF0000"><b>100 </b></font>* B0
         Uin = B0 / <font color="#FF0000"><b>207
         </b></font><font color="#000080"><b>GOSUB </b></font>Bargraph
         <font color="#000080"><b>PAUSE </b></font><font color="#FF0000"><b>5
    
    </b></font><font color="#000080"><b>GOTO </b></font>Main
    
    Bargraph:
    
    <font color="#000080"><b>LCDOUT </b></font><font color="#FF0000"><b>$fe</b></font>,<font color="#FF0000"><b>1      </b></font><font color="#000080"><i>'Valid for all cases.
    
    </i><b>SELECT CASE </b></font>Uin
           
     <font color="#000080"><b>CASE IS </b></font>&lt; <font color="#FF0000"><b>10 
          </b></font><font color="#000080"><b>LCDOUT </b></font><font color="#008000"><b>&quot;TOO LOW&quot;
     </b></font><font color="#000080"><b>CASE IS </b></font>&gt; <font color="#FF0000"><b>10 </b></font><font color="#000080"><b>AND IS </b></font>&lt;= <font color="#FF0000"><b>15
          </b></font>RepNo = <font color="#FF0000"><b>1
          </b></font><font color="#000080"><b>GOSUB </b></font>RepLCD
    
     <font color="#000080"><b>CASE IS </b></font>&gt; <font color="#FF0000"><b>15 </b></font><font color="#000080"><b>AND IS </b></font>&lt;= <font color="#FF0000"><b>19
          </b></font>RepNo = <font color="#FF0000"><b>2
          </b></font><font color="#000080"><b>GOSUB </b></font>RepLCD
    
     <font color="#000080"><b>CASE IS </b></font>&gt; <font color="#FF0000"><b>19 </b></font><font color="#000080"><b>AND IS </b></font>&lt;= <font color="#FF0000"><b>24
          </b></font>RepNo = <font color="#FF0000"><b>3
          </b></font><font color="#000080"><b>GOSUB </b></font>RepLCD
    
     <font color="#000080"><b>CASE IS </b></font>&gt; <font color="#FF0000"><b>24 </b></font><font color="#000080"><b>AND IS </b></font>&lt;= <font color="#FF0000"><b>29
          </b></font>RepNo = <font color="#FF0000"><b>4
          </b></font><font color="#000080"><b>GOSUB </b></font>RepLCD
    
     <font color="#000080"><b>CASE IS </b></font>&gt; <font color="#FF0000"><b>29 </b></font><font color="#000080"><b>AND IS </b></font>&lt;= <font color="#FF0000"><b>34
          </b></font>RepNo = <font color="#FF0000"><b>5
          </b></font><font color="#000080"><b>GOSUB </b></font>RepLCD
    
     <font color="#000080"><b>CASE IS </b></font>&gt; <font color="#FF0000"><b>34 </b></font><font color="#000080"><b>AND IS </b></font>&lt;= <font color="#FF0000"><b>43
          </b></font>RepNo = <font color="#FF0000"><b>6
          </b></font><font color="#000080"><b>GOSUB </b></font>RepLCD
    
     <font color="#000080"><b>CASE IS </b></font>&gt; <font color="#FF0000"><b>43 </b></font><font color="#000080"><b>AND IS </b></font>&lt;= <font color="#FF0000"><b>53
          </b></font>RepNo = <font color="#FF0000"><b>7
          </b></font><font color="#000080"><b>GOSUB </b></font>RepLCD
    
     <font color="#000080"><b>CASE IS </b></font>&gt; <font color="#FF0000"><b>53 </b></font><font color="#000080"><b>AND IS </b></font>&lt;= <font color="#FF0000"><b>62 
          </b></font>RepNo = <font color="#FF0000"><b>8
          </b></font><font color="#000080"><b>GOSUB </b></font>RepLCD
    
     <font color="#000080"><b>CASE IS </b></font>&gt; <font color="#FF0000"><b>62 </b></font><font color="#000080"><b>AND IS </b></font>&lt;= <font color="#FF0000"><b>72
          </b></font>RepNo = <font color="#FF0000"><b>8
          </b></font><font color="#000080"><b>GOSUB </b></font>RepLCD
          <font color="#000080"><b>GOSUB </b></font>LCD2
          RepNo = <font color="#FF0000"><b>1      
          </b></font><font color="#000080"><b>GOSUB </b></font>RepLCD
     <font color="#000080"><b>CASE IS </b></font>&gt; <font color="#FF0000"><b>72 </b></font><font color="#000080"><b>AND IS </b></font>&lt;= <font color="#FF0000"><b>81
          </b></font>RepNo = <font color="#FF0000"><b>8
          </b></font><font color="#000080"><b>GOSUB </b></font>RepLCD
          <font color="#000080"><b>GOSUB </b></font>LCD2
          RepNo = <font color="#FF0000"><b>2
          </b></font><font color="#000080"><b>GOSUB </b></font>RepLCD
    
     <font color="#000080"><b>CASE IS </b></font>&gt; <font color="#FF0000"><b>81 </b></font><font color="#000080"><b>AND IS </b></font>&lt;= <font color="#FF0000"><b>86
          </b></font>RepNo = <font color="#FF0000"><b>8
          </b></font><font color="#000080"><b>GOSUB </b></font>RepLCD
          <font color="#000080"><b>GOSUB </b></font>LCD2
          RepNo = <font color="#FF0000"><b>3
          </b></font><font color="#000080"><b>GOSUB </b></font>RepLCD
    
     <font color="#000080"><b>CASE IS </b></font>&gt; <font color="#FF0000"><b>86 </b></font><font color="#000080"><b>AND IS </b></font>&lt;= <font color="#FF0000"><b>91
          </b></font>RepNo = <font color="#FF0000"><b>8
          </b></font><font color="#000080"><b>GOSUB </b></font>RepLCD
          <font color="#000080"><b>GOSUB </b></font>LCD2
          RepNo = <font color="#FF0000"><b>4
          </b></font><font color="#000080"><b>GOSUB </b></font>RepLCD
    
     <font color="#000080"><b>CASE IS </b></font>&gt; <font color="#FF0000"><b>91 </b></font><font color="#000080"><b>AND IS </b></font>&lt;= <font color="#FF0000"><b>96
          </b></font>RepNo = <font color="#FF0000"><b>8
          </b></font><font color="#000080"><b>GOSUB </b></font>RepLCD
          <font color="#000080"><b>GOSUB </b></font>LCD2
          RepNo = <font color="#FF0000"><b>5
          </b></font><font color="#000080"><b>GOSUB </b></font>RepLCD
    
     <font color="#000080"><b>CASE IS </b></font>&gt; <font color="#FF0000"><b>96 </b></font><font color="#000080"><b>AND IS </b></font>&lt;= <font color="#FF0000"><b>100
          </b></font>RepNo = <font color="#FF0000"><b>8
          </b></font><font color="#000080"><b>GOSUB </b></font>RepLCD
          <font color="#000080"><b>GOSUB </b></font>LCD2
          RepNo = <font color="#FF0000"><b>6
          </b></font><font color="#000080"><b>GOSUB </b></font>RepLCD
    
     <font color="#000080"><b>CASE IS </b></font>&gt; <font color="#FF0000"><b>100 </b></font><font color="#000080"><b>AND IS </b></font>&lt;= <font color="#FF0000"><b>105
          </b></font>RepNo = <font color="#FF0000"><b>8
          </b></font><font color="#000080"><b>GOSUB </b></font>RepLCD
          <font color="#000080"><b>GOSUB </b></font>LCD2
          RepNo = <font color="#FF0000"><b>7
          </b></font><font color="#000080"><b>GOSUB </b></font>RepLCD
    
     <font color="#000080"><b>CASE IS </b></font>&gt; <font color="#FF0000"><b>105 </b></font><font color="#000080"><b>AND IS </b></font>&lt;= <font color="#FF0000"><b>110
          </b></font>RepNo = <font color="#FF0000"><b>8
          </b></font><font color="#000080"><b>GOSUB </b></font>RepLCD
          <font color="#000080"><b>GOSUB </b></font>LCD2
          RepNo = <font color="#FF0000"><b>8
          </b></font><font color="#000080"><b>GOSUB </b></font>RepLCD
    
     <font color="#000080"><b>CASE ELSE 
          LCDOUT </b></font><font color="#FF0000"><b>$FE</b></font>,<font color="#FF0000"><b>$C0</b></font>,<font color="#008000"><b>&quot;TOO RICH&quot;
    </b></font><font color="#000080"><b>END SELECT
    
    RETURN
    
    </b></font>RepLCD:
        <font color="#000080"><b>WHILE </b></font>RepNo &gt; <font color="#FF0000"><b>0
              </b></font><font color="#000080"><b>LCDOUT </b></font><font color="#FF0000"><b>255
              </b></font>RepNo = RepNo - <font color="#FF0000"><b>1
        </b></font><font color="#000080"><b>WEND
       </b></font><font color="#000080"><b>RETURN
    
    </b></font>LCD2:
        <font color="#000080"><b>LCDOUT </b></font><font color="#FF0000"><b>$FE</b></font>,<font color="#FF0000"><b>$C0
        </b></font><font color="#000080"><b>RETURN
        
    </b></font>

    Btw:
    Select case produces 100 words more!
    So, if you go with your IF..THENs, it will be approx. 882 words, but select case provides a clean look.
    Last edited by sayzer; - 3rd March 2008 at 16:11.
    "If the Earth were a single state, Istanbul would be its capital." Napoleon Bonaparte

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


    Did you find this post helpful? Yes | No

    Talking ....

    Another way

    Code:
    '************************************************* ****************
    '* Name : Analogbargraph1(16F628A).BAS *
    '* Author : M.David *
    '* Notice : Copyright (c) 2008 [select VIEW...EDITOR OPTIONS] *
    '* : All Rights Reserved *
    '* Date : 28.02.2008 *
    '* Version : 1.0 *
    '* Notes : needs 12F675 for Lambdatesting device and LCD 1X16 *
    '* : input 0.1 - 1.1 Volts in GPIO.0 *
    '* : needs ADCserout(12F675).bas *
    '  569 Lines
    '************************************************* ****************
    '
    ' DEFINITIONS
    
    @      __config _XT_OSC & _WDT_ON & _MCLRE_ON & _LVP_OFF & _CP_OFF
    Include "modedefs.bas"
    'CMCON=%00000111
    
    
    DEFINE OSC 4
    
    NbPatterns	var Byte
    Uin 		var word
    B0 			VAR word ' Cnt is a word variable
    inputData	var word ' variable to receive data into
    
    
    ' START OF MAIN PROGRAM
    '
    CMCON = 7 ' RA0-RA3 are digital I/O
    TRISA = 0 ' PORT A is output
    TRISB = 1 ' RB0 is Input others output
    
    main:
    
    Serin PORTB.0,N2400,B0 
    B0 = 100 * B0
    Uin = B0 / 207
    
    bargraph:
    
    IF Uin < 10 THEN LCDOUT $FE,1,"TOO LOW" : GOTO Show
    
    IF Uin > 110 THEN LCDOUT $FE,1,"TOO HIGH" : GOTO Show
    
    
    LOOKDOWN2 Uin , < [ 11,16,20,25,30,35,44,54,63], NbPatterns 
    
    LCDOUT $FE, 1, REP 255\ NbPatterns
    
    IF Uin > 62 THEN
    
    LOOKDOWN2 Uin , < [ 63,73,82,87,92,97,101,106,111], NbPatterns 
    
    LCDOUT $FE, 1, REP 255\ 8
    
    LCDOUT $FE, $C0, REP 255\ NbPatterns
    
    ENDIF
    
    Show:
    
    Pause 5 
    goto main
    
    
    END ' End of program



    569 Words ...




    Alain
    Last edited by Acetronics2; - 3rd March 2008 at 09:51. Reason: CMCON : Double definition ....
    ************************************************** ***********************
    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 " !!!
    *****************************************

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


    Did you find this post helpful? Yes | No

    Default Sting!

    Hey Girls & Guys,

    seems I poked into a bees nest.... I will try those codes in the evening (10 hrs from now).

    Youre really helpful.

    How about a code for extern interrupt that triggers a 1 ms high port after a delay found in a lookdown/case/if then row list? from 3 to 600 Hz of course......to get a constant phase shift between trigger and output.....

    Its oughta be real fast!! 20MHz 16F628A preferred
    "On interrupt" gets 180° phase shift (maximum limit) at 200 Hz.....

    I dunno how to integrate a variable delay into DTs instant interrupts....

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


    Did you find this post helpful? Yes | No

    Smile

    Quote Originally Posted by Mugelpower View Post

    How about a code for extern interrupt that triggers a 1 ms high port after a delay found in a lookdown/case/if then row list? from 3 to 600 Hz of course......to get a constant phase shift between trigger and output.....

    ....
    Could you explain that better ???

    You're asking for a PBP written electronic ignition here ...

    don't you think you abuse ... just a little bit !!!

    Have an eye here ... : http://a110.free.fr/SPIP172a110/arti...?id_article=23

    Ok, assembler ... but kit or scratch realizable, and the forum offers a Huge help ...

    Alain

    PS: I'm working on a full PBP version ... but Assembler interrupts can't be avoided !!!
    Last edited by Acetronics2; - 3rd March 2008 at 09:39.
    ************************************************** ***********************
    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 " !!!
    *****************************************

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


    Did you find this post helpful? Yes | No

    Red face Ignition help

    Hi Acetronics,

    yeah, in Principle thats that. BUT: thats french (ARGL-GARG!!) and I donīt understand 2% of it.
    And: I have to modify the code it myself fromtime to time which could only be done if Iīm knowing quite a lot about the code. Man, thats a BIG FISH to swallow for an oldschool mechanic. Learning programming, trying to avoid asm, learning that asm couldnīt be avoided...... ARGL-GARG !

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


    Did you find this post helpful? Yes | No

    Wink

    Hi,

    Generally speaking ...

    Using PbP do not "protect" you from learning assembler ...it's a real "plus" to see the ASM result of your programming ...
    and overall understand what's really happening, and how ...

    Now about Ignition ... it's simple: you have an asm program to use with MPLAB , and a " Table generator " program ( in QBasic or, more recently EXCEL), just to load your timing values.
    So, there are special knowledge of assembler needed ...

    For French ... aha ... just think I spent a year in Berlin ( Yr 1990 ), and had to dig out my German school knowledge ... Euuuuhhhh, I'm also an old Mechanics ( and Thermics ) guy ...

    Just Follow the scheme and components list ... you'll have done 90% of the work. ... on the Forum, we ALSO Compute tables for ... how to tell it ??? .... E.T.s ?

    You also have this link ... in English :

    http://www.transmic.net/index.htm

    But ... not so good as ours ... yeah !!!

    Alain

    PS for Sayzer ...: I found a Turkish > French / French > Turkish free dictionnary on the Web; I do Hope you appreciate the effort ( LoL ...)
    Last edited by Acetronics2; - 3rd March 2008 at 12:40.
    ************************************************** ***********************
    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 " !!!
    *****************************************

  8. #8
    skimask's Avatar
    skimask Guest


    Did you find this post helpful? Yes | No

    Default

    Code:
    @      __config _XT_OSC & _WDT_ON & _MCLRE_ON & _LVP_OFF & _CP_OFF
    Include "modedefs.bas"
    nbpatterns var byte:uin var word:cmcon=7:trisa=0:trisb=1
    main: serin portb.0,n2400,uin:uin=(uin*100)/207:lcdout $fe,1,"TOO ":if uin<10 then lcdout "LOW":goto show
    IF Uin > 110 THEN LCDOUT "HIGH": GOTO Show
    lookdown2 uin,<[11,16,20,25,30,35,44,54,63],nbpatterns:lcdout $fe,1,rep 255\nbpatterns
    if uin > 62 then
    lookdown2 uin,<[ 63,73,82,87,92,97,101,106,111], NbPatterns
    lcdout $fe,1,rep 255\ 8,$fe, $c0, rep 255\ nbpatterns
    ENDIF
    Show:     Pause 5:goto main
    END ' End of program
    13 LINES!
    Last edited by skimask; - 3rd March 2008 at 16:29.

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


    Did you find this post helpful? Yes | No

    Default code minimum

    Hi Skimask,

    yeah will try that too, never worked around the lookdown commands...will see how it works


    sincerely

    Mugel

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


    Did you find this post helpful? Yes | No

    Talking

    Quote Originally Posted by skimask View Post
    13 LINES!

    Hi, Ski

    That's way too hard for my old eyes !!! Lol ...

    at second look ... I've seen that somewhere before, but Where ??? ...

    Alain
    Last edited by Acetronics2; - 3rd March 2008 at 15:46.
    ************************************************** ***********************
    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 " !!!
    *****************************************

  11. #11
    skimask's Avatar
    skimask Guest


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by Acetronics View Post
    Hi, Ski
    That's way too hard for my old eyes !!! Lol ...
    at second look ... I've seen that somewhere before, but Where ??? ...
    Alain
    Might even be a few words shorter on code!
    Or at least a few colons longer.

  12. #12
    Join Date
    Jan 2006
    Location
    Istanbul
    Posts
    1,185


    Did you find this post helpful? Yes | No

    Default

    13 lines is not the case ;

    But, it is only 2 words smaller then Alain's.

    Come on Ski, saved 2 words only ???


    -----------------
    "If the Earth were a single state, Istanbul would be its capital." Napoleon Bonaparte

  13. #13
    skimask's Avatar
    skimask Guest


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by sayzer View Post
    CASE IS >19 AND IS <= 24
    Does the AND in the CASE IS actually work?
    I thought the CASE could only take one parameter to work on...

Similar Threads

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