'My own IO settings
#define SWX PORTC.2 ; input pin from pushbuttons (A,B,C,D)
#define Led PORTC.5 ; output pin for led
#define SoundOut PORTC.0 ; output pin for tone
Dir SWX in ; set port as input for pushbuttons
'Settings for DS1820
#define DQ PortD.0 ; input pin DS1820/DS18S20 with external pullup 4K7
;poke(0x50, Peek(0x50) Or 4) ; PUD on = internal Pullup off (only for atmega8)
Dim DSM(9) as byte ; DS memory bytes
IntOff ; switch off interrupts (if you use them)
; show temperature of 4 x DS18S20 on 1 bus; adapt the IDs with your own sensors
; include the adapted DS18S20_ADP.H
Do
DSM(1)=16:DSM(2)=108:DSM(3)=17:DSM(4)=219:DSM(5)=1:DSM(6)=8:DSM(7)=0:DSM(8)=188
DS18S20MatchRom
locate 0,0:gosub ShowTemp
sub Showtemp
if DSM(2).7 1 then ; bit 7-1 of DSM(2) are 1 if temp = below zero
DSM(1)= (NOT DSM(1))+1 ; 2 complement for negative values
print "-"
else
Print " "
end if
print DSM(1)/2
If DSM(1).0 = 1 then
print ".5"
else
print ".0"
end if
print CHR(223):print "C"
end sub
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Based on the adapted DS18S20.h: multiple sensors on 1 bus.
4 x DS18S20 on a single bus, No parasite power mode.
Tested with a clockspeed from 1 to 8 Mhz, not tested with a long wire.
#chip mega8,8
#include <74LS164.h> ; include My IO 74LS164
#include <DS18S20_ADP.h>
'Use LCD in 2 pin mode with 74LS164 / 74HC164
#define LCD_IO 2
#define LCD_DB PORTC.0 ; databit
#define LCD_CB PORTC.1 ; clockbit
#define LCD_NO_RW
'My own IO settings
#define SWX PORTC.2 ; input pin from pushbuttons (A,B,C,D)
#define Led PORTC.5 ; output pin for led
#define SoundOut PORTC.0 ; output pin for tone
Dir SWX in ; set port as input for pushbuttons
'Settings for DS1820
#define DQ PortD.0 ; input pin DS1820/DS18S20 with external pullup 4K7
;poke(0x50, Peek(0x50) Or 4) ; PUD on = internal Pullup off (only for atmega8)
Dim DSM(9) as byte ; DS memory bytes
IntOff ; switch off interrupts (if you use them)
; show temperature of 4 x DS18S20 on 1 bus; adapt the IDs with your own sensors
; include the adapted DS18S20_ADP.H
Do
DSM(1)=16:DSM(2)=108:DSM(3)=17:DSM(4)=219:DSM(5)=1:DSM(6)=8:DSM(7)=0:DSM(8)=188
DS18S20MatchRom
locate 0,0:gosub ShowTemp
DSM(1)=16:DSM(2)=49:DSM(3)=33:DSM(4)=219:DSM(5)=1:DSM(6)=8:DSM(7)=0:DSM(8)=92
DS18S20MatchRom
print " ":gosub ShowTemp
DSM(1)=16:DSM(2)=217:DSM(3)=150:DSM(4)=170:DSM(5)=2:DSM(6)=8:DSM(7)=0:DSM(8)=9
DS18S20MatchRom
locate 1,0:gosub ShowTemp
DSM(1)=16:DSM(2)=247:DSM(3)=49:DSM(4)=171:DSM(5)=2:DSM(6)=8:DSM(7)=0:DSM(8)=65
DS18S20MatchRom
print " ":gosub Showtemp
Loop
sub Showtemp
if DSM(2).7 1 then ; bit 7-1 of DSM(2) are 1 if temp = below zero
DSM(1)= (NOT DSM(1))+1 ; 2 complement for negative values
print "-"
else
Print " "
end if
print DSM(1)/2
If DSM(1).0 = 1 then
print ".5"
else
print ".0"
end if
print CHR(223):print "C"
end sub
DS18S20_ADP.h