• Pic« Basic

  • Ds2438 code

    The DS2438 is a battery monitor IC using the 1-Wire protocol. It measures temperature, voltage and current to name just three of its functions.

    Below is the code I've come up with that reads temperature, voltage and current and displays on LCD.
    '*  Name    : DS2438.BAS                                        *
    '*  Author  : Flosi Gu­mundsson                                 *
    '*  Notice  : Copyright (c) 2010 Flosi Gu­mundsson              *
    '*          : All Rights Reserved                               *
    '*  Date    : 13/03/2010                                        *
    '*  Version : 1.0                                               *
    '*  Notes   :  Pogram reads temperature, voltage and current    *
    '*          :  from DS2438 and displays on LCD                  *
            Include    "18F452.BAS"
            Symbol DQ = PORTA.4                             'DS2438 I/O port bit
            Dim Temp As Word                      'Temperature low/high bytes 
            Dim NEGPOS As Byte                      'Temperature char "-" or "+"
            Dim Result As Byte
            Dim Con As Byte
            Dim Volts As Word
            Dim Amps As Word
            Dim threshold As Byte
            Dim crc As Byte
            Dim mod As Byte
            DelayMS 500
    '        OWrite DQ, 3, [$CC,$4E,$00,$0F]        ' Skip Rom,Write_Scratchpad,Page0, measure Vdd
            OWrite DQ, 3, [$CC,$4E,$00,$07]        ' Skip Rom,Write_Scratchpad,Page0, measure Vad
    loop:    DelayMS 1000
            OWrite DQ,3,[$CC,$44]               ' Skip Rom,Convert_T
            '    DelayMS 10
                ORead DQ,4,[Result]
            Until Result=1        
            OWrite DQ,1,[$CC,$B4]                ' Skip Rom,Convert_V
            OWrite DQ,3,[$CC,$B8,$00]           ' Skip Rom,Recall_Memory
            OWrite DQ,1,[$CC,$BE,$00]           ' Skip Rom,Read_Scratchpad
            ORead DQ,2,[Con,Temp.LowByte,Temp.HighByte,Volts.LowByte,Volts.HighByte,Amps.LowByte,Amps.HighByte,threshold,crc]
            '    DelayMS 10
                ORead DQ,4,[Result]
            Until Result=1
            If Temp.15 = 1 Then
            NEGPOS = "-"
            Temp = ~Temp + 1
            NEGPOS = "+"
            Print At 0,0, NEGPOS, Dec Temp.HighByte,".",
            Temp.LowByte=Temp.LowByte>>3 Temp.LowByte                   
            Print Dec2 Temp.LowByte *3125
            NEGPOS = "+"
            mod =Volts//100        
            Print At 1,0,Dec Volts/100,".",Dec2 mod,"V"
            Print At 2,0, Dec Amps/(4096*.1)
            GoTo loop
    This article was originally published in forum thread: Ds2438 code started by flosi View original post
  • Recent Activity


    PIC18F1330 PLL problem

    Thread Starter: rcurl

    I'm just starting out on a new project that uses a PIC18F1330. I haven't used this specific chip before, so I began by trying to blink an LED just...

    towlerg Yesterday, 16:26 Go to last post

    Pic16f18877 oread

    Thread Starter: evoortman

    Hi, On a PIC16F18877 the OREAD command doesn't seem to work. The code is working on a PIC16F1939. Both controllers use 32MHz int osc. If i...

    towlerg Yesterday, 16:25 Go to last post

    MID$ Problem with a PIC18F25K22

    Thread Starter: palamont

    Hi everybody, I encounter a strange problem : I have a string of 230 characters. This string is divided into 10 segments of 23 characters, with a...

    palamont Yesterday, 10:08 Go to last post