PDA

View Full Version : ShiftIn to array of bits using EXT modifier?



HenrikOlsson
- 10th March 2011, 18:38
Hi,
I have an array of bits (MB_Inputs) to which I want to shift in data from an external device. After trying a couple of different things without luck I came to think of Darrels writeup on the EXT modifier (http://www.picbasic.co.uk/forum/showthread.php?t=3891#TYP) and thought I'd give that a try:

DataIn VAR WORD EXT
@DataIn = _MB_Inputs
and then later on

ShiftIn PortB.0, PortB.1, 0, [DataIn \16]
This actually seems to work but when compiling I get an assmebler error 108, Illegal character (,) on line 1532 in the ASM file, that particular line is:

DataIn = _MB_Inputs


Questions:
1) Any idea why I get the error? I hope it's not the underscore "inside" my variable name...
2) Since it, despite the error message, seems to work on the target should I just disregard the error? (Hard to do but I guess I can be convinced)
3) Any other way of shifting data directly into an array of bits using ShiftIn?

I know this may look weird as I could just as well have used a WORD to begin with but it is what it is.

Thanks!
/Henrik.

Darrel Taylor
- 11th March 2011, 14:40
Hi Henrik,

BYTE and WORD variables only have one value that is a pointer to an address in RAM.

But BIT's and BIT arrays have two parameters ... the address, and a pointer to the bit in that address, because PBP can combine BIT arrays into single bytes if they are small enough. This makes it difficult to locate the beginning of the array since MyBitArray(0) may start at bit5 of the byte it's located in. These are located in PB01 type variables that PBP creates.

Fortunately, if the BIT array is more than 8 bits, PBP will will create a PBA01 type variable and the first bit will always start at bit0.

In ASM, a BIT array is aliased like this ...
#define _MB_Inputs PBA01,0

You have to strip off the ,0 to be able to assign it to an EXT var.


MB_Inputs VAR BIT[16]
DataIn VAR WORD EXT

@ #define Reg(Areg,Abit) Areg
@DataIn = Reg(_MB_Inputs)


The #define creates a "function" that only returns the register part of the BIT alias.
So DataIn will be assigned to PBA01 without the ,0.

HTH,

.

HenrikOlsson
- 12th March 2011, 14:30
Thanks Darrel!
Looks like it's working :-)
So, as long as the array of bits is longer than 8 this method is safe to use, nice to know!

/Henrik.