S7 Indirect bit addressing

curlyandshemp

Lifetime Supporting Member
Join Date
Jul 2005
Location
Toronto
Posts
1,903
Forgive me if this has been posted before, but I have done a quick search of the forum and could not find a quick answer.

I have an S7-300 PLC application, where I am creating a FC that sets a bit in an indirectly addressed Mbyte. I have created a Function where as parameters I pass the address of the Mbyte to access and another parameter to determine which bit to set in the indirectly addressed Mbyte. The parameter of which bit to access is qualified to be between 1 - 8 meaning I am setting bit 0 - 7 in the Mbyte.

Currently I have the FC test which bit to set and then jump to a label that sets that bit. There must be a way to access bits indirectly.

...
L #machine // load machine #
L 40 // offset to access MB4X
+I
SLD 3 // setup for MB pointer
LAR1 // AR1 contains pointer to MB4X

L #bit // load bit # to set
...
ju one // jump to bit 1 = MBXX.0
ju two // jump to bit 2 = MBXX.1
ju thre // jump to bit 3 = MBXX.2
ju four // jump to bit 4 = MBXX.3
ju five // jump to bit 5 = MBXX.4
ju six // jump to bit 6 = MBXX.5
ju sevn // jump to bit 7 = MBXX.6
ju eigh // jump to bit 8 = MBXX.7
...

one: AN M[AR1,#P0.0] // set bit 0
S M[AR1,P#0.0]
BEU
two: AN M[AR1,P#0.1] // set bit 1
S M[AR1,P#0.1]
BEU
thre:AN M[AR1,P#0.2] // set bit 2
S M[AR1,P#0.2]
BEU
.....

Thanks
Ian
 
You code may be simplified as follows.
after:
SLD 3
type:
L #bit // load bit number (range 1..8)
+ -1 // decrease bit number by 1 (now 0..7)
+D // add bit offset to byte pointer
LAR1 // load bit pointer to AR1 (points to MXX.(bit-1))
SET // set RLO to 1
S M[AR1,P#0.0] // set desired bit to 1
 

Similar Topics

I have to check 1024 (sequential) bits for change of state in any of the bits and record which bit changed. I was going to do something like...
Replies
9
Views
4,445
I use a lot of indirect addressing in my programs. In a Rockwell Logix500 (Micro, SLC500, etc..) system, indirect addressing of bits is pretty...
Replies
1
Views
4,478
Howdy folks, I am an Allen Bradley guy currently living in an Emerson world. Working with Rx3i on PacSystems Machine Edition v. 9.6? i think...
Replies
3
Views
577
Hey, I'm trying to do the following, I have some experience with Citect but can't seem to figure this out. I/O Tag: BoxPos1_ProdNum (Data Type...
Replies
0
Views
554
Hello, I'm very new to programming with absolutely zero schooling in this field and pretty hands off training in my new role, it's been fun...
Replies
4
Views
649
Back
Top Bottom