diff -r 98fc461e1888 -r 8d36d1f81170 lib/bistable.txt --- a/lib/bistable.txt Mon Apr 04 11:19:48 2011 +0100 +++ b/lib/bistable.txt Mon Apr 04 14:32:21 2011 +0100 @@ -1,21 +1,28 @@ (* - * (c) 26 Feb 2001 David Campbell + * matiec - a compiler for the programming languages defined in IEC 61131-3 * - * 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. + * Copyright (C) 2011 Mario de Sousa (msousa@fe.up.pt) * - * 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 program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 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. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + * * * 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. + * An IEC 61131-3 compiler. * * Based on the * FINAL DRAFT - IEC 61131-3, 2nd Ed. (2001-12-10) @@ -31,35 +38,42 @@ * ------------------------- *) +(* The standard defines the SR FB thus: + + +-----+ +S1----------------| >=1 |---Q1 + +---+ | | + R------O| & |----| | + Q1------| | | | + +---+ +-----+ +*) FUNCTION_BLOCK SR VAR_INPUT - S1 : BOOL; - R : BOOL; + S1, R : BOOL; END_VAR VAR_OUTPUT Q1 : BOOL; END_VAR - VAR - Q_INTERNAL : BOOL; - END_VAR + Q1 := S1 OR ((NOT R) AND Q1); +END_FUNCTION_BLOCK - Q_INTERNAL := S1 OR ( Q_INTERNAL AND (NOT R)); - Q1 := Q_INTERNAL; -END_FUNCTION_BLOCK + +(* The standard defines the RS FB thus: + +---+ +R1----------------O| & |---Q1 + +-----+ | | +S-------| >=1 |----| | +Q1------| | | | + +-----+ +---+ +*) FUNCTION_BLOCK RS VAR_INPUT - S : BOOL; - R1 : BOOL; + S, R1 : BOOL; END_VAR VAR_OUTPUT Q1 : BOOL; END_VAR - VAR - Q_INTERNAL : BOOL; - END_VAR - - Q_INTERNAL := (NOT R1) AND (S OR Q_INTERNAL); - Q1 := Q_INTERNAL; + Q1 := (NOT R1) AND (S OR Q1); END_FUNCTION_BLOCK