fl { GP2Y0E03 PropForth 5.5 2014/07/07 21:03:19 3.3V | -----| | |2SA1015 3.3V 10k E |1 |----B ------------------- C C 4| Vdd |6 P0 --1k-----B |--------|VIO SCL|------ Prop SCL | E | GP2Y0E03 |7 1k |2SA1815 | SDA|------ Prop SDA | | | GPIO1 GND | GND GND ------------------- |5 |3 | GND P1 ------------------------------ } \ =========================================================================== \ Constants \ =========================================================================== \ Slave addres h40 for GP2Y0E03 h80 wconstant GP2Y0E03 \ VIN(IO) 0 wconstant VIN 1 wconstant GPIO1 \ =========================================================================== \ Main \ =========================================================================== : tab 9 emit ; \ Power up GP2Y0E03 \ ( -- ) : PowerUp \ Power up VIN and GPIO1 5 delms \ Supply 3.3V to VIN GPIO1 pinout VIN pinout VIN pinhi GPIO1 pinhi ; \ Power down GP2Y0E03 \ ( -- ) : PowerDn GPIO1 pinlo _scll _sclo \ Set scl to lo _sdal _sdao \ Set sda to lo \ Cut off VIN VIN pinlo _scli \ Release scl _sdai \ Release sda ; \ Software reset \ ( -- ) : soft_reset 0 hEF GP2Y0E03 i2c_wr err? \ Select Bank 0 hFF hEC GP2Y0E03 i2c_wr err? \ Set clock to manual 6 hEE GP2Y0E03 i2c_wr err? \ software reset h7F hEC GP2Y0E03 i2c_wr err? \ Set clock to auto ; \ Display all register \ ( -- ) : disp_rg hex 3 GP2Y0E03 i2c_rd err? ." Hold bit" tab tab tab .byte cr h13 GP2Y0E03 i2c_rd err? ." Maximum Emitting Pulse Width" tab .byte cr h1C GP2Y0E03 i2c_rd err? ." Spot Symmetry Thresgold" tab tab .byte cr h2F GP2Y0E03 i2c_rd err? ." Signal Intensity Threshold" tab .byte cr h33 GP2Y0E03 i2c_rd err? ." Maximum Spot Size Threshold" tab .byte cr h34 GP2Y0E03 i2c_rd err? ." Minimum Spot Size Threshold" tab .byte cr h35 GP2Y0E03 i2c_rd err? ." Shift Bit" tab tab tab .byte cr h3F GP2Y0E03 i2c_rd err? ." Median Filter" tab tab tab .byte cr h4C GP2Y0E03 i2c_rd err? ." SRAM Access" tab tab tab .byte cr h5E GP2Y0E03 i2c_rd err? ." Distance[11:4]" tab tab tab .byte cr h5F GP2Y0E03 i2c_rd err? ." Distance[3:0]" tab tab tab .byte cr h64 GP2Y0E03 i2c_rd err? ." AE[15:8]" tab tab tab .byte cr h65 GP2Y0E03 i2c_rd err? ." AE[7:0]" tab tab tab tab .byte cr h67 GP2Y0E03 i2c_rd err? ." AG[7:0]" tab tab tab tab .byte cr h8D GP2Y0E03 i2c_rd err? ." Cover Compensation[5:0]" tab tab .byte cr h8E GP2Y0E03 i2c_rd err? ." Cover Compensation[10:6]" tab .byte cr h8F GP2Y0E03 i2c_rd err? ." Cover Compensation Enable Bit" tab .byte cr h90 GP2Y0E03 i2c_rd err? ." Read out ImageSensor data" tab .byte cr hA8 GP2Y0E03 i2c_rd err? ." Signal Accumlation Number" tab .byte cr hBC GP2Y0E03 i2c_rd err? ." Enable Bit(Signal Intensity)" tab .byte cr hBD GP2Y0E03 i2c_rd err? ." Enable Bit(Miniumum spot size)" tab .byte cr hBE GP2Y0E03 i2c_rd err? ." Enable Bit(Maximum spot size)" tab .byte cr hBF GP2Y0E03 i2c_rd err? ." Enable Bit(Spot symmetry)" tab .byte cr hC8 GP2Y0E03 i2c_rd err? ." E-Fuse Target Address" tab tab .byte cr hC9 GP2Y0E03 i2c_rd err? ." E-Fuse Bit Number" tab tab .byte cr hCA GP2Y0E03 i2c_rd err? ." E-Fuse Program Enable Bit" tab .byte cr hCD GP2Y0E03 i2c_rd err? ." E-Fuse Program Data" tab tab .byte cr hE8 GP2Y0E03 i2c_rd err? ." Active/StandBy State Control" tab .byte cr hEC GP2Y0E03 i2c_rd err? ." Clock Select" tab tab tab .byte cr hEE GP2Y0E03 i2c_rd err? ." Software Reset" tab tab tab .byte cr hEF GP2Y0E03 i2c_rd err? ." Bank Select" tab tab tab .byte cr hF8 GP2Y0E03 i2c_rd err? ." Right Edge Coordinate(C)" tab .byte cr hF9 GP2Y0E03 i2c_rd err? ." Left Edge Coordinate(A)" tab tab .byte cr hFA GP2Y0E03 i2c_rd err? ." Peak Coordinate(B)" tab tab .byte cr decimal ; \ Display distance \ ( -- ) : Get_distance 2 h5E GP2Y0E03 i2c_rd_multi err? hF and \ distance[3:0] swap d16 u* \ distance[11:4]x16 + \ ( distance[11:4]x16+distance[3:0] ) d16 h35 GP2Y0E03 i2c_rd err? \ Shift_bit 1 = if 2 else 4 then \ ( distance[11:4]x16+distance[3:0] 16 2/4 ) u/ u/ \ distance value ; : test begin Get_distance . cr 500 delms fkey? swap drop until ;