curlyandshemp
Lifetime Supporting Member
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
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