Menu

Exercises with a single sensor DS18S20

Theo
2014-10-21
2014-10-21
  • Theo

    Theo - 2014-10-21

    Exercises with a single sensor DS18S20

    with an adapted DS18S20.h and a single sensor (1820/18S20) showing the temperature, internal registers and the 64 bit ID.
    Tested with a clockspeed from 1 to 8 Mhz.

    No parasite power mode, no error checking by CRC; no testing with a long wire(something for the future).

    I'm sure that this is not the most excellent code, but for the daily use it works fine.


    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

    '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)

    ; Some exercises with single DS1820/18S20 and an adapted DS18S20.h

    Do
    DS18S20ReadTemp ; display temp from single DS
    cls
    locate 0,0:print "Temp: "
    if DSM(2).7 1 then
    DSM(1)= (NOT DSM(1))+1 ; 2 complement for negative values
    print "-"
    end if
    print DSM(1)/2
    If DSM(1).0 1 Then
    Print ".5"
    else
    Print ".0"
    end if
    print " ":Print chr(223):print "C."
    wait 3 S
    DS18S20ReadReg ; display the registers from single DS as hex values
    CLS
    print "Reg: "
    for index = 1 to 4
    print Hex(DSM(index)):print " "
    next
    locate 1,0
    for index = 5 to 9
    print Hex(DSM(index)):print " "
    next
    wait 3 S
    DS18S20ReadRom ; display 64 bit ID from single DS1820/DS18S20
    CLS
    if DSM(1)=0x10 then print "1820/18S20"
    if DSM(1)=0x28 then Print "18B20"
    if DSM(1)<>0x10 AND DSM(1)<>0x28 Then print "Unknown Fam."
    print " ":print hex(DSM(1)) ; DSM(1) = Family
    locate 1,0
    for index = 2 to 8 ; DSM(2-7) = ID; ignore displaying MSB first; bit 7 to 2
    print Hex(DSM(index)) ; DSM(8) = CRC
    next
    wait 3 S
    Loop


     
  • Theo

    Theo - 2014-10-21

    DS18S20_ADP.h

     

Log in to post a comment.

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.