 FP_DIV_MOD_BCD
FP_DIV_MOD_BCDBCD data division with remainder
This FP instruction divides the BCD data specified by s1 by s2 if the trigger EN is TRUE. The integer quotient is stored in d1_Div and the remainder in d2_Mod.

Input
Dividend
Divisor
Output
Integer quotient
Remainder

All input and output variables used for programming this function have been declared in the POU header. The same POU header is used for all programming languages.

	VAR
		bStart: BOOL:=FALSE;
			(*activates the fuction*)
		dwDividend: DWORD:=16#442201;
			(*dividend*)
		dwDivisor: DWORD:=16#2;
			(*divisor*)
		dwResult: DWORD:=0;
			(*result after a 0->1 leading
edge from start: 16#221100*)
		dwRemainder: DWORD:=0;
			(*remainder: 16#1*)
	END_VAR
When the variable bStart is set to TRUE, the function is carried out.

BODY
    WORKSPACE
        NETWORK_LIST_TYPE := NWTYPELD ;
        ACTIVE_NETWORK := 0 ;
    END_WORKSPACE
    NET_WORK
        NETWORK_TYPE := NWTYPELD ;
        NETWORK_LABEL :=  ;
        NETWORK_TITLE :=  ;
        NETWORK_HEIGHT := 7 ;
        NETWORK_BODY
B(B_CONTACT,,bStart,4,2,6,4,);
B(B_VAROUT,,dwDividend,9,4,11,6,);
B(B_VARIN,,dwDivisor,6,4,8,6,);
B(B_VAROUT,,dwResult,18,3,20,5,);
B(B_F,FP_DIV_MOD_BCD!,,8,1,18,6,,?DEN?D@'s1'?Ds2?AENO?Cd1_Div?Cd2_Mod);
B(B_VAROUT,,dwRemainder,18,4,20,6,);
B(B_VARIN,,dwDividend,6,3,8,5,);
L(1,3,4,3);
L(6,3,8,3);
L(1,0,1,7);
        END_NETWORK_BODY
    END_NET_WORK
END_BODY
IF (bStart) then
    FP_DIV_MOD_BCD(s1 := dwDividend, 
                   s2 := dwDivisor, 
                   d1_Div => dwResult, 
                   d2_Mod => dwRemainder);
END_IF;