• 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.
    Code:
    '****************************************************************
    '*  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
            Cls
                                  
    '        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
            Repeat
            '    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]
            Repeat
            '    DelayMS 10
                ORead DQ,4,[Result]
            Until Result=1
            If Temp.15 = 1 Then
            NEGPOS = "-"
            Temp = ~Temp + 1
            Else
            NEGPOS = "+"
            EndIf
            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
            End
    This article was originally published in forum thread: Ds2438 code started by flosi View original post
  • Recent Activity

    teo-16018

    Microsoft security essentials blues

    Thread Starter: shantanu@india

    Hi, A strange thing happened just now.My Windows 7 Micrsoft Sercurity Essentials suddenly gave a warning that prplus.exe(Compiler) is a potential...

    teo Today, 19:23 Go to last post
    pic-ignorant-1162

    Proton Runtime Error

    Thread Starter: Paulcc

    I have proton running well on my laptop, but after installing it on my desktop, I get the following runtime error: "Runtime Error 217 at 000709FC" I...

    pic-ignorant Yesterday, 22:11 Go to last post
    David Barker-251

    UMC bootloader 18F46K22

    Thread Starter: shunt010

    Hi all. I am trying to build a UMC bootloader file for the 18F46K22, and it doesn't appear to work. It returns (in the error log) Error ...

    David Barker Today, 11:20 Go to last post
    barak-1433

    SPI mssp

    Thread Starter: picprotonguy

    Just ordered Digital to Analog IC MCP4822 with SPI interface and immediately opened proton manual. I'm very disappointed, it looks like Proton...

    barak Today, 16:06 Go to last post