View previous topic :: View next topic |
Author |
Message |
Deanus
Joined: 26 May 2006 Posts: 188 Location: Adelaide
|
Posted: Tue Feb 21, 2012 7:39 am Post subject: Retting Resetting BITS, Lots of them |
|
|
Hi Guys,
I have the need to set and reset lots of bits.
Each bit correcponds to a menu if items
Eg:
MenuItem1 Bit1
MenuItem2 Bit2
MenuItem3 Bit3
MenuItem4 Bit4
To as many as is required menu Items and the associated bits.
The menu items are held in an array and requires a bit for each (to enable or disable a test or function)
The array system does not support bits, So I endeavored to write a sub that looked for the bit you wish to
set/reset, figured out which byte the bit was in, and did the set / reset.
I had set up an array of bytes.
Dim Bitbyte(4) As Byte
Dim Ln As Byte
'Load Ram variables from EEprom
Bitbyte(1) = 0
Bitbyte(2) = 0
Bitbyte(3) = 0
Bitbyte(4) = 0
In the process of trying various ways of doing this, I accidentally forgot to change the byte number
and ended up with a command like
toggle bitbyte(1).13
and to my surprise, it worked.
So I wrote the following small routine to try it out, and it too works.
It goes through 32 bits setting,printing to terminal and resetting & printing to terminal.
Since I can't find any mention of this on the Net or Bascom help files, (bit setting in bytes, yes, but not bits in other bytes)
I guess my question is to Albert or any of you guys that know Bascom inside out.
Is this a legal Bascom way of bit setting and resetting.
I have already put it in my program (an 8535) and it seems to work a treat, just don't know whether it might play funny buggers down the track.
I would just like to add that I am impressed with all people on this forum that spend time helping the masses to achieve their goals
with the minimum fuss, and I thank you all.
Test code below.
(don't forget to turn Terminal on to see the results)
$regfile = "8535DEF.dat"
$crystal = 8000000
$hwstack = 20 ' default use 32 for the hardware stack
$swstack = 40 ' default use 10 for the SW stack
$framesize = 40 ' default use 40 for the frame space
$sim
Dim Bitbyte(4) As Byte '=32 bits
Dim Ln As Byte
'Load Ram variables from EEprom
Bitbyte(1) = 0
Bitbyte(2) = 0
Bitbyte(3) = 0
Bitbyte(4) = 0
Bitbyte(1).14 = 1
For Ln = 1 To 32
Bitbyte(1).ln = 1
Print Ln ; " " ; Bitbyte(1).ln ; " "; ' Notice in all four lines within the fornext, the byte is ALWAYS Bitbyte(1)
Bitbyte(1).ln = 0 ' the .LN is the bit number up to 32 bits in this example
Print Bitbyte(1).ln
Next
Do
Loop |
|
Back to top |
|
|
albertsm
Joined: 09 Apr 2004 Posts: 5913 Location: Holland
|
Posted: Tue Feb 21, 2012 11:52 am Post subject: |
|
|
yes the bit works on all integer numeric variables.
you can have a bit array of 0-31 when you use a long :
dim L as Long
L.0=1
set L.31
dim idx as byte
reset L.idx _________________ Mark |
|
Back to top |
|
|
Deanus
Joined: 26 May 2006 Posts: 188 Location: Adelaide
|
Posted: Tue Feb 21, 2012 11:52 pm Post subject: |
|
|
Excellent, thanks Mark
Deanus |
|
Back to top |
|
|
MWS
Joined: 22 Aug 2009 Posts: 2262
|
|
Back to top |
|
|
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum You cannot attach files in this forum You cannot download files in this forum
|
|