More IF_THEN dumb questions.


Closed Thread
Results 1 to 12 of 12

Hybrid View

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


    Did you find this post helpful? Yes | No

    Default

    For this Kind of task i'll prefer using Select Case instead of bang my head everywhere.

    I see you check only two bits variable..

    if r1sched = 0 and r1ctrl = 1 then

    if those are comming from some PORT pins, let's say PORTB.0 and PORTB.1 use the following

    Code:
    GetPORTB = PORTB & $3 ' mask other bits than B0 and B1
    
    select case GetPORTB
          Case 0 ' b0=0 b1=0
            ' Do your stuff here for that condition
    
          Case 1 ' b0=1 b1=0
            ' Do your stuff here for that condition
    
          Case 2 'b0=0 b1=1
            ' Do your stuff here for that condition
    
          Case 3 ' b0=1 b1=1
            ' Do your stuff here for that condition
    
    end select
    that's easier like that.

    Or you can also use BRANCH statement that will make your program jump (GOTO) to a specific label depending of the value of your var.

    Code:
    GetPORTB = PORTB & $3 ' mask other bits than B0 and B1
    branch GetPORTB[condition0,condition1,condition2,condition3]

    BUT in case you still want to use IF then bla blah

    Code:
    IF condition 1 then 
        ' do your stuff here
    endif
    
    IF condition 2 then 
        ' do your stuff here
    endif
    
    IF condition 3 then 
        ' do your stuff here
    endif
    
    IF condition 3 then 
        ' do your stuff here
    endif
    Last edited by mister_e; - 18th February 2005 at 23:43.
    Steve

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

Similar Threads

  1. Olympic Timer
    By Melanie in forum Code Examples
    Replies: 47
    Last Post: - 17th September 2008, 19:46
  2. Two quick (and elementary) questions.
    By scorpion990 in forum mel PIC BASIC Pro
    Replies: 1
    Last Post: - 26th June 2008, 23:03
  3. A few 12F683 questions
    By dhouston in forum mel PIC BASIC Pro
    Replies: 6
    Last Post: - 24th May 2008, 03:54
  4. Usart Questions
    By shawn in forum mel PIC BASIC Pro
    Replies: 5
    Last Post: - 8th March 2008, 01:17
  5. Still new to PicBasic - i2c questions
    By cometboy in forum mel PIC BASIC
    Replies: 4
    Last Post: - 13th November 2006, 18:27

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