⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 tiny_plc.txt

📁 单片PLC,AT2581实现梯形图功能,可作为参考
💻 TXT
📖 第 1 页 / 共 4 页
字号:
               than a preset limit, set output to TRUE.  The timer is NOT
               reset when the line is FALSE, a RST must be used.

      -[RTF]-  Measure cumulative time that line is FALSE.  If this is more
               than a preset limit, set output to TRUE.  The timer is NOT
               reset when the line is TRUE, a RST must be used.

      -[RST]-  If the line is TRUE, reset a timer or a counter.

      There is a TIMER associated with a TMT, TMF, RTT, and RTF.  In
      addition, the preset limit is a CONSTANT in the range of 0 to 65535,
      which is a time in 1ms increments.

      For purposes of checking timers ANDing the timer with 1 will provide
      the enabled status (i.e.  T0 & 1 checks to see if the node using timer
      0 is being fed the appropriate TRUE or FALSE to enable the timer),
      ANDing the timer with 2 will provide the active status (i.e.  T0 & 2
      checks to see if timer is 0 running), ANDing the timer with 4 will
      provide the done status (i.e.  T0 & 4 checks to see if the timer is
      expired).

      The operand of RST must be a COUNTER or a TIMER.

   Miscellaneous Operations:
      -[INV]-  Invert the TRUE/FALSE value of the line.

      -(JMP)-  If the line is TRUE, skip all processing between the JMP and
               the associated LBL.

      -[LBL]-  The target of a JMP.  This MUST be the first node on a line.

      -[OSR]-  If the line has just made a FALSE to TRUE transition, set
               output to TRUE else FALSE.

      JMP must specify a LABEL (L000 to L255).

      A LBL (label) MUST be the FIRST node on a line, and cannot be on an OR
      branch.

      A OSR has a ONESHOT register associated with it.  Reusing a ONESHOT is
      a bad idea.

   OR Branches:
      An OR branch represents an alternative processing path whose value
      also affects the line value.

      An OR branch may have an OR branch, but the OR branch cannot be
      connected to the first or last node on an OR branch.

      For example:

      ---+-------------------+-----
         |                   |
         +-------------------+
         ^          ^        ^
         |          |        |
         |          |        +-- An OR branch my not be placed here
         |          +----------- An OR branch may be placed here
         +---------------------- An OR branch may not be placed here

      The OR branch tool is selected by left-clicking on the  -------
                                                              |     |
                                                               -----
      menu element, and then left-clicking on a line to "drop" the OR branch.
      The initial length of an OR branch is one node.  Right-click the mouse
      to drop the OR branch tool.

      To expand an OR branch, select the Expand tool by left-clicking on the
          ---------
          |     |
           ------>
      menu element, and the left-clicking on the OR branch to expand.
      The OR branch will not expand if:
         it is already as long as its parent OR branch
      or
         the node it would expand into is already occupied by an operand
      Right-click the mouse to drop the Expand tool.

      OR branches are evaluated left-to-right and top-to-bottom, in
      sequential order.  So, the OR branch

            Val1                                          Val2
      ---------------+---- OP1 ----------- OP2 ----+--------------
                     |                             |
                     +---- OP3 ----------- OP4 ----+
                     |                             |
                     +---- OP5 ----------- OP6 ----+

      Will execute in the order OP1 followed by OP2 followed by OP3 (with an
      input value of Val1) followed by OP4 followed by OP5 (with an input
      value of Val1) followed by OP6.  Val2 will be the logical OR of the
      outputs from OP2, OP4, and OP6.

