PDA

View Full Version : Confused on an IF...THEN decimal # check



kevlar129bp
- 15th December 2008, 21:18
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:

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

mackrackit
- 15th December 2008, 21:24
What size of variable is
boardadd
??
If it is not a WORD size that could be the problem.

kevlar129bp
- 15th December 2008, 21:27
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

kevlar129bp
- 15th December 2008, 21:31
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

mackrackit
- 15th December 2008, 21:35
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?

kevlar129bp
- 15th December 2008, 21:41
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

mackrackit
- 15th December 2008, 21:58
I hope that answers what your trying to ask me?

:D 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?


IF (boardadd = 000) OR (boardadd > 254) THEN

As Duncan says "I will get my hat now".

kevlar129bp
- 15th December 2008, 22:10
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

mackrackit
- 15th December 2008, 22:19
Ok... Go ahead and change it to a WORD. 44 is what you are getting when it rolls over.

kevlar129bp
- 15th December 2008, 22:24
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

mackrackit
- 15th December 2008, 22:29
It should not. Your code is making the max 254. The WORD size just lets something bigger, like 300 be seen as 300.

kevlar129bp
- 15th December 2008, 22:38
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

Archangel
- 16th December 2008, 01:15
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:

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 . .


IF (boardadd = 000) OR (boardadd > 254) THEN

have you tried . . . ?


IF (boardadd <1) OR (boardadd > 254) THEN

kevlar129bp
- 16th December 2008, 01:46
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

Melanie
- 16th December 2008, 07:35
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.

mackrackit
- 16th December 2008, 12:46
...
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.

kevlar129bp
- 16th December 2008, 14:20
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.
<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>