DI-159 PLC Hardware Manual
Sample Programs
Example #2 General-purpose LED
Object
Flash general-purpose LED0 at a precise one second on/off interval.
Code
200 let led0 = 0
210 configure timer 0 for 1 s
220 on timer 0 do gosub flasher
230 while 1 do
240 endwhile
250 sub flasher
260 let led0 = !led0
270 endsub
'start with LED on
'configure one of four timers for 1 sec interval
'execute subroutine "flasher" when timer fires
'do nothing while waiting for the timer to fire
'
'end up here when timer fires
'invert the state of LED0 (turn off if on, and on if off)
'return to waiting for the timer to fire again
Comment
This example demonstrates the real time power of the BASIC program, the ease with which it
can manipulate peripherals, and one of many block statements (gosub, in this case). A single
statement configures a timer for a precise interval, and another single statement defines the state
of the peripheral (Led0 in this case.) Timer intervals can be configured in seconds (s), mil-
liseconds (ms), or microseconds (us) and can range from milliseconds to hours.
Example #3 Flash Both LEDs
Object
Flash both LEDs at precisely different rates, LED1 at four times the rate of LED0.
Code
200 let led0 = 0
210 let led1 = 0
220 configure timer 0 for 1000 ms
230 configure timer 1 for 250 ms
240 on timer 0 do gosub flash_led0
250 on timer 1 do gosub flash_led1
260 while 1 do
270 endwhile
280 sub flash_led0
290 let led0 = !led0
300 endsub
310 sub flash_led1
320 let led1 = !led1
330 endsub
'begin with both LEDs on
'
'configure first of four timers for 1 sec interval
'configure second of four timers for 1/4 sec interval
'execute subroutine "flash_led0" when timer0 fires
'execute subroutine "flash_led1" when timer1 fires
'do nothing while waiting for the timers to fire
'
'end up here when timer0 fires
'invert the state of LED0 (turn off if on, and on if off)
'return to waiting for timers to fire again
'end up here when timer1 fires
'invert the state of LED1 (turn off if on, and on if off)
'return to waiting for timers to fire again
72
Содержание DI-159
Страница 51: ...StickOS DI 159 PLC Hardware Manual 4 is even _ 51...
Страница 76: ...DI 159 Block Diagram 76...
Страница 77: ...Dimensional Drawing 77...