But, you can an arrays of bytes and 'use' as an array of bits. Then set the bit using FnLsL and an code to determine the BitNum you are going to set and the Byte_adress. As in the buffer(10) use the following.
buffer(Byte_adress) = buffer(Byte_adress) OR FnLSL( 1, BitNum)
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Bit arrays are a bit of an anomaly (no pun intended) as every variable in any computer language is automatically an array of bits. When accessed as ASCII code we call 8 Bits a Char, an 8 bit Number is an Integer, a 16 bit number a word etc. When the individual bits, rather than the data structure are accessed most languages call them a Flag.
GCBasic makes it easier than most other languages to access individual bits with the ‘Var.Bit’ form of reference.
For example if you need to set Pin 7 of a PIC16F690 to High you can use the command:
PortC.3 = 1 ‘ Set Pin7 - RC3 High
Likewise if you need to save an interim Bit value you can do the same with Variables.
MyFlag.4 = PortA.0 ‘Read switch on Pin RA0 and store result
So in order to use a data structure as an array all we need is the ability to specify the bit Number and the bit State as variables, for that we can create a function that expands on what Evan posted:
Using that function BitArray can be any variable, register or Port on the device, BitNum is the Bit to be changed and BitState is the the State (TRUE/FALSE - ON/OFF - 1/0) of the target Bit.
BitNum and BitState may be specified as a constant, variable, expression or function.
The line:
SetBit(PortC, 1+2, 4)
Will light an LED on Pin RC3 because 1+2 evaluates to 3, and 4 is NOT Zero so evaluates as TRUE.
Putting it all together as an test on a PIC16F690:
#chip16f690dimMyBitArrayasbyteDirPortCOutMyBitNum=3MyBitState=1SetBit(MyBitArray,MyBitNum,MyBitState)' set or clear RC0 according to Bit Array valuePortC.0 = GetBit(MyBitArray, MyBitNum) endSub SetBit(BitArray, BitNum, BitState) if BitState then BitArray = BitArray OR FnLSL(1, BitNum) else BitArray = BitArray And FnLSL(0, BitNum) end ifend subFunction GetBit(BitArray, BitNum) Repeat BitNum + 1 Rotate BitArray Right End Repeat GetBit = STATUS.CEnd Function
So in conclusion GCBasic has got bit arrays in that every data structure is a bit array, the two functions above will allow you to access a byte as if it were an 8 element Bit Array passing variable or coinstants as you would any other type of array.
Cheers
Chris
Last edit: Chris Roper 2018-02-02
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
@Chris. It would be very good if you could edit this for inclusion in the Help? Only change would to make make the document talk of the 'third party'. You up for this?
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Thank you all,
I'm trying to do a small multi-task for reading keyboard update display etc. trying to use as few ram as possible, is there any example already done?
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Looked at your demos? ..\GCB@Syn\GreatCowBasic\Demos\KeyPad Solutions\Keypad_Demonstration_with_Hardware_Serial-16F1938.gcb and others in the same folder.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
I like Anobiums idea more. I can work with a rotating mask ok for bit arrays.
Nice thought Chris, I thought about it to but better to understand the idea and do one's own thing.
Gigi, please elaborate "I'm trying to do a small multi-task for reading keyboard update display etc. trying to use as few ram as possible, is there any example already done?" interesting
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
@Anobium@Stan
Great, as always I start something that has already been done.
I saw the library: Time_Based_Task_Switcher_Library001.h It seems just face
in my case. Truly great GCB
MANY THANKS
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Is it possible to create BIT arrays? It always gives me error
Es: Dim Test(10) as bit
You cannot create an array of bits.
But, you can an arrays of bytes and 'use' as an array of bits. Then set the bit using FnLsL and an code to determine the
BitNum
you are going to set and theByte_adress
. As in the buffer(10) use the following.buffer(Byte_adress) = buffer(Byte_adress) OR FnLSL( 1, BitNum)
Bit arrays are a bit of an anomaly (no pun intended) as every variable in any computer language is automatically an array of bits. When accessed as ASCII code we call 8 Bits a Char, an 8 bit Number is an Integer, a 16 bit number a word etc. When the individual bits, rather than the data structure are accessed most languages call them a Flag.
GCBasic makes it easier than most other languages to access individual bits with the ‘Var.Bit’ form of reference.
For example if you need to set Pin 7 of a PIC16F690 to High you can use the command:
Likewise if you need to save an interim Bit value you can do the same with Variables.
So in order to use a data structure as an array all we need is the ability to specify the bit Number and the bit State as variables, for that we can create a function that expands on what Evan posted:
Using that function BitArray can be any variable, register or Port on the device, BitNum is the Bit to be changed and BitState is the the State (TRUE/FALSE - ON/OFF - 1/0) of the target Bit.
BitNum and BitState may be specified as a constant, variable, expression or function.
The line:
Will light an LED on Pin RC3 because 1+2 evaluates to 3, and 4 is NOT Zero so evaluates as TRUE.
A complementary function would read the array:
Putting it all together as an test on a PIC16F690:
So in conclusion GCBasic has got bit arrays in that every data structure is a bit array, the two functions above will allow you to access a byte as if it were an 8 element Bit Array passing variable or coinstants as you would any other type of array.
Cheers
Chris
Last edit: Chris Roper 2018-02-02
@Chris Roper... I like this. Nice explanation!
@Chris. It would be very good if you could edit this for inclusion in the Help? Only change would to make make the document talk of the 'third party'. You up for this?
Thank you all,
I'm trying to do a small multi-task for reading keyboard update display etc. trying to use as few ram as possible, is there any example already done?
Looked at your demos? ..\GCB@Syn\GreatCowBasic\Demos\KeyPad Solutions\Keypad_Demonstration_with_Hardware_Serial-16F1938.gcb and others in the same folder.
I like Anobiums idea more. I can work with a rotating mask ok for bit arrays.
Nice thought Chris, I thought about it to but better to understand the idea and do one's own thing.
Gigi, please elaborate "I'm trying to do a small multi-task for reading keyboard update display etc. trying to use as few ram as possible, is there any example already done?" interesting
@Anobium@Stan
Great, as always I start something that has already been done.
I saw the library: Time_Based_Task_Switcher_Library001.h It seems just face
in my case. Truly great GCB
MANY THANKS