How can you address I/O bytes and individual bits via the I/O?
If the bits are to be updated faster than through the process image, you can implement your program with the direct commands PQB, PQW and PQD in the STL editor of STEP 7. However, with these statements you cannot address individual bits via the I/O. For addressing individual bits you must write at least the complete byte to the I/O. If the other bits of the byte are not be to changed, then you must program relevant logical operations according to the change of the bit (TRUE/FALSE). Then you can write the complete byte to the I/O via direct command.
The table below contains examples for addressing a bit field and setting an individual bit in the I/O.
|No.||Examples for I/O addressing:|
|1||Setting the bit field in the I/O area|
By calling and parameterizing SFC 79 "SET" you can set a selected bit field in the I/O area. The parameters must be assigned as shown in the following example (Fig. 01). In this example PQB 4 is set.
Please pay attention to the syntax of the pointer on the "SA" parameter - here there must be the statement "P#Px.y" (pointer to the first bit to be set). If you specify a different area ID or an incorrect address here, STEP 7 doesn't report an error. Upon implementation at runtime however the CPU reports an "area error when writing a parameter".
More information on the system function SFC 79 is also available in the STEP 7 Online Help or in the manual "System Software for S7-300/400 System and Standard Functions", Entry ID: 44240604.
|2||Setting individual bits via the I/O|
The STEP 7 project contains the function FC4, which you use to change a bit and write it directly to the I/O without affecting the other bits. Specifying the output address and the bit to be changed changes the status of that bit according to your specification. Through logic operations in the function only that specific bit is changed. The function then transfers the complete byte to the I/O via direct command.
Di_Com.zip ( 357 KB )
Runnability and test environment:
The examples can be used on all the CPU types of SIMATIC S7-300, S7-400, C7 and WinAC. The following table lists the components that have been used to create this entry and verify the functions described.
|PC platform||Intel(R) Pentium(R) M processor 1.73 GHz, 1.49 GB RAM|
|PC operating system||MS Windows XP SP2|
|Options package S7 PLCSIM||V5.3|
Direct command access