====== On LadderInt ====== ''On LadderInt GoSub label'' If Register F40 turns on in Ladder Logic, and the ''On LadderInt GoSub'' command is used, then the processor will jump to the routine (''label'') specified by ''On LadderInt''. This can be used when a Ladder Logic program needs to trigger a specific procedure in BASIC. Please use the ''SETOUT'' and ''DF'' command to write 1 to the register F40. When the BASIC interrupt routine is finished, register F40 can be cleared by writing a zero to it. During the interrupt service routine(ISR) execution, writing a 1 to register F40 will not allow another interrupt to occur. If register F40 is cleared from BASIC, it signals the end of the ISR and can process another interrupt. UsePin 0,In Set Ladder On Set Display 0,0,16,77,50 On LadderInt GoSub msg1_rtn Dim i As Integer Low 1 Do i=i+1 ByteOut 1,i Delay 200 Loop msg1_rtn: Locate 0,0 Print "ON LadderInt",Dec i Reverse 1 Return {{ :cubloc:on_ladderint:onladderint.png?nolink |}} When P0 turns on, register F40 turns on and the ''msg1_rtn'' interrupt routine in BASIC is executed. In the ISR, a String is printed to the LCD. Although there is only one register, F40, with which call an ISR in BASIC from Ladder Logic, we can use data register D to process many different types of interrupts. {{ :cubloc:on_ladderint:onladderint2.png?nolink |}} Given the ladder above, when P0 turns on, D0 gets 3 and the interrupt routine is executed. If P2 turns on, D0 gets 2 and the interrupt routine is executed. In the ISR, the user can then process the type of interrupt based on the value stored in D0. msg1_rtn: If _D(0)=3 Then Locate 0,0 Print "ON Ladderint",Dec i End If If _D(0)=2 Then Locate 0,0 Print "TEST PROGRAM",Dec i End If Return For a short version of the ladder above the user can use an ''INTON'' command, which accomplishes both ''WMOV'' and ''SETOUT'' in one command. The following is an equivalent shortened version of the ladder above: {{ :cubloc:on_ladderint:onladderint3.png?nolink |}} [[cubloc:index#system_library:|Go CUBLOC home]]