From 67d25d837ac55f28a366c0a3b262e439a6e75fc3 Mon Sep 17 00:00:00 2001 From: Dimitri Sokolyuk Date: Sat, 19 Aug 2017 12:15:28 +0200 Subject: Add AmForth --- amforth-6.5/avr8/lib/portio.frt | 46 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 46 insertions(+) create mode 100644 amforth-6.5/avr8/lib/portio.frt (limited to 'amforth-6.5/avr8/lib/portio.frt') diff --git a/amforth-6.5/avr8/lib/portio.frt b/amforth-6.5/avr8/lib/portio.frt new file mode 100644 index 0000000..4d40c46 --- /dev/null +++ b/amforth-6.5/avr8/lib/portio.frt @@ -0,0 +1,46 @@ +\ Only for PORTx bits, +\ because address of DDRx is one less than address of PORTx. + +\ Set DDRx so its corresponding pin is output. +: pin_output ( pinmask portadr -- ) + 1- bm:high +; + +\ Set DDRx so its corresponding pin is input. +: pin_input ( pinmask portadr -- ) + 1- bm:low +; + +\ PINx is two less of PORTx +: pin_high? ( pinmask portaddr -- f) + 1- 1- c@ and +; + +: pin_low? ( pinmask portaddr -- f) + 1- 1- c@ invert and +; + +\ read the pins masked as input +: pin@ ( pinmask portaddr -- c ) + 1- 1- c@ and +; + +\ toggle the pin +: toggle ( pinmask portaddr -- ) + 2dup bm:high? if + bm:low + else + bm:high + then +; + +\ disable the pull up resistor +: pin_pullup_off ( pinmask portaddr -- ) + 2dup pin_input low +; + + +\ enable the pull up resistor +: pin_pullup_on ( pinmask portaddr -- ) + 2dup pin_input high +; -- cgit v1.2.3