Ultraschallsensor mit FlashForth auslesen

1. Breadboard
2. Programm

Auslesen der Entfernung in cm aus dem Ultraschallsensor SRF02 mit FlashForth über einen PIC-Microcontrolle.

Breadboard

Ultraschall

Programm

Benötigt i2c_base im Speicher.

-distsensor
marker -distsensor

$ff3a constant anselc
%1110000 constant addr-srf02 \ default 7-bit address for DS1621

: add-read-bit ( 7-bit-c -- 8-bit-c )
1 lshift 1 or
;

: add-write-bit ( 7-bit-c -- 8-bit-c )
1 lshift 1 invert and
;

: calcdist ( reg2 reg3 -- n )
swap 256 * +
;

: distance@ ( -- n )
addr-srf02 add-write-bit i2cws 0 i2c! $51 i2c! spen
#65 ms
addr-srf02 add-write-bit i2cws 2 i2c! spen
addr-srf02 add-read-bit i2cws i2c@ak i2c@nak
calcdist
;

: main ( -- )
%11000 anselc mclr
i2cinit
begin
distance@ .
#500 ms
key? until
;

main
1. März 2017 15:25:26
© 2017. Thomas Buschhardt. Some Rights Reserved. Alle hier genannten Marken sind Eigentum der jeweiligen Inhaber.