ST 编写锁存器、8位寄存器程序

FUNCTION_BLOCK FB_write_bit
VAR_INPUT
	bBitIn:BOOL;
	bWrite:BOOL;
END_VAR
VAR_OUTPUT
	bBitState:BOOL;
END_VAR
VAR
END_VAR
bBitState:=((bBitIn AND bWrite) OR bBitState) AND (NOT (NOT bBitIn AND bWrite));
FUNCTION_BLOCK FB_write_byte
VAR_INPUT
	nByteIn:BYTE;
	bWrite:BOOL;
END_VAR
VAR_OUTPUT
	nByteState:BYTE;
END_VAR
VAR
	fb_write_bit:ARRAY[0..7] OF FB_write_bit;
END_VAR
THIS^.fb_write_bit[0](bBitIn:=nByteIn.0 , bWrite:=bWrite , bBitState=>nByteState.0 );
THIS^.fb_write_bit[1](bBitIn:=nByteIn.1 , bWrite:=bWrite , bBitState=>nByteState.1 );
THIS^.fb_write_bit[2](bBitIn:=nByteIn.2 , bWrite:=bWrite , bBitState=>nByteState.2 );
THIS^.fb_write_bit[3](bBitIn:=nByteIn.3 , bWrite:=bWrite , bBitState=>nByteState.3 );
THIS^.fb_write_bit[4](bBitIn:=nByteIn.4 , bWrite:=bWrite , bBitState=>nByteState.4 );
THIS^.fb_write_bit[5](bBitIn:=nByteIn.5 , bWrite:=bWrite , bBitState=>nByteState.5 );
THIS^.fb_write_bit[6](bBitIn:=nByteIn.6 , bWrite:=bWrite , bBitState=>nByteState.6 );
THIS^.fb_write_bit[7](bBitIn:=nByteIn.7 , bWrite:=bWrite , bBitState=>nByteState.7 );

你可能感兴趣的:(codesys,TwinCAT,3,st)