summaryrefslogtreecommitdiff
path: root/ldmicro/sample
diff options
context:
space:
mode:
Diffstat (limited to 'ldmicro/sample')
-rw-r--r--ldmicro/sample/7seg-display.ld123
-rw-r--r--ldmicro/sample/blink.ld61
-rw-r--r--ldmicro/sample/pic-adc.ld158
-rw-r--r--ldmicro/sample/serial.ld92
-rw-r--r--ldmicro/sample/traffic.ld73
-rw-r--r--ldmicro/sample/var-timer.ld63
6 files changed, 570 insertions, 0 deletions
diff --git a/ldmicro/sample/7seg-display.ld b/ldmicro/sample/7seg-display.ld
new file mode 100644
index 0000000..b9d0c9d
--- /dev/null
+++ b/ldmicro/sample/7seg-display.ld
@@ -0,0 +1,123 @@
+LDmicro0.1
+CYCLE=5000
+CRYSTAL=4000000
+BAUD=2400
+
+IO LIST
+ Ycom_digit0 at 0
+ Ycom_digit1 at 0
+ Ycom_digit2 at 0
+ Yseg_a at 0
+ Yseg_b at 0
+ Yseg_c at 0
+ Yseg_d at 0
+ Yseg_e at 0
+ Yseg_f at 0
+ Yseg_g at 0
+END
+
+PROGRAM
+RUNG
+ COMMENT Sample program: how to drive a multiplexed 7-segment LED display. This is\r\nfor a 3-digit common-cathode display but it is easy to modify.
+END
+RUNG
+ COMMENT With a 5 ms cycle time, this will oscillate at 100 Hz, which should be\r\nokay (33 Hz refresh rate, 1/3 duty cycle).
+END
+RUNG
+ CONTACTS Rdosc 1
+ COIL Rdosc 0 0 0
+END
+RUNG
+ CONTACTS Rdosc 0
+ CTC Cdigit 2
+END
+RUNG
+ COMMENT Use the Ycom_digitx lines to drive the base/gate of the NPN transistor/\r\nn-FET used to switch the cathode of digit x.
+END
+RUNG
+ PARALLEL
+ SERIES
+ EQU Cdigit 0
+ PARALLEL
+ COIL Ycom_digit0 0 0 0
+ MOVE digit digit0
+ END
+ END
+ SERIES
+ EQU Cdigit 1
+ PARALLEL
+ COIL Ycom_digit1 0 0 0
+ MOVE digit digit1
+ END
+ END
+ SERIES
+ EQU Cdigit 2
+ PARALLEL
+ COIL Ycom_digit2 0 0 0
+ MOVE digit digit2
+ END
+ END
+ END
+END
+RUNG
+ COMMENT You can drive the segment pins of the display directly from the GPIO pins,\r\nYseg_a to Yseg_b.
+END
+RUNG
+ PARALLEL
+ SERIES
+ NEQ digit 1
+ NEQ digit 4
+ COIL Yseg_a 0 0 0
+ END
+ SERIES
+ NEQ digit 5
+ NEQ digit 6
+ COIL Yseg_b 0 0 0
+ END
+ SERIES
+ NEQ digit 2
+ COIL Yseg_c 0 0 0
+ END
+ SERIES
+ NEQ digit 1
+ NEQ digit 4
+ NEQ digit 7
+ COIL Yseg_d 0 0 0
+ END
+ SERIES
+ PARALLEL
+ EQU digit 0
+ EQU digit 2
+ EQU digit 6
+ EQU digit 8
+ END
+ COIL Yseg_e 0 0 0
+ END
+ SERIES
+ NEQ digit 1
+ NEQ digit 2
+ NEQ digit 3
+ NEQ digit 7
+ COIL Yseg_f 0 0 0
+ END
+ SERIES
+ NEQ digit 0
+ NEQ digit 1
+ NEQ digit 7
+ COIL Yseg_g 0 0 0
+ END
+ END
+END
+RUNG
+ COMMENT Fill in your program here; just set the output that you want on digit0,\r\ndigit1, and digit2.
+END
+RUNG
+ PARALLEL
+ MOVE digit0 1
+ MOVE digit1 8
+ MOVE digit2 5
+ END
+END
+RUNG
+ COMMENT by Jonathan Westhues, June 2005
+END
diff --git a/ldmicro/sample/blink.ld b/ldmicro/sample/blink.ld
new file mode 100644
index 0000000..e86d7a3
--- /dev/null
+++ b/ldmicro/sample/blink.ld
@@ -0,0 +1,61 @@
+LDmicro0.1
+MICRO=Microchip PIC16F877 40-PDIP
+CYCLE=10000
+CRYSTAL=4000000
+COMPILED=C:\depot\ldmicro\pic.hex
+
+IO LIST
+ Xbutton at 21
+ Yled at 30
+END
+
+PROGRAM
+RUNG
+ CONTACTS Xbutton 1
+ CTC Cwhich 4
+END
+RUNG
+ CONTACTS Xbutton 1
+ OSF
+ TOF Tdblclk 500000
+ COIL Rdblclk 0 0 0
+END
+RUNG
+ CONTACTS Xbutton 1
+ CONTACTS Rdblclk 0
+ MOVE Cwhich 3
+END
+RUNG
+ CONTACTS Rfast 0
+ TOF Tffast 100000
+ TON Tnfast 100000
+ COIL Rfast 1 0 0
+END
+RUNG
+ CONTACTS Rslow 0
+ TON Tnslow 100000
+ TOF Tfslow 1000000
+ COIL Rslow 1 0 0
+END
+RUNG
+ PARALLEL
+ SERIES
+ EQU Cwhich 0
+ CONTACTS Rfast 0
+ END
+ SERIES
+ EQU Cwhich 1
+ CONTACTS Rslow 0
+ END
+ SERIES
+ EQU Cwhich 2
+ CONTACTS Rslow 1
+ END
+ EQU Cwhich 3
+ SERIES
+ EQU Cwhich 4
+ OPEN
+ END
+ END
+ COIL Yled 0 0 0
+END
diff --git a/ldmicro/sample/pic-adc.ld b/ldmicro/sample/pic-adc.ld
new file mode 100644
index 0000000..760475a
--- /dev/null
+++ b/ldmicro/sample/pic-adc.ld
@@ -0,0 +1,158 @@
+LDmicro0.1
+MICRO=Microchip PIC16F877 40-PDIP
+CYCLE=10000
+CRYSTAL=4000000
+BAUD=2400
+COMPILED=c:\temp\asd.hex
+
+IO LIST
+ Xlimit at 2
+ Yled at 22
+ Ain at 3
+END
+
+PROGRAM
+RUNG
+ COMMENT Serial/ADC test program for PIC16F877: read an ADC input, convert from integer to string\r\n(three ASCII chars), then send it out over the serial port. Display a message at startup:
+END
+RUNG
+ PARALLEL
+ SERIES
+ EQU Cinit 2
+ MOVE initc 'a'
+ END
+ SERIES
+ EQU Cinit 3
+ MOVE initc 'd'
+ END
+ SERIES
+ EQU Cinit 4
+ MOVE initc 'c'
+ END
+ SERIES
+ PARALLEL
+ EQU Cinit 0
+ EQU Cinit 5
+ END
+ MOVE initc 13
+ END
+ SERIES
+ PARALLEL
+ EQU Cinit 1
+ EQU Cinit 6
+ END
+ MOVE initc 10
+ END
+ END
+END
+RUNG
+ TON Ttod 500000
+ CONTACTS Rinitdone 1
+ CONTACTS Rtxbusy 1
+ UART_SEND initc
+ COIL Rtxbusy 0 0 0
+END
+RUNG
+ CONTACTS Rtxbusy 0
+ CTU Cinit 7
+ COIL Rinitdone 0 0 0
+END
+RUNG
+ COMMENT Clock for the ADC read and a circular counter that sequences it. Just block the\r\noscillator until the init sequence completes.
+END
+RUNG
+ CONTACTS Rinitdone 0
+ CONTACTS Rosc 1
+ TOF Tct1 50000
+ TON Tct2 50000
+ COIL Rosc 0 0 0
+END
+RUNG
+ CONTACTS Rosc 0
+ CTC Cchar 4
+END
+RUNG
+ OSR
+ MOVE Cchar 3
+END
+RUNG
+ COMMENT Read the A/D input, then saturate the input so that we only have to display three digits.
+END
+RUNG
+ PARALLEL
+ READ_ADC Ain
+ SERIES
+ LEQ Ain 999
+ MOVE intval Ain
+ END
+ SERIES
+ GEQ Ain 1000
+ MOVE intval 999
+ END
+ END
+END
+RUNG
+ COMMENT Split the integer into the ones, tens, and hundreds digits. This is just cumbersome, but\r\nit does not waste much memory (the multiply and divide are subroutines in the PIC code).
+END
+RUNG
+ PARALLEL
+ DIV hundreds intval 100
+ MUL hundredsv hundreds 100
+ SUB wohundreds intval hundredsv
+ DIV tens wohundreds 10
+ MUL tensv tens 10
+ SUB ones wohundreds tensv
+ END
+END
+RUNG
+ COMMENT Now convert the ones, tens, and hundreds digits to ASCII characters by adding\r\nASCII character '0' (since the ASCII digits are contiguous in order).
+END
+RUNG
+ PARALLEL
+ ADD hunc hundreds '0'
+ ADD tensc tens '0'
+ ADD onesc ones '0'
+ END
+END
+RUNG
+ COMMENT Then send out the characters. For each line we must send out five characters:\r\nhundreds, tens, ones, ones, carriage return, newline; use a CTC to sequence.
+END
+RUNG
+ PARALLEL
+ SERIES
+ EQU Cchar 0
+ MOVE outch hunc
+ END
+ SERIES
+ EQU Cchar 1
+ MOVE outch tensc
+ END
+ SERIES
+ EQU Cchar 2
+ MOVE outch onesc
+ END
+ SERIES
+ EQU Cchar 3
+ MOVE outch 13
+ END
+ SERIES
+ EQU Cchar 4
+ MOVE outch 10
+ END
+ END
+END
+RUNG
+ COMMENT Time it off Rosc (10 characters/s) which is slow so ignore the busy out.
+END
+RUNG
+ CONTACTS Rosc 0
+ OSR
+ UART_SEND outch
+END
+RUNG
+ PARALLEL
+ CONTACTS Rosc 0
+ CONTACTS Xlimit 1
+ END
+ COIL Yled 0 0 0
+END
diff --git a/ldmicro/sample/serial.ld b/ldmicro/sample/serial.ld
new file mode 100644
index 0000000..1285e4f
--- /dev/null
+++ b/ldmicro/sample/serial.ld
@@ -0,0 +1,92 @@
+LDmicro0.1
+MICRO=Microchip PIC16F877 40-PDIP
+CYCLE=10000
+CRYSTAL=4000000
+BAUD=2400
+COMPILED=c:\temp\ser.hex
+
+IO LIST
+ Yled at 22
+END
+
+PROGRAM
+RUNG
+ CONTACTS Rosc 1
+ TOF Tct1 250000
+ TON Tct2 250000
+ COIL Rosc 0 0 0
+END
+RUNG
+ CONTACTS Rfast 1
+ TOF Tct3 100000
+ TON Tct4 100000
+ COIL Rfast 0 0 0
+END
+RUNG
+ CONTACTS Rosc 0
+ CTC Cwhich 4
+END
+RUNG
+ PARALLEL
+ SERIES
+ EQU Cwhich 0
+ MOVE ch 'A'
+ END
+ SERIES
+ EQU Cwhich 1
+ MOVE ch 'b'
+ END
+ SERIES
+ EQU Cwhich 2
+ MOVE ch 'c'
+ END
+ SERIES
+ EQU Cwhich 3
+ MOVE ch 13
+ END
+ SERIES
+ EQU Cwhich 4
+ MOVE ch 10
+ END
+ END
+END
+RUNG
+ CONTACTS Rosc 0
+ OSF
+ UART_SEND ch
+END
+RUNG
+ UART_RECV inch
+ COIL Rjustgot 0 1 0
+END
+RUNG
+ CONTACTS Rjustgot 0
+ TON Tnew 1000000
+ COIL Rjustgot 0 0 1
+END
+RUNG
+ PARALLEL
+ SERIES
+ CONTACTS Rjustgot 0
+ CONTACTS Rfast 0
+ END
+ SERIES
+ CONTACTS Rjustgot 1
+ PARALLEL
+ SERIES
+ EQU inch 'o'
+ SHORT
+ END
+ SERIES
+ EQU inch 'b'
+ CONTACTS Rosc 0
+ END
+ SERIES
+ SHORT
+ OPEN
+ END
+ END
+ END
+ END
+ COIL Yled 0 0 0
+END
diff --git a/ldmicro/sample/traffic.ld b/ldmicro/sample/traffic.ld
new file mode 100644
index 0000000..cc716d6
--- /dev/null
+++ b/ldmicro/sample/traffic.ld
@@ -0,0 +1,73 @@
+LDmicro0.1
+MICRO=Atmel AVR ATmega128 64-TQFP
+CYCLE=10000
+CRYSTAL=4000000
+COMPILED=C:\depot\ldmicro\out.hex
+
+IO LIST
+ Xbutton1 at 46
+ Xbutton2 at 45
+ Ygreen at 49
+ Yred at 51
+ Ywait at 48
+ Yyellow at 50
+END
+
+PROGRAM
+RUNG
+ CONTACTS Rclock 1
+ TOF Ton 500000
+ TON Toff 500000
+ COIL Rclock 0 0 0
+END
+RUNG
+ CONTACTS Rclock 0
+ CTC Ccycle 19
+END
+RUNG
+ GEQ Ccycle 0
+ LES Ccycle 8
+ COIL Yred 0 0 0
+END
+RUNG
+ GEQ Ccycle 8
+ LES Ccycle 12
+ COIL Yyellow 0 0 0
+END
+RUNG
+ GEQ Ccycle 12
+ LES Ccycle 20
+ PARALLEL
+ COIL Ygreen 0 0 0
+ COIL Rwait 0 0 1
+ END
+END
+RUNG
+ PARALLEL
+ CONTACTS Xbutton1 1
+ CONTACTS Xbutton2 1
+ END
+ PARALLEL
+ SERIES
+ GEQ Ccycle 0
+ LES Ccycle 6
+ MOVE cycle 6
+ END
+ COIL Rwait 0 1 0
+ END
+END
+RUNG
+ CONTACTS Rwait 0
+ PARALLEL
+ SERIES
+ GEQ Ccycle 8
+ LES Ccycle 12
+ CONTACTS Rclock 0
+ END
+ SERIES
+ GEQ Ccycle 0
+ LES Ccycle 8
+ END
+ END
+ COIL Ywait 0 0 0
+END
diff --git a/ldmicro/sample/var-timer.ld b/ldmicro/sample/var-timer.ld
new file mode 100644
index 0000000..a7b28fb
--- /dev/null
+++ b/ldmicro/sample/var-timer.ld
@@ -0,0 +1,63 @@
+LDmicro0.1
+CYCLE=10000
+CRYSTAL=4000000
+BAUD=2400
+
+IO LIST
+ Xin at 0
+ Yout at 0
+ Apot at 0
+END
+
+PROGRAM
+RUNG
+ COMMENT This is the actual variable-delay TOF timer. When Rdel_input goes high, Rdel_output goes high \r\nt_max cycle times later. When Rdel_input goes low, Rdel_output goes low immediately.
+END
+RUNG
+ CONTACTS Rdel_input 0
+ LEQ t_count t_max
+ ADD t_count t_count 1
+END
+RUNG
+ CONTACTS Rdel_input 1
+ MOVE t_count 0
+END
+RUNG
+ COMMENT The extra branch is to make a delay of 0 cycles work correctly.
+END
+RUNG
+ PARALLEL
+ GRT t_count t_max
+ SERIES
+ CONTACTS Rdel_input 0
+ EQU t_max 0
+ END
+ END
+ COIL Rdel_output 0 0 0
+END
+RUNG
+ COMMENT \r\n
+END
+RUNG
+ COMMENT This is just an example of how to use the timer. The voltage attached to Apot (which goes\r\nfrom 0 V to Vdd) sets the delay between when Xin goes high and when Yout goes high.
+END
+RUNG
+ READ_ADC Apot
+END
+RUNG
+ COMMENT This only works with a cycle time of 10 ms. If we want the delay to be between 0 s and 5 s,\r\nthen it should be 0 to 500 cycle times; the ADC goes from 0 to 1023, so (roughly) divide by 2.
+END
+RUNG
+ DIV t_max Apot 2
+END
+RUNG
+ COMMENT Then just hook up the input and the output of the timer to pins. Of course\r\nthat could drive more complicated logic, not just a pin on the processor.
+END
+RUNG
+ CONTACTS Xin 0
+ COIL Rdel_input 0 0 0
+END
+RUNG
+ CONTACTS Rdel_output 0
+ COIL Yout 0 0 0
+END