lib/bcd_to_int.txt
author etisserant
Tue, 15 May 2007 09:52:38 +0200
changeset 27 667721cf52c5
parent 0 fb772792efd1
permissions -rwxr-xr-x
Now, stage4out can address files. Generate_cc have been split into one visitor per C file : pous, ressource and config. Work in progress.
(*
 * (c) 2003 Mario de Sousa
 *
 * Offered to the public under the terms of the GNU General Public License
 * as published by the Free Software Foundation; either version 2 of the
 * License, or (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful, but
 * WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General
 * Public License for more details.
 *
 * This code is made available on the understanding that it will not be
 * used in safety-critical situations without a full and competent review.
 *)

(*
 * An IEC 61131-3 IL and ST compiler.
 *
 * Based on the
 * FINAL DRAFT - IEC 61131-3, 2nd Ed. (2001-12-10)
 *
 *)

(*
 * This is part of the library conatining the functions
 * and function blocks defined in the standard.
 *
 * Conversion from BCD
 * -------------------
 *)



FUNCTION BYTE_BCD_TO_USINT: USINT
  VAR_INPUT
    BCD : BYTE;
  END_VAR

  BYTE_BCD_TO_USINT := BCD MOD 16;
  BCD := BCD / 16;
  BYTE_BCD_TO_USINT := BYTE_BCD_TO_USINT + 10*BCD;
END_FUNCTION




FUNCTION WORD_BCD_TO_UINT: UINT
  VAR_INPUT
    BCD : WORD;
  END_VAR

  WORD_BCD_TO_UINT := BCD MOD 16;
  BCD := BCD / 16;
  WORD_BCD_TO_UINT := WORD_BCD_TO_UINT + 10*(BCD MOD 16);
  BCD := BCD / 16;
  WORD_BCD_TO_UINT := WORD_BCD_TO_UINT + 100*(BCD MOD 16);
  BCD := BCD / 16;
  WORD_BCD_TO_UINT := WORD_BCD_TO_UINT + 1000*BCD;
END_FUNCTION




FUNCTION DWORD_BCD_TO_UDINT: UDINT
  VAR_INPUT
    BCD : DWORD;
  END_VAR

  DWORD_BCD_TO_UDINT := BCD MOD 16;
  BCD := BCD / 16;
  DWORD_BCD_TO_UDINT := DWORD_BCD_TO_UDINT + 10*(BCD MOD 16);
  BCD := BCD / 16;
  DWORD_BCD_TO_UDINT := DWORD_BCD_TO_UDINT + 100*(BCD MOD 16);
  BCD := BCD / 16;
  DWORD_BCD_TO_UDINT := DWORD_BCD_TO_UDINT + 1000*(BCD MOD 16);
  BCD := BCD / 16;
  DWORD_BCD_TO_UDINT := DWORD_BCD_TO_UDINT + 1_0000*(BCD MOD 16);
  BCD := BCD / 16;
  DWORD_BCD_TO_UDINT := DWORD_BCD_TO_UDINT + 10_0000*(BCD MOD 16);
  BCD := BCD / 16;
  DWORD_BCD_TO_UDINT := DWORD_BCD_TO_UDINT + 100_0000*(BCD MOD 16);
  BCD := BCD / 16;
  DWORD_BCD_TO_UDINT := DWORD_BCD_TO_UDINT + 1000_0000*BCD;
END_FUNCTION




FUNCTION LWORD_BCD_TO_ULINT: ULINT
  VAR_INPUT
    BCD : LWORD;
  END_VAR

  LWORD_BCD_TO_ULINT := DWORD_BCD_TO_UDINT(BCD MOD (256*256*256*256));
  BCD := BCD / (256*256*256*256);
  LWORD_BCD_TO_ULINT := LWORD_BCD_TO_ULINT + 1_0000_0000*DWORD_BCD_TO_UDINT(BCD);
END_FUNCTION