PDA

View Full Version : IF..AND/OR..THEN and PBPL



duncan303
- 25th January 2008, 14:02
hi all,
I have just been caught out introducing PBPL into some older code, I have prepared an example which demonstates the observation.

This demo is on an 18F4520 PBP 2.5 MCSP 3.0.0.5.


define OSC 16


'---------------------------- debug defines -----------------------------------

DEFINE DEBUG_REG PORTB
DEFINE DEBUG_BIT 5
DEFINE DEBUG_BAUD 38400
DEFINE DEBUG_MODE 0
'-------------------------------------------------------------------------------




W0 var word
W1 var word(8)
Counter var byte
Index var byte
Sum Var word

Counter = 0
Sum = 0



Start:
w1[0] = 567
w1[1] = 568
w1[2] = 566
w1[3] = 566
w1[4] = 568
w1[5] = 586
w1[6] = 567
w1[7] = 567


w0 = w1[0] 'place first value of w1array into W0 to be able to compare against it
for index = 1 to 7
if w1[index] < (w0 - 2) or w1[index] > (w0 + 2) then

debug #w1[index]," Value out of range" ,10

else
Sum = Sum + w1[index]
Counter = Counter + 1
debug #w1[index]," within range ",10
endif
next index

pause 1000
goto start

END

If this code is compiled using PBP the IF...AND...THEN routine works perfectly, but if you compile with PBPL then it fails. Is it possible that there some additional fuses I should be setting when converting from PBP to PBPL?

I have found that using the AND/OR in an IF..THEN statement is very code hungry so I try not to use it that often. But I was not expecting this problem at all, took me quite a long time to find it and even then it did not occur to me it was associated with PBPL

Duncan

skimask
- 25th January 2008, 14:13
if w1[index] < (w0 - 2) or w1[index] > (w0 + 2) then

Duncan

I believe that's similar to a problem I had a couple of months ago. There's a simple fix in one of the PBPL macro files for it, but I'm at work and don't have it handy. Involves changing a CT to BT or something along those lines. It's not the AND/OR that causes the problems, it's the index'ing part of the problem. I just don't remember what it is...
If you don't get a fix from MeLabs or have it posted here when I get home today, I'll post the fix in a fresh thread....(I know...should've done that weeks ago...)

Besides that...


w1 var word(8)

should be


w1 var word[8]

duncan303
- 25th January 2008, 14:45
Thanks Skimask,

I did not think to check melabs for a patch :(

I downloaded the patch and the issue has gone away :)


I seem to always think that it is me that is doing something wrong, a confidence issue.

At least I am up to speed with that code now , so I am considering making some improvements whilst I know what is going on.

Maybe we should all be on an email mailing list at melabs for announcements and patches, after all everybody and thier father are trying to bombard me with stuff I do not want or have never heard of before. Why not things I should be kept up to date with?

Thanks again

duncan

skimask
- 25th January 2008, 14:50
Thanks Skimask,
I did not think to check melabs for a patch :(
I downloaded the patch and the issue has gone away :)
I seem to always think that it is me that is doing something wrong, a confidence issue.
At least I am up to speed with that code now , so I am considering making some improvements whilst I know what is going on.
Maybe we should all be on an email mailing list at melabs for announcements and patches, after all everybody and thier father are trying to bombard me with stuff I do not want or have never heard of before. Why not things I should be kept up to date with?
Thanks again
duncan

The patch fixes a few things...
The issue I was talking about is a bit different (deals with variables and constants inside the brackets, easy workaround, but still broken). I found a piece of paper here at work, under another pile at my desk with notes on it. The issue I found is a very small issue and I'd doubt highly somebody else will come across it and cause them a headache also.
Most patches and issues are posted here in one way or another, but, as I've found, I just go back to MeLabs site once in awhile just to see what's up. Works for me, and keeps down the overall email traffic :)

duncan303
- 25th January 2008, 15:31
Yes I accept that it would probably be better to keep the overall email traffic down.

I am not on PBP every day so it might be helpfull for somebody like me. I have to admit that I do tend to leave major upgrades either hardware or software for as long as possible to try a keep a longer period of stability to work in. Therefore I should check regularily for patches.

As to the syntax........ well spotted. I just checked the new and old manuals to see where I have got it into my head to use ( ) in defining an array. It is certainly not there. I seem to have used it like that for years, obviously a bad habit......... but not any more :D

Duncan

skimask
- 25th January 2008, 16:45
As to the syntax........ well spotted. I just checked the new and old manuals to see where I have got it into my head to use ( ) in defining an array. It is certainly not there. I seem to have used it like that for years, obviously a bad habit......... but not any more :D
Duncan

QBASIC? :D
GW-BASIC? :)