Revision: 1622
Author: sebastien.lelong
Date: Mon Jan 25 00:09:22 2010
Log: pintools sample for 18f4550
http://code.google.com/p/jallib/source/detail?r=1622
Added:
/trunk/sample/18f4550_pintools.jal
=======================================
--- /dev/null
+++ /trunk/sample/18f4550_pintools.jal Mon Jan 25 00:09:22 2010
@@ -0,0 +1,105 @@
+-- Title: Show how to access pins by number, controlling their direction
and levels, using pintools.jal library
+-- Author: Sébastien Lelong, Copyright (c) 2008..2010, all rights reserved.
+-- Adapted-by:
+-- Compiler: 2.4m
+--
+-- This file is part of jallib (http://jallib.googlecode.com)
+-- Released under the BSD license
(http://www.opensource.org/licenses/bsd-license.php)
+--
+-- Description: this sample show how to use pintools.jal library.
pintools.jal allows to
+-- access pins using a number. This number is first defined in kind of
associative array.
+-- Using pintools.jal, you don't have to use pin's name.
+-- This sample uses LEDs and push-buttons:
+-- - when switch SW1 is pushed, pin_A0 (LED1) switches between high and
low level
+-- - when switch SW2 is pushed, pin_C2 (LED2) switches between output and
input direction
+-- (if output, LED shines)
+-- that is, we're controlling LED1 with its level, and LED2 with its
direction
+--
+-- Notes: this sample is derived from Jaluino's "crumboard_pintools.jal"
sample. It uses
+-- crumboard shield where LEDs and push-buttons are built-in. You may want
to have a look at
+-- the whole schematic:
http://justanotherlanguage.org/content/jaluino/shields/jaluino_crumboard
+--
+
+include 18f4550
+pragma target clock 48_000_000
+pragma target PLLDIV P5
+pragma target CPUDIV P2
+pragma target USBPLL F48MHZ
+pragma target OSC HS_PLL
+pragma target WDT disabled
+pragma target LVP disabled
+pragma target MCLR external
+-- by default, we'll set all pins as digital pins
+enable_digital_io()
+include delay
+
+-- 2 LEDs on pin_A0 and pin_C2
+-- at the beginning, we configure them to be ready to use
+alias led1 is pin_A0
+alias led2 is pin_C2
+pin_A0_direction = output
+pin_C2_direction = output
+alias led2_direction is pin_C2_direction
+
+-- we'll also use two push-button, to control these LEDs
+alias sw1 is pin_D6
+alias sw2 is pin_D7
+pin_D6_direction = input
+pin_D7_direction = input
+
+-- we here define our associate array, a mapping between
+-- pin names and an arbitrary index. crumboard_shield.jal says:
+-- - LED1 is on pin_A0: its index will be 0
+-- - LED2 is on pin_C2: its index will be 1
+-- Array map's elements go y two: [port,number], so
+-- this translates to (size = 2 * 2 pins):
+-- index: 0 1
+const byte pintools_map[4] = {"A",0, "C",2}
+include pintools
+
+-- everything is setup, ready to be used
+led1 = off
+led2 = off
+
+-- blink a little at first
+for 5 loop
+ led1 = on
+ led2 = on
+ delay_1ms(200)
+
+ led1 = off
+ led2 = off
+ delay_1ms(200)
+end loop
+
+-- we first turn on LEDs
+-- before evaluate inputs
+led1 = on
+led2 = on
+
+-- these are just used to store previous level/direction state
+var bit _led1_level = led1
+var bit _led2_direction = led2_direction
+
+forever loop
+ -- "read" switch SW1
+ if sw1 == high then
+ -- here we set pin #0, which is pin_A0, to high or low level
+ -- according to previous level
+ _led1_level = ! _led1_level
+ pintools_set_level(0,_led1_level)
+ end if
+
+ -- same for SW2
+ if sw2 == high then
+ -- here we set pin #1, which is pin_C2, to input or output direction
+ -- according to previous direction
+ _led2_direction = ! _led2_direction
+ pintools_set_direction(1,_led2_direction)
+ end if
+
+ -- debounce push buttons
+ delay_1ms(200)
+end loop
+
+--
--
You received this message because you are subscribed to the Google Groups
"jallib" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/jallib?hl=en.