USBmicro

Your source for USB electrical device interface products.

  • Home
  • Services
    • Design
    • Contact USBmicro
  • Where to buy…

Delphi Interface Example

A customer was kind enough to share an example project for the U401/U421 centered around the 1-wire temperature device. The project was written in Delphi and is available for download (source and executable) here: http://www.circuitgizmos.com/files/u401delphi.zip

You can get the DS1822 from CircuitGizmos along with the U401 USB Interface and the U421 USB interface

2009-07-14_180854

Program and example features:
Port A is INPUTPort
A.7 is set for DS1822.
Port B is OUTPUT
Programmable scan rate
Programmable temperature threshold controls PortB.1
Option to log data to a local file
Optional choice of units
On-Demand temperature read

The example code is very readable, even if you don’t know object pascal. You can see just in this small part of code that reading a 1 wire device only takes resetting the bus and a few read and write commands. Easy-peasy.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
<span style="color: #008000;">
    // Reset device
    USBm_Reset1Wire( dev, pin );
 
    // Write "SkipRom" and "Conversion"
    USBm_Write1Wire( dev, $CC);
    USBm_Write1Wire( dev, $44);
    sleep(100);
    pin := $7;
    USBm_Reset1Wire( dev, pin );
 
    // Write "SkipRom" and "Read Scratch Pad"
    USBm_Write1Wire( dev, $CC);
    USBm_Write1Wire( dev, $BE);
 
    // Process Family Code "22" (DS18B22)
    // Read two bytes of temperature
    result := USBm_Read1Wire( dev, data[0]);
    temp := inttostr(data[1]);
    val(inttostr(data[1]),T2,result);
    comb :=  T2;
</span>

This example code is provided AS-IS without warranty for distribution as example coding for the U4x1 in Delphi. It is easy enough to implement similar projects using Visual Basic, C, REALbasic, or the free RobotBASIC.

Enjoy!

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

Documentation

Open all | Close all