IF..THEN syntax


Closed Thread
Results 1 to 40 of 53

Thread: IF..THEN syntax

Hybrid View

  1. #1
    Join Date
    Oct 2006
    Posts
    32

    Default IF..THEN syntax

    Good day! I am a new user of PIC Basic and my version is PicBasic Pro 2.3 compiler. I am starting this thread because there is something that I cannot quite understand. There is a code in a book about robotics that I copied word for word into my editor, by the way I'm using MicroCode Studio 2003 for my editor, and somehow, when I tried to compile the program, there is an error message that says that the syntax is wrong. I'm including the code in here:

    "if s1 > 225 then s1 = 225"

    could anyone please help me or give me any idea why the compiler gives me an error message that the syntax is wrong? Thanks in advance!

  2. #2
    Join Date
    Oct 2006
    Posts
    32


    Did you find this post helpful? Yes | No

    Default IF..THEN syntax

    Please PM me if possible.. thanks!

  3. #3
    Join Date
    Aug 2006
    Location
    Look, behind you.
    Posts
    2,818


    Did you find this post helpful? Yes | No

    Default From the Spaghetti bowl . . .

    What does S1 represent?
    you have a variable declared to represent s1?
    examples:
    s1 var byte
    or
    s1 var portB.1
    or
    symbol s1 = portb.1
    Last edited by Archangel; - 15th February 2007 at 06:59.
    If you do not believe in MAGIC, Consider how currency has value simply by printing it, and is then traded for real assets.
    .
    Gold is the money of kings, silver is the money of gentlemen, barter is the money of peasants - but debt is the money of slaves
    .
    There simply is no "Happy Spam" If you do it you will disappear from this forum.

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


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by scaenix View Post
    ...

    "if s1 > 225 then s1 = 225"...
    There must be some other IF statements with missing THEN or ENDIF in the code.
    One of those may be the cause of the error you get.

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

  5. #5
    Join Date
    Jul 2003
    Posts
    2,358


    Did you find this post helpful? Yes | No

    Default

    PBP Version 2.3 is probably well over six years old (it's time MeLabs put a Date against the version releases on their website) and has many issues that have been fixed and improvements made over the subsequent years. You should seriously consider upgrading. Forum members here would be hard pressed to try to second-guess problems when you're using a product that old and you could spend many hours chasing a problem that has been long fixed and forgotten in the mists of time.

  6. #6
    Join Date
    Oct 2006
    Posts
    32


    Did you find this post helpful? Yes | No

    Default IF..THEN syntax

    I agree that the version I'm using is old but the program I tried to compile was also more or less 6 years old. anyway im pasting the whole program here for you to inspect. Thanks!


    'Read Cds cell #1 on port b line 1
    'Read Cds cell #2 on port b line 7
    v1 var byte 'Variable v1 holds Cds #1 information
    v2 var byte 'Variable v2 holds Cds #2 information
    v3 var byte 'Variable for calculation
    s1 var byte 'Variable s1 holds servomotor #1 pulse width info
    s2 VAR word 'variable for random function
    rv var byte 'variable rv holds the range value
    s1 = 150 'initialize steering servomotor facing forward
    rv = 10 'Adjust as needed for operation
    ct var byte 'counter


    start:
    pot portb.2,255,v1
    pot portb.3,255,v2

    'Check bumper switch "Did I hit something?"
    if porta.0 = 0 then avoid 'Hit obstacle go into avoid mode
    'Is it sleepy time?
    if v1 <= 230 then skp 'Is it dark enough to sleep?
    if v2 > 230 then slp 'Yes

    'Is it too bright to see?
    skp:
    if v1 >= 12 then skip2
    if v2 < 12 then avoid

    'Which way do I go?
    skip2:
    if v1 = v2 then straight
    if v1 > v2 then greater
    if v1 < v2 then lesser

    straight:
    pulsout portb.6, s1
    pulsout portb.7, 157
    goto start

    greater:
    v3 = v1 - v2
    if v3 > rv then right
    goto straight

    lesser:
    v3 = v2 - v1
    if v3 > rv then left
    goto straight

    right:
    s1 = s1 + 1
    if s1 > 225 then s1 = 225
    pulsout portb.6, s1
    pulsout portb.7, 165
    goto start
    left:
    s1 = s1 - 1
    if s1 < 65 then s1 = 65
    pulsout portb.6, s1
    pulsout portb.7, 165
    goto start

    slp:
    pulsout portb.6, s1
    pulsout portb.7, 167
    goto start

    avoid:
    random s2
    s1 = s2 / 256
    if s1 < 65 then s1 = 65
    if s1 > 225 then s1 = 225
    for ct = 1 to 125
    pulsout portb.6, s1
    pulsout portb.7, 177
    pause 18
    next ct

    s1 = 150

    goto start

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


    Did you find this post helpful? Yes | No

    Default

    I just compiled it here for a 16F877. PBP 2.46

    No errors.
    <br>
    DT

  8. #8
    Join Date
    Oct 2006
    Posts
    32


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by Darrel Taylor View Post
    I just compiled it here for a 16F877. PBP 2.46

    No errors.
    <br>

    I'm compiling it for a 16F84 with PBP 2.3

    That's the only version I have because I can't afford to buy or upgrade.. I hope you understand :-)

  9. #9
    Join Date
    Oct 2006
    Posts
    32


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by scaenix View Post

    'Read Cds cell #1 on port b line 1
    'Read Cds cell #2 on port b line 7
    v1 var byte 'Variable v1 holds Cds #1 information
    v2 var byte 'Variable v2 holds Cds #2 information
    v3 var byte 'Variable for calculation
    s1 var byte 'Variable s1 holds servomotor #1 pulse width info
    s2 VAR word 'variable for random function
    rv var byte 'variable rv holds the range value
    s1 = 150 'initialize steering servomotor facing forward
    rv = 10 'Adjust as needed for operation
    ct var byte 'counter


    start:
    pot portb.2,255,v1
    pot portb.3,255,v2

    'Check bumper switch "Did I hit something?"
    if porta.0 = 0 then avoid 'Hit obstacle go into avoid mode
    'Is it sleepy time?
    if v1 <= 230 then skp 'Is it dark enough to sleep?
    if v2 > 230 then slp 'Yes

    'Is it too bright to see?
    skp:
    if v1 >= 12 then skip2
    if v2 < 12 then avoid

    'Which way do I go?
    skip2:
    if v1 = v2 then straight
    if v1 > v2 then greater
    if v1 < v2 then lesser

    straight:
    pulsout portb.6, s1
    pulsout portb.7, 157
    goto start

    greater:
    v3 = v1 - v2
    if v3 > rv then right
    goto straight

    lesser:
    v3 = v2 - v1
    if v3 > rv then left
    goto straight

    right:
    s1 = s1 + 1
    if s1 > 225 then s1 = 225
    pulsout portb.6, s1
    pulsout portb.7, 165
    goto start
    left:
    s1 = s1 - 1
    if s1 < 65 then s1 = 65
    pulsout portb.6, s1
    pulsout portb.7, 165
    goto start

    slp:
    pulsout portb.6, s1
    pulsout portb.7, 167
    goto start

    avoid:
    random s2
    s1 = s2 / 256
    if s1 < 65 then s1 = 65
    if s1 > 225 then s1 = 225
    for ct = 1 to 125
    pulsout portb.6, s1
    pulsout portb.7, 177
    pause 18
    next ct

    s1 = 150

    goto start

    I've quoted the code I've posted in one of the previous replies. the program is supposed to make the servomotor #1, which is connected to RB7 stop when in total darkness. I'm confused why the motor still continues on turning even if it is supposed to stop. Please anyone enlighten me on this. Thanks very much!
    Last edited by scaenix; - 19th February 2007 at 08:09.

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


    Did you find this post helpful? Yes | No

    Default

    I didn't read the whole thing but here's one fast suggestion for you.

    Pulsout have to return the pin to it's previous state right? but nowhere the initial state have been set. When you turn on a PIC, the state of all pin is hard to predict. add those lines at the top of your code.

    Code:
    PORTB=0    ' Clear all PORTB pin
    TRISB=0     ' Set all PORTB pins to output
    if it doesn't work, you could still place a LOW PORTB.7 after each PULSOUT.
    Steve

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

  11. #11
    Join Date
    Oct 2006
    Posts
    32


    Did you find this post helpful? Yes | No

    Default

    PBP is great and easy to get along with. I'm saving to purchase an upgrade. Talking about what we've just discussed in the previous posts would certainly be worth another topic, say about piracy and intellectual rights? But then again, that is a very broad topic.
    Huhum..let's move on..if anyone wants to start that topic somewhere then I suggest you request that in the forum. As for me, I've created another thread about inputting a mic into the 16f84.

  12. #12
    malc-c's Avatar
    malc-c Guest


    Did you find this post helpful? Yes | No

    Default

    The issue of pirate copies will never go away. In an ideal world there would be no murders, break-ins, car jacking, robberies, hacking or bootlegging etc... but we don't live in an ideal world.

    Someone mentioned cost... I've seen $10 applications pirated and placed up on the net for download, so its not the fact that a genuine copy cost so much. It seems that the low life that pirate these applictions do it just for fun or kudos.

    In the example of reading a book rather than buying it, thats a bad example as you are still causing finacial hardship to both the author, publisher and retailer as its a lost sale. I mean you would hardly go out and buy the book for yourself if you had read your friends copy from cover to cover.

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


    Did you find this post helpful? Yes | No

    Default

    I agree with most that you say with the exception of the book example.

    If I buy a book (or CD or DVD or whatever), I'll probably read it and like with most people it is then destined to spend the rest of it's life abandoned on the shelf. You can come along and borrow the book, read it and return it to me. I can sell that book or give it away to someone else. But at any instance in time, only ONE COPY exists, but more than one person can enjoy the book, certainly not just the person who originally bought it. After all, all your school textbooks have probably been read many times before you and long after you have finished with them. Libraries would not exist where a single copy can be borrowed for the enjoyment of many. The objection is where someone COPIES the original work without recompensing the author/publisher.

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


    Did you find this post helpful? Yes | No

    Default

    Another point of view is from me.

    For US$10, I buy a pirate copy of a US$900 software.
    I do the job and earn US$2,500.
    Then I go to the shop and buy the original version at US$900.
    Me = happy, software maker=happy, customer=happy

    This is the way for me to buy the original version.

    Who can call me a pirate software user?


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

  15. #15
    Join Date
    Feb 2003
    Posts
    432


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by sayzer View Post
    Another point of view is from me.

    For US$10, I buy a pirate copy of a US$900 software.
    I do the job and earn US$2,500.
    Then I go to the shop and buy the original version at US$900.
    Me = happy, software maker=happy, customer=happy

    This is the way for me to buy the original version.

    Who can call me a pirate software user?

    ----------------------
    At the point of doing the actual job you were a pirate user but having bought the software I suppose that legitimises it.

    I have done similar with a disney film. Saw it at the movies, got a downloaded copy for the kids to watch (VCD) and then when the DVD came out I bought it so I dont feel that I have cheated Disney out of anything.

    Having said that, we went to the Cinema a couple of weeks ago to see Night at the Museum. Good family film, current release. Last week I was talking to someone who said they hadnt seen it yet because they lent THEIR DVD to someone THREE WEEKS AGO before it was even on cinema release here.

    I very much doubt that they have any intention of getting a genuine DVD once it is released and that is true of many users of Pirate Software
    Keith

    www.diyha.co.uk
    www.kat5.tv

Similar Threads

  1. Endless supply of 'syntax error's.
    By BitHead in forum mel PIC BASIC Pro
    Replies: 2
    Last Post: - 14th December 2009, 20:21
  2. Replies: 0
    Last Post: - 1st September 2008, 07:03
  3. Math operations & Syntax?
    By kevj in forum mel PIC BASIC Pro
    Replies: 7
    Last Post: - 23rd February 2008, 01:40
  4. Need help with I2C syntax problem?
    By Michael Wakileh in forum mel PIC BASIC Pro
    Replies: 5
    Last Post: - 19th July 2007, 19:11
  5. Syntax error PIC16F684
    By milestag in forum mel PIC BASIC Pro
    Replies: 1
    Last Post: - 21st September 2005, 18:54

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