Temperatorsensor mit FlashForth auslesen

1. Breadboard
2. Programm

Auslesen der Temperaturwerte aus dem Temperatursensor DS1621 mit FlashForth über einen PIC-Microcontroller

Breadboard

ds1621.png

Programm

Benötigt i2c_base im Speicher.

-tempsensor
marker -tempsensor

$ff3a constant anselc
%1001000 constant addr-ds1621 \ 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
;

: sign-extend ( c -- n )
 dup $7f > if $ff80 or then
;

: init-ds1621 ( -- )
 addr-ds1621 add-write-bit i2cws $ee i2c! spen
 addr-ds1621 add-write-bit i2cws $aa i2c! spen
;

: degrees@ ( -- n )
 addr-ds1621 add-read-bit i2cws i2c@ak i2c@nak drop sign-extend
;

: main ( -- )
 %11000 anselc mclr
 i2cinit
 init-ds1621
 begin
  degrees@ .
  #1000 ms
 key? until
;
1. März 2017 15:02:44
© 2017. Thomas Buschhardt. Some Rights Reserved. Alle hier genannten Marken sind Eigentum der jeweiligen Inhaber.