PLC menu:
   The PLC program is controlled by a menu on the left hand side of the
   screen.  The menu elements are:

      Save     Load
      New      Download
      AddRow   DelRow
      OneStep  LineStep
      Run      Stop
      ---[]--  --[/]--
      ---()--  --(/)--
      -(LAT)-  -(UNL)-
      -(ADD)-  -(SUB)-
      -(MUL)-  -(DIV)-
      -(MOD)-  -(NEG)-
      -(AND)-  -(OR)--
      -(XOR)-  -(NOT)-
      -[EQ]--  -[NE]--
      -[GT]--  -[GE]--
      -[LT]--  -[LE]--
      -(MOV)-  -[OSR]-
      -(JMP)-  -[LBL]-
      -[CTT]-  -[CTF]-
      -[TMT]-  -[TMF]-
      -[RTT]-  -[RTF]-
      -[RST]-  -[INV]-
      -------  -------
      |    |   |    |
       ----     ----->

      Exit

   The menu elements are divided into ACTIONS and TOOLS.

   Menu ACTIONS:
      The menu elements Save, Load, New, Download, OneStep, LineStep, Run,
      Stop, and Exit are actions.  When left-clicked, an action is performed.

      A special case is AddRow,which performs an action when right-clicked.
      See the description of AddRow below for full details.

      Save      Save the current ladder in a file.  Default extension is .LAD

      Load      Load a ladder from a file.  Default extension is .LAD

      New       Erase the ladder and start with a blank ladder.  If the
                current ladder has been modified, you will be asked if you
                want to save the current ladder.

      Download  Compile the ladder and transfer it to the processor board.
                Do not forget that you must click "Run" to start the program.

      Run       Set the software RUN state.

      Stop      Clear the software RUN state.

      Onestep   Not currently functional.

      Linestep  Not currently functional.

      Exit      Exit the PLC program.  If you ladder has changed, you will be
                prompted to save it.  The Esc key will also exit the PLC
                program.

   Menu TOOLS:
      The menu items that are not actions are tools (the majority of them).
      When a tools is left-clicked, it's function will be picked up by the
      mouse cursor.  The mouse cursor will change to show it's new function.

      Normal tools are logic elements (i.e. not AddRow or DelRow), and are
      placed on the ladder when the cursor is left-clicked on an empty rung
      element.

      Left-clicking on a occupied rung element will cause the tool to be
      dropped and bring up an edit dialog for the contents of the rung
      element.

      Right-clicking anywhere will case the tool to be dropped.  If the
      click is on an occupied rung element, the rung element will be
      cleared.

      AddRow    Right-clicking AddRow in the menu will add a new rung to the
                bottom of the ladder.  The AddRow tool is picked up by the
                normal left-click in the menu.  With the AddRow tool active,                
                left-clicking on a rung will add a new rung after that rung,
                while right-clicking on a rung will add new rung before that
                rung.  The AddRow tool will be dropped when any mouse click
                occurs.

      DelRow    To pickup the DelRow tool, left-click on DelRow.  Then,
                right-clicking on a rung will delete that rung.  The DelRow
                tool will be dropped when a mouse click occurs.

Two sample programs (.LAD) files are included:
   BOUNCE.LAD -- "Bounce" a lit LED back and forth between DIG_OUT_0 and
                 DIG_OUT_5.

   PONG.LAD   -- Play a simple game of "Ping-Pong", bouncing a lit LED
                 back and forth between DIG_OUT_0 and DIG_OUT_5.  DIG_IN_0
                 is the "left" player paddle, and must be switched ON no
                 earlier than 1/4 second before the "ball" reaches DIG_OUT_0
                 or the "left" player loses.  DIG_IN_3 is the "right" player
                 paddle, and must be switched ON no earlier than 1/4 second
                 before the "ball" reaches DIG_OUT_5 or the "right" player
                 loses.  DIG_IN_1 resets the game to it's power up status,
                 and DIG_IN_2 restarts the game after a "loss" (the "ball"
                 heads towards the winning player).


---------------------------------------------------------------------------

Section II:  TinyPLC kernel documentation


TinyPLC was originally designed to run as a user programmable part of an
embedded control system.  Thus, it does not use all, or even most, of the
resources available on the processor chip.

The target processor is the Atmel ATmega1281 / ATmega2561 (the processors
used on the processor board), compiled with Codevision AVR C compiler,
version 1.24.8e (later versions are available, but I do not upgrade the
compiler used for a project unless it is mandated by bug fixes / necessary
features).

Yes, Codevision AVR compiler is propritary software, but it's what we are
using for development at work.  Maybe some nice person will port an
AVR GCC version.

The source files are:
   TINYPLC.C
   TINYPLC.H
   PLCSHARE.H

The target hardware described by TINYPLC.H is both simplified (display
driver has been removed, external EEPROM has been removed, external ADC
has been removed, etc) and more complex (additional I/O lines have been
added, internal ADC is available to PLC, etc) then the original embedded
processor board.

The processor resources supported by TinyPLC are:
   RS232 port -- USART0 using pins PE0 (pin 2) for RX and PE1 (pin 3) for TX

   Status LED -- LED on pin PE2 (pin 4), this is PWMed by TinyPLC to show
                 processor active.

   RUN/STOP switch -- Input on pin PG0 (pin 33).  If TRUE (see TINYPLC.H
                 for input logic values), the PLC program is permitted to
                 run (with permission of the "soft run" flag and program
                 valid flag).

   DIG_IN_0 .. DIG_IN_20 -- PC0 (DIG_IN_0) .. PC7 (DIG_IN_7), PD0 (DIG_IN_8)
                 .. PD7 (DIG_IN_15), PG1 (DIG_IN_16) .. PG5 (DIG_IN_20)
                 Digital inputs, see TINYPLC.H for input logic values.

   DIG_OUT_0 .. DIG_OUT_20 -- PA0 (DIG_OUT_0) .. PA7 (DIG_OUT_7),
                 PB0 (DIG_OUT_8) .. PB7 (DIG_OUT_15), PE3 (DIG_OUT_16)
                 .. PE7 (DIG_OUT_20)

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -