DI-159 PLC Hardware Manual
Sample Programs
Code
200 dim count, i as byte
210 let count = 3
220 let led0 = 1
230 let led1 = 1
240 while 1 do
250 while push_button do
260 endwhile
270 gosub debounce
280 let count = count-1
290 let led0 = count&1
300 let led1 = count>>1&1
310 while !push_button do
320 gosub debounce
330 endwhile
340 endwhile
350 sub debounce
360 for i = 1 to 200
370 next
380 endsub
'define variables COUNT and I as byte (0-255)
'set two LSBs of COUNT to 1
'set initial LED states to match initial COUNT value (both LEDs off)
'
'loop continuously
'wait for pushbutton to be pressed (low true)
'
'de-bounce the pushbutton to get one clean transition
'the LEDs are low true, so we’ll decrement COUNT
'LED0 is LSB, so mask COUNT LSB state by ANDing with 1
'LED1 is second LSB, so right-shift COUNT one bit, then AND with 1
'wait for the pushbutton to be released
'de-bounce pushbutton again to get a clean transition
'end one pushbutton cycle
'do it again
'pushbutton de-bounce subroutine.
'do nothing for 200 cycles while the pushbutton settles down
'
'return from the subroutine
Comment
Note that the pushbutton and LEDs are low true. A 0 written to either LED lights it, and the
pushbutton transitions from 1 to 0 when pressed.
Example #6 Create a Square Wave
Object
Create a square wave output with a frequency that’s proportional to the magnitude of the volt-
age applied to an analog input channel.
Code
200 dim o0 as pin Do0 for frequency output
210 dim New_o0
220 let o0 = 100230 configure timer 0 for 100 ms
240 on timer 0 do gosub Update
250 while 1 do
260 endwhile
270 sub Update
280 let New_o0 = c0/100+100
290 if o0!=New_o0 then
300 let o0 = New_o0
310 endif
330 endsub
're-dimension do0 to be a frequency output
'define variable New_o0
'set square wave frequency output at o0 to100Hz
'set timer to update 10 times per second
'go to subroutine Update whenever timer 0 fires
'loop while waiting for the timer to fire
'
'get here when the timer fires
'calculate new frequency where c0=analog input0
'don’t write the value if it hasn't changed
'New_o0 is different so change frequency
'
Comment
Note that the pushbutton and LEDs are low true. A 0 written to either LED lights it, and the
pushbutton transitions from 1 to 0 when pressed. Any DI-159 PLC digital output port may be
74
Содержание DI-159
Страница 51: ...StickOS DI 159 PLC Hardware Manual 4 is even _ 51...
Страница 76: ...DI 159 Block Diagram 76...
Страница 77: ...Dimensional Drawing 77...