S7300 Indirect addressing of MBs

curlyandshemp

Lifetime Supporting Member
Join Date
Jul 2005
Location
Toronto
Posts
1,903
Sorry if that has been posted before, but I cannot find an answer to my problem.

I am trying to access a Flag Byte MBXX in a Function call. My application passes an INT value as an IN parameter that represents the MB that the function needs to call. Within the called function, certain bits are tested for their current state , MBXX.0 - MBXX.7, then the results of a particular test are passed back as an OUT.

For the life of me, I cannot get this to work. According to the Step7 documentation i should be able to use the following code:


L #dest_ptr // INT value of dest route to access 11 - 19
L 10 // route 11 to 19 status are in MB21 - MB29
+I // create an offset to point to actual MB
T #mb_ptr // transfer to a DWORD that contains MB#

L MB[#mb_ptr] // load the contents of MBXX
T MB1000 // transfer to working MB1000

A MB1000.7 // test for machine OFFLINE bit
= #offline // Bool OUT value macine OFFLINE

BEU // exit


Is the above code valid, or am I missing something?

Thanks
Ian
 
The DWORD format has the right hand 3 bits as the bit address. Take your code.

L #dest_ptr // INT value of dest route to access 11 - 19
L 10 // route 11 to 19 status are in MB21 - MB29

+I // create an offset to point to actual MB

This is adding 10 to byte address, if for example #dest_ptr came in as 14, it now = 24.

You now need to shift the DWORD left by 3 to make it a pointer format.

SLD3
T #mb_ptr // transfer to a DWORD that contains MB#
L MB[#mb_ptr] // load the contents of MBXX
T MB1000 // transfer to working MB1000


A MB1000.7 // test for machine OFFLINE bit
= #offline // Bool OUT value macine OFFLINE

BEU // exit

This could be done slightly different.

L #dest_ptr // INT value of dest route to access 11 - 19
L 10 // route 11 to 19 status are in MB21 - MB29
+I // create an offset to point to actual MB
SLD 3
L DW#16#7
AD
T #mb_ptr // transfer to a DWORD that contains MB#



A M[#mb_ptr] // load the contents of MBXX
= #offline // Bool OUT value macine OFFLINE

BEU // exit
 
Another method you may find useful.

L #dest_ptr // INT value of dest route to access 11 - 19
L 10 // route 11 to 19 status are in MB21 - MB29
+I // create an offset to point to actual MB

SLD3 // Change it to pointer format
LAR1 // and put in Address Register 1

A M[AR1, P#0.0] // = bit 0 of address
A M[AR1, P#0.1] // = bit 1 of address
A M[AR1, P#0.2] // = bit 2 of address
A M[AR1, P#0.3] // = bit 3 of address
A M[AR1, P#0.4] // = bit 4 of address
A M[AR1, P#0.5] // = bit 5 of address
A M[AR1, P#0.6] // = bit 6 of address
A M[AR1, P#0.7] // = bit 7 of address

By putting it in the address register, you can quickly access the individual bits by using the P# offset.

As a matter of fact you don't even need to add the 10:

L #dest_ptr // INT value of dest route to access 11 - 19
SLD3 // Change it to pointer format
LAR1 // and put in Address Register 1

A M[AR1, P#10.0] // = bit 0 of address
A M[AR1, P#10.1] // = bit 1 of address
A M[AR1, P#10.2] // = bit 2 of address
A M[AR1, P#10.3] // = bit 3 of address
A M[AR1, P#10.4] // = bit 4 of address
A M[AR1, P#10.5] // = bit 5 of address
A M[AR1, P#10.6] // = bit 6 of address
A M[AR1, P#10.7] // = bit 7 of address

As the P# offset allows you to offset bytes as well as words.
 
Last edited:
It should be OD instead of AD

PeterW said:

This could be done slightly different.

L #dest_ptr // INT value of dest route to access 11 - 19
L 10 // route 11 to 19 status are in MB21 - MB29
+I // create an offset to point to actual MB
SLD 3
L DW#16#7
AD
T #mb_ptr // transfer to a DWORD that contains MB#



A M[#mb_ptr] // load the contents of MBXX
= #offline // Bool OUT value macine OFFLINE

BEU // exit
 
Thanks Peter ,

I will give it a try on Tuesday morning. It's a long weekend here in Canada, Labour Day, don't know if they have that over in the UK or not.

I have a strong Siemens S5 and AB background, but am relatively new to the S7 world. I have been spoiled by the very intuitive and user friendly programming software packages of the AB product line and I have been struggling with the online help and suppport for the S7-300 family.

Ian
 

Similar Topics

How can I integrate my S7-300 Simatic with the IFM AS-i Master AC1335 and its slave IOs, such as 2411 and Airbox 2041, into Simatic Manager?
Replies
0
Views
116
Hello everyone, One of our machine we use Siemens Cpu315-2dp. And this cpu communicate with 4 Lenze servo drives series 9300 via profibus. Also...
Replies
0
Views
179
Hi guys, I'm having problems converting WinAC (WinLC RTF F application) to S7 300 project based on CPU 319F-3PN or S7 400/416F-3PN. The problem is...
Replies
0
Views
615
Hi Any one here please helpmein simulation of s7 300 plc program with factory io. how to connect. plcsim 5 doesnot have option of s7 300 ..:
Replies
2
Views
1,010
Hi to all, Our company does not usually use Siemens PLCs, but have a press with one in it. We are trying to change the IP address in our Simatic...
Replies
2
Views
1,068
Back
Top Bottom