Proton BASIC Compiler - Ds2438 code

  • 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


    PICKitPlus Forum

    Thread Starter: evan

    PICkitPlus PICkitPlus is a total replacement for the existing Microchip PICkit2Ö and PICkit3Ö Windows GUI software. The PICkitPlus software ...

    rcurl Yesterday, 20:28 Go to last post
    John Drew-26

    Request for Assistance - PIC16F15323

    Thread Starter: gdesantis

    After having successfully programmed various enhanced PIC16 MCUs, I plan to use a PIC16F15323 in a new application. As always, I first start with a...

    John Drew Yesterday, 23:03 Go to last post