My favorites | Sign in
Project Home Downloads Wiki Issues Source
Checkout   Browse   Changes    
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
-- Title: Test program for GP2D02 IR ranger
-- Author: Sebastien Lelong, Copyright (c) 2008-2009, all rights reserved.
-- Adapted-by:
-- Compiler: >=2.4k
-- Revision: $Revision$
--
-- 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. 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.
-- --
--


;@jallib section chipdef
-- chip setup
include 16f88

;--
-- We'll use internal oscillator. It work @ 8MHz
pragma target clock 8_000_000
pragma target OSC INTOSC_NOCLKOUT
-- Specify no postscaler, ie. really runs @8MHz
OSCCON_IRCF = 0b_111
pragma target WDT disabled -- no watchdog
pragma target LVP disabled -- no low-voltage programming
pragma target CCP1MUX pin_B0 -- ccp1 pin on B0
pragma bootloader long_start -- for TinyBootloader

enable_digital_io()

;@jallib section ccp
-- ccp setup: since CCP1 is multiplexed, we need to define
-- alias pointing to the active CCP1 pin
alias pin_ccp1_direction is pin_ccp1_rb0_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
serial_hw_init()

;@jallib section gp2d02
alias gp2d02_vin is pin_a4
alias gp2d02_vout is pin_a6
alias gp2d02_vin_direction is pin_a4_direction
alias gp2d02_vout_direction is pin_a6_direction
include ir_ranger_gp2d02
-- set pin direction (careful: "vin" is the GP2D02 pin's name,
-- it's an input for GP2D02, but an output for PIC !)
gp2d02_vin_direction = output
gp2d02_vout_direction = input

var byte measure
forever loop
-- read distance from ranger num. 0
measure = gp2d02_read_pins(gp2d02_vin,gp2d02_vout)
-- results via serial
serial_hw_write(measure)
-- now blink more or less
pwm1_set_dutycycle(measure)
end loop

Change log

r3044 by sebastien.lelong on Apr 22, 2012   Diff
save samples from apocalypse
Go to: 
Project members, sign in to write a code review

Older revisions

r2760 by sebastien.lelong on Jul 31, 2011   Diff
added Revision: field + svn:keywords
Revision property on all existing
*.jal files. Also add to normalize EOL
chars to avoid mixed ones
r1428 by robhamerling on Oct 29, 2009   Diff
Samples updated for changes in device
files revision 1427

r1220 by sebastien.lelong on Aug 18, 2009   Diff
var...is to alias...is
All revisions of this file

File info

Size: 2185 bytes, 71 lines

File properties

svn:keywords
Revision
Powered by Google Project Hosting