Author: sebastien.lelong
Date: Fri Apr 10 01:02:36 2009
New Revision: 924
Modified:
trunk/include/external/ranger/ir/ir_ranger_gp2d02.jal
trunk/sample/16f88_ir_ranger_gp2d02.jal
trunk/test/external/ranger/ir/test_ir_ranger_gp2d02.jal
Log:
issue-46: lib + test + sample for GP2D02 libs
Modified: trunk/include/external/ranger/ir/ir_ranger_gp2d02.jal
==============================================================================
--- trunk/include/external/ranger/ir/ir_ranger_gp2d02.jal (original)
+++ trunk/include/external/ranger/ir/ir_ranger_gp2d02.jal Fri Apr 10
01:02:36 2009
@@ -1,7 +1,7 @@
-- Title: GP2D02 IR ranger library
-- Author: Sebastien Lelong, Copyright (c) 2008-2009, all rights reserved.
-- Adapted-by:
--- Compiler: >=2.4j
+-- Compiler: >=2.4k
--
-- This file is part of jallib (http://jallib.googlecode.com)
-- Released under the ZLIB license
(http://www.opensource.org/licenses/zlib-license.html)
@@ -27,19 +27,8 @@
include delay
-if !(defined(GP2D02_COUNT) == true) then
- const byte GP2D02_COUNT = 1
-end if
--- will store couple (pin_vin,pin_vout)
-var byte GP2D02_ARRAY[GP2D02_COUNT * 2]
-
-procedure gp2d02_register(byte in idx, bit in pin_vin, bit in pin_vout) is
- GP2D02_ARRAY[idx] = pin_vin
- GP2D02_ARRAY[idx+1] = pin_vout
-end procedure
-
-function gp2d02_read_pins(bit in pin_vin, bit in pin_vout) return byte is
+function gp2d02_read_pins(volatile bit out pin_vin, volatile bit in
pin_vout) return byte is
-- See GP2D02 for detailed specs
var byte range = 0b_0000_0000
-- pin_in to 1: ready for next range
@@ -77,14 +66,5 @@
return range
end function
-
-function gp2d02_read(byte in idx) return byte is
- -- retrieve corresponding pin for ranger num.idx
- var volatile bit pin_vin = GP2D02_ARRAY[idx]
- var volatile bit pin_vout = GP2D02_ARRAY[idx+1]
- var byte measure = gp2d02_read_pins(pin_vin,pin_vout)
- return measure
-end function
-
Modified: trunk/sample/16f88_ir_ranger_gp2d02.jal
==============================================================================
--- trunk/sample/16f88_ir_ranger_gp2d02.jal (original)
+++ trunk/sample/16f88_ir_ranger_gp2d02.jal Fri Apr 10 01:02:36 2009
@@ -1,30 +1,25 @@
-- Title: Test program for GP2D02 IR ranger
-- Author: Sebastien Lelong, Copyright (c) 2008-2009, all rights reserved.
-- Adapted-by:
--- Compiler: >=2.4j
+-- Compiler: >=2.4k
--
-- 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 GP2D02 IR ranger library
-- It regularly gets distance measures, and print them back to serial.
--- It also uses a LED to "show" the distance:
--- - when the distance is low (object is closed from the ranger),
--- the LED will blink very fast
--- - when the distance is high (object is far way from the ranger),
--- the LED will blink very slow
--- - when the distance is to high (nothing detected), the LED is on, no
--- blinking
+-- It also uses a led to "show" the distance. This LED is connected to a
PWM output.
+-- it will be more or less bright according to the distance between the
ranger
+-- and an object.
-- --
--
--
--
--- This file has been generated on Mon Mar 16 18:41:14 2009, from:
+-- This file has been generated on Fri Apr 10 10:01:00 2009, from:
-- * board: board_16f88_sl.jal
-- * test : test_ir_ranger_gp2d02.jal
--
-
;@jallib section chipdef
-- chip setup
include 16f88
@@ -41,14 +36,16 @@
pragma bootloader long_start -- for TinyBootloader
enable_digital_io()
-;@jallib section led
--- LED IO definition
-var bit led is pin_b3
-var bit led_direction is pin_b3_direction
-var bit led2 is pin_b1
-var bit led2_direction is pin_b1_direction
-include delay
+;@jallib section ccp
+-- ccp setup
+var volatile bit pin_ccp1_direction is pin_b0_direction
+-- Configure PWM
+pin_ccp1_direction = output
+include pwm_hardware
+pwm_max_resolution(1)
+pwm1_on()
+
;@jallib section serial
const serial_hw_baudrate = 57_600
include serial_hardware
@@ -61,50 +58,17 @@
var bit gp2d02_vout_direction is pin_a6_direction
include ir_ranger_gp2d02
-- set pin direction (careful: "vin" is the GP2D02 pin's name,
--- and is an output, not an input...)
+-- it's an input for GP2D02, but an output for PIC !)
gp2d02_vin_direction = output
gp2d02_vout_direction = input
--- now register these pins as ranger num. 0
-gp2d02_register(0,gp2d02_vin,gp2d02_vout)
-
--- Flash a litlle to show we're alive !
-led_direction = output
-for 4 loop
- LED = on
- delay_100ms(3)
- LED = off
- delay_100ms(3)
-end loop
-
-var byte measure1
-var byte measure2
-var byte mean
-var word tmp
+var byte measure
forever loop
-
-- read distance from ranger num. 0
- measure1 = gp2d02_read(0)
- -- you can also pass a couple of (pin_vin,pin_vout)
- -- to save stack and code space
- measure2 = gp2d02_read_pins(gp2d02_vin,gp2d02_vout)
+ measure = gp2d02_read_pins(gp2d02_vin,gp2d02_vout)
-- results via serial
- serial_hw_write(measure1)
- serial_hw_write(measure2)
- -- compute the mean
- tmp = (measure1 + measure2) / 2
- -- cast to byte (can't be more than byte, since
- -- it's a mean...)
- mean = byte(tmp)
- serial_hw_write(measure2)
-
+ serial_hw_write(measure)
-- now blink more or less
- for 10 loop
- LED = on
- delay_1ms(mean)
- LED = off
- delay_1ms(mean)
- end loop
-
+ pwm1_set_dutycycle(measure)
end loop
Modified: trunk/test/external/ranger/ir/test_ir_ranger_gp2d02.jal
==============================================================================
--- trunk/test/external/ranger/ir/test_ir_ranger_gp2d02.jal (original)
+++ trunk/test/external/ranger/ir/test_ir_ranger_gp2d02.jal Fri Apr 10
01:02:36 2009
@@ -1,20 +1,16 @@
-- Title: Test program for GP2D02 IR ranger
-- Author: Sebastien Lelong, Copyright (c) 2008-2009, all rights reserved.
-- Adapted-by:
--- Compiler: >=2.4j
+-- Compiler: >=2.4k
--
-- 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 GP2D02 IR ranger library
-- It regularly gets distance measures, and print them back to serial.
--- It also uses a LED to "show" the distance:
--- - when the distance is low (object is closed from the ranger),
--- the LED will blink very fast
--- - when the distance is high (object is far way from the ranger),
--- the LED will blink very slow
--- - when the distance is to high (nothing detected), the LED is on, no
--- blinking
+-- It also uses a led to "show" the distance. This LED is connected to a
PWM output.
+-- it will be more or less bright according to the distance between the
ranger
+-- and an object.
-- --
--
--
@@ -22,9 +18,14 @@
;@jallib use chipdef
enable_digital_io()
-;@jallib use led
-include delay
+;@jallib use ccp
+-- Configure PWM
+pin_ccp1_direction = output
+include pwm_hardware
+pwm_max_resolution(1)
+pwm1_on()
+
;@jallib use serial
include serial_hardware
@@ -34,50 +35,18 @@
;@jallib use gp2d02
include ir_ranger_gp2d02
-- set pin direction (careful: "vin" is the GP2D02 pin's name,
--- and is an output, not an input...)
+-- it's an input for GP2D02, but an output for PIC !)
gp2d02_vin_direction = output
gp2d02_vout_direction = input
--- now register these pins as ranger num. 0
-gp2d02_register(0,gp2d02_vin,gp2d02_vout)
-
-
--- Flash a litlle to show we're alive !
-led_direction = output
-for 4 loop
- LED = on
- delay_100ms(3)
- LED = off
- delay_100ms(3)
-end loop
-var byte measure1
-var byte measure2
-var byte mean
-var word tmp
+var byte measure
forever loop
-
-- read distance from ranger num. 0
- measure1 = gp2d02_read(0)
- -- you can also pass a couple of (pin_vin,pin_vout)
- -- to save stack and code space
- measure2 = gp2d02_read_pins(gp2d02_vin,gp2d02_vout)
+ measure = gp2d02_read_pins(gp2d02_vin,gp2d02_vout)
-- results via serial
- serial_hw_write(measure1)
- serial_hw_write(measure2)
- -- compute the mean
- tmp = (measure1 + measure2) / 2
- -- cast to byte (can't be more than byte, since
- -- it's a mean...)
- mean = byte(tmp)
- serial_hw_write(measure2)
-
+ serial_hw_write(measure)
-- now blink more or less
- for 10 loop
- LED = on
- delay_1ms(mean)
- LED = off
- delay_1ms(mean)
- end loop
-
+ pwm1_set_dutycycle(measure)
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
-~----------~----~----~----~------~----~------~--~---