Help on using sbit type

General discussion on mikroBasic PRO for dsPIC30/33 and PIC24.
Post Reply
Author
Message
robmar
Posts: 13
Joined: 15 Oct 2014 07:10

Help on using sbit type

#1 Post by robmar » 06 Nov 2021 09:17

Hi all,
Due to my limited programming experience, I always get stuck in pointer issues... :mrgreen:

In detail, I know that
dim my_bit as sbit at LATB0_bit
....
my_bit = 1

is a valid and working construction.

Now I would need to create an array of pointers to a list of port bits, in order to access them with an index, like in (well, sort of...)
dim my_bit as sbit[3] at (LATB0_bit, LATE1_bit, LATG7_bit)
so to be able to do (sort of...)
my_bit[1] = 1

Now, I know that the above construction is awfully wrong, :( I tried fiddling with ^ and @ operators but I couldn't find a working syntax in order to accessing port bits "arrays" with an index.

Any suggestion? Thanks so much in advance!

Levi
Posts: 55
Joined: 01 Mar 2008 20:27

Re: Help on using sbit type

#2 Post by Levi » 06 Nov 2021 10:18

Hi,

Check in the help file of the compiler section "Accessing Individual Bits"
Reagrds,
Levi

robmar
Posts: 13
Joined: 15 Oct 2014 07:10

Re: Help on using sbit type

#3 Post by robmar » 06 Nov 2021 10:37

Levi wrote:
06 Nov 2021 10:18
Hi,

Check in the help file of the compiler section "Accessing Individual Bits"
Reagrds,
Levi
Yes, thanks, I did it already, but I got no clue on how to apply the sbit definition to an array of port pointers... :(
This is the actual issue and request for help :)

Levi
Posts: 55
Joined: 01 Mar 2008 20:27

Re: Help on using sbit type

#4 Post by Levi » 06 Nov 2021 11:38

Hi,
I don't understand exactly what do you mean by array of ports pointers .
Do you mean this?
stat = 0
for i = 0 to 9
stat = portb.i
next i

Regards,
Levi

robmar
Posts: 13
Joined: 15 Oct 2014 07:10

Re: Help on using sbit type

#5 Post by robmar » 06 Nov 2021 17:55

Levi wrote:
06 Nov 2021 11:38
Hi,
I don't understand exactly what do you mean by array of ports pointers .
Do you mean this?
stat = 0
for i = 0 to 9
stat = portb.i
next i

Regards,
Levi
Hi Levi,
Sorry for not being that much clear, imagine that i want to set the bits of, say,
porta.0, portb.3 and portc.7

much like a sort of: (of course the following is awfully not correct)
const my_var as sbit[3] = (@porta.0, @portb.3, @portc.7)
so that that upon setting my_var[1] = 1, actually portb.3 is set.

Or in any other way where an index from 1 to n can address the n ports and bits, the constraint being that the ports and bits have not to be contiguous, like in your example, but arbitrarily defined in a list (or array, or structure...)

Sorry again, the confusion in my head is evident :cry:
Thanks,
Roberto

Levi
Posts: 55
Joined: 01 Mar 2008 20:27

Re: Help on using sbit type

#6 Post by Levi » 07 Nov 2021 08:26

Hi Roberto,
As I know there is no way to create arrays with sbit and bit types :wink: .A workaround of what you need is a function I think

dim my_var as byte[3]

my_var[0]=0x01
my_var[1]=0x01
my_var[2]=0x00

porta.0= my_var[0].0
portb.3= my_var[1].0
portc.7= my_var[2].0


Regards,
Levi

Post Reply

Return to “mikroBasic PRO for dsPIC30/33 and PIC24 General”