Confused on an IF...THEN decimal # check


Closed Thread
Results 1 to 17 of 17
  1. #1
    Join Date
    Dec 2005
    Location
    Salt Lake City, Ut, USA
    Posts
    108

    Question Confused on an IF...THEN decimal # check

    Hello all,

    I've got my serial comms working great, thanks to all of you! As I'm running my code through the sim, I'm trying to validate the incoming decimal address, with no success. It goes something like this:
    Code:
    hserin [wait("A"),DEC3 boardadd]
                hserout ["Board received A",DEC3 boardadd,13,10]
                IF (boardadd = 000) OR (boardadd > 254) THEN     'THIS IS NOT WORKING!!!!!
                    hserout ["Error: Address ",DEC3 boardadd," not valid! Please use 001 to 254.",13,10]
                else        
                    write 0,boardadd
                    high Progled
                        pauseus 50
                    low progled
                    read 0,boardaddep
                    hserout ["Board address set to ",DEC boardaddep,13,10]
                endif
    The "=000" works, but the ">254" doesn't. The code allows me to enter >254. Am I missing something here, or am I trying to compare 2 different formats? I've tried the following with no success:

    IF (DEC3 boardadd = 000) or (DEC3 boardadd > 254) THEN...

    Hope one of you can help. Thanks a million!
    C

  2. #2
    Join Date
    Nov 2003
    Location
    Wellton, U.S.A.
    Posts
    5,924


    Did you find this post helpful? Yes | No

    Default

    What size of variable is
    boardadd
    ??
    If it is not a WORD size that could be the problem.
    Dave
    Always wear safety glasses while programming.

  3. #3
    Join Date
    Dec 2005
    Location
    Salt Lake City, Ut, USA
    Posts
    108


    Did you find this post helpful? Yes | No

    Default

    It's a byte. That's not ok for 1-256? If that's the case, through your eyes, will I need to change anything else in the code, besides the VAR? Thanks a bunch!
    C

  4. #4
    Join Date
    Dec 2005
    Location
    Salt Lake City, Ut, USA
    Posts
    108


    Did you find this post helpful? Yes | No

    Default

    Sorry, mis-spoke...

    BIT 1 0 to 1
    BYTE 8 0 to 255
    WORD 16 0 to 65535
    LONG* 32 -2147483648 to 2147483647

    My bad...0 to 255

    Thanks again!
    C

  5. #5
    Join Date
    Nov 2003
    Location
    Wellton, U.S.A.
    Posts
    5,924


    Did you find this post helpful? Yes | No

    Default

    A byte is 256 steps starting at 0.

    Not knowing the value of "boardadd" I will make a guess and say changing it to WORD is all you have to do. Pulling the three digits of boardadd, 999 would be the largest number... right?
    Dave
    Always wear safety glasses while programming.

  6. #6
    Join Date
    Dec 2005
    Location
    Salt Lake City, Ut, USA
    Posts
    108


    Did you find this post helpful? Yes | No

    Default

    thanks mackrackit. the BoardAdd is stored in EEPROM 0, with a min value of 001 to a max value of 254. I hope that answers what your trying to ask me?

    Thanks,
    C

  7. #7
    Join Date
    Nov 2003
    Location
    Wellton, U.S.A.
    Posts
    5,924


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by kevlar129bp View Post
    I hope that answers what your trying to ask me?
    That is what little or no sleep does for me, makes me babbble more than usual.

    If 254 is the max then how could this ever happen?
    Code:
     
    IF (boardadd = 000) OR (boardadd > 254) THEN
    As Duncan says "I will get my hat now".
    Dave
    Always wear safety glasses while programming.

  8. #8
    Join Date
    Dec 2005
    Location
    Salt Lake City, Ut, USA
    Posts
    108


    Did you find this post helpful? Yes | No

    Default

    Sorry, I guess I should have noted that this routine checks to make sure you don't try to write an address to EEPROM that is >254 or is =0. So, if a user enters "A280" for example, I want that to be invalid. I hope that helps explain my goal?

    Just tried it in the sim...
    I entered "A300" and it returned with,
    "Board received A044
    Board address set to 44"

    Hopefully you can see what I mean?

    Thanks again,
    C

  9. #9
    Join Date
    Nov 2003
    Location
    Wellton, U.S.A.
    Posts
    5,924


    Did you find this post helpful? Yes | No

    Default

    Ok... Go ahead and change it to a WORD. 44 is what you are getting when it rolls over.
    Dave
    Always wear safety glasses while programming.

  10. #10
    Join Date
    Dec 2005
    Location
    Salt Lake City, Ut, USA
    Posts
    108


    Did you find this post helpful? Yes | No

    Default

    On that note, a word sized var won't flow over into EEPROM 1 will it? I'de like to avoid that if I could.

    Thanks again,
    C

  11. #11
    Join Date
    Nov 2003
    Location
    Wellton, U.S.A.
    Posts
    5,924


    Did you find this post helpful? Yes | No

    Default

    It should not. Your code is making the max 254. The WORD size just lets something bigger, like 300 be seen as 300.
    Dave
    Always wear safety glasses while programming.

  12. #12
    Join Date
    Dec 2005
    Location
    Salt Lake City, Ut, USA
    Posts
    108


    Did you find this post helpful? Yes | No

    Thumbs up

    Thanks Dave! I get where your goin' with that now. I'm going to give it a run. Thanks so much for your help!

    C

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


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by kevlar129bp View Post
    Hello all,

    I've got my serial comms working great, thanks to all of you! As I'm running my code through the sim, I'm trying to validate the incoming decimal address, with no success. It goes something like this:
    Code:
    hserin [wait("A"),DEC3 boardadd]
                hserout ["Board received A",DEC3 boardadd,13,10]
                IF (boardadd = 000) OR (boardadd > 254) THEN     'THIS IS NOT WORKING!!!!!
                    hserout ["Error: Address ",DEC3 boardadd," not valid! Please use 001 to 254.",13,10]
                else        
                    write 0,boardadd
                    high Progled
                        pauseus 50
                    low progled
                    read 0,boardaddep
                    hserout ["Board address set to ",DEC boardaddep,13,10]
                endif
    The "=000" works, but the ">254" doesn't. The code allows me to enter >254. Am I missing something here, or am I trying to compare 2 different formats? I've tried the following with no success:

    IF (DEC3 boardadd = 000) or (DEC3 boardadd > 254) THEN...

    Hope one of you can help. Thanks a million!
    C
    I have a thought . . . Right, wrong or otherwise . . .
    your code . .
    Code:
    IF (boardadd = 000) OR (boardadd > 254) THEN
    have you tried . . . ?
    Code:
    IF (boardadd <1) OR (boardadd > 254) THEN
    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.

  14. #14
    Join Date
    Dec 2005
    Location
    Salt Lake City, Ut, USA
    Posts
    108


    Did you find this post helpful? Yes | No

    Default

    Thanks for your input Joe. If I remember correctly, I tried so many different ways, but to no avail. Although, Dave's solution worked flawlessly so far! Hey guys, without me starting a new thread, I've got 1 more question. This "Master Board" PIC is actually going to be sending serial out to "Daughter" boards with their own PICs. A quick snippet of my code goes like so:

    ...
    case 2
    serout portB.1,n9600,[UpdPinLvl] 'CAT5 JACK 1, PIN 2
    GOTO Start
    ...

    Is this (basically) the correct syntax if the signal does not route through a MAX232? BTW: UpdPinLvl is a 8 bit integer. OK, so 2 questions: Correctness of syntax aside, what is roughly the max distance between Master and Daughter I could expect with driving it TTL?

    Any thoughts would be great!
    C

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


    Did you find this post helpful? Yes | No

    Default

    It's a byte. That's not ok for 1-256?
    No it's not. A byte is OK for 0-255.

    A byte has 256 states... ZERO is one of them.

  16. #16
    Join Date
    Nov 2003
    Location
    Wellton, U.S.A.
    Posts
    5,924


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by kevlar129bp View Post
    ...
    case 2
    serout portB.1,n9600,[UpdPinLvl] 'CAT5 JACK 1, PIN 2
    GOTO Start
    ...

    Is this (basically) the correct syntax if the signal does not route through a MAX232? BTW: UpdPinLvl is a 8 bit integer. OK, so 2 questions: Correctness of syntax aside, what is roughly the max distance between Master and Daughter I could expect with driving it TTL?
    It the variable is a number you may want to consider this from the manual
    A numeric value preceded by a pound sign ( # ) will send the
    ASCII representation of its decimal value. For example, if W0 =
    123, then #W0 (or #123) will send “1", “2", ”3".
    Distance... Depending on the cable, connections, and the amount of noise in the environment, 30 to 50 feet is about the max distance you can expect. Could get a little more, maybe less.
    Dave
    Always wear safety glasses while programming.

  17. #17
    Join Date
    Dec 2005
    Location
    Salt Lake City, Ut, USA
    Posts
    108


    Did you find this post helpful? Yes | No

    Thumbs up

    Thanks guys,
    I think I'll just mess with the daughter board when I have more time...the master board was my main focus, and it's good so far. As for the cabling, I'm an Audio-Video-Security installer, so cat5 is a natural fit for me. This is what I've got so far...so we'll just have to road-test the max limits.
    [IMG]<table style="width:auto;"><tr><td><a href="http://picasaweb.google.com/lh/photo/nK_RiB5vTk6ukG3L5lkzJg"><img src="http://lh6.ggpht.com/_B18XeDRTquI/SUPWW2AHgDI/AAAAAAAAACA/xrDpzvtT7Ik/s144/MOTHERBOARD.jpg" /></a></td></tr><tr><td style="font-family:arial,sans-serif; font-size:11px; text-align:right">From <a href="http://picasaweb.google.com/kevlar129bp/SerialControl">Serial Control</a></td></tr></table>[/IMG]

Similar Threads

  1. HARDWARE I2C SAMPLE CODE question
    By Michael Wakileh in forum Code Examples
    Replies: 2
    Last Post: - 16th June 2009, 21:07
  2. Help for decimal conversion
    By eva in forum mel PIC BASIC Pro
    Replies: 2
    Last Post: - 15th March 2007, 18:20
  3. Code check -- button not working
    By docwisdom in forum mel PIC BASIC Pro
    Replies: 12
    Last Post: - 2nd March 2006, 22:43
  4. 16bit variable and degrees conversion
    By RFsolution in forum mel PIC BASIC Pro
    Replies: 7
    Last Post: - 2nd May 2005, 17:27
  5. Convert a word variable to decimal
    By Tomexx in forum mel PIC BASIC Pro
    Replies: 1
    Last Post: - 4th December 2004, 20:02

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