Online Development Notebook > Index > U4x1 Application Notes > App14: 2-Wire to PCF8574 > App14: PCF8574 output using VB6 and USBm.dll

App14: PCF8574 output using VB6 and USBm.dll


VB Project

This example demonstrates control of a PCF8574 using Visual Basic 6. This VB project builds on the established code base of all of the other example VB projects. The specifics for interfacing to the PCF8574 are described below.

2-wire interface support is in USBm.dll version 65 or newer. You must also use a device with version 3.35 of the device firmware in order to have the 2-wire functionality.

Send a command to the U4x1

' Write to PCF8574
Private Sub Write8574_Click()

    ' Send init control signal (both lines high)
    USBm_Wire2Control selectedu4x1, 0

    ' Send start control signal (drop data line low )
    USBm_Wire2Control selectedu4x1, 1

    ' Send address byte
    dataarray(0) = 0
    dataarray(1) = 1
    dataarray(2) = &H70
    USBm_Wire2Data selectedu4x1, dataarray(0)

    ' Send data to light up the LEDs
    dataarray(0) = 0
    dataarray(1) = 1
    dataarray(2) = ReturnHexByte(Write0Value.Text)
    USBm_Wire2Data selectedu4x1, dataarray(0)

    ' Send stop control signal (clock high, then data high)
    USBm_Wire2Control selectedu4x1, 2

    State = ReturnHexByte(Write0Value.Text)

    End Sub

This code illustrates the steps needed to address and control the PCF8574.

The VB6 code fragmant above sends a byte to the PCF8574 to display on the LEDs. Assuming that the hardware is as described in the hardware section of this app note, then PA.3 of the U4x1 is the 2-wire data line, while PA.2 is the 2-wire clock line. These connect to the PCF8574 chip.

The first command in the program listing above distinct to 2-wire control is the init command USBm_Wire2Control selected4x1, 0. The Wire2Control function sends one of several conditions to the two port lines. Three different ones are used here in this code fragment. The first one initialized the port to be open drain and allows the output to be pulled high by external pull-up resistors.

The second Wire2Control command is the command that acts like the "start" condition for I2C. The third Wire2Control command is after the byte writes and makes the two 2-wire lines act like the "stop" condition for I2C.

After the I2C start conditon and before the I2C stop condition the code fragment sends out two clocked bytes using two calls to the USBm_Wire2Data command. The first byte correctly addresses the PCF8574 (see the data sheet for details) and the second byte is the pattern to display on the LEDs.

Download Code

Download all application files: (all application files)


Hardware:  U401 USB Interface    U421 USB Interface   U451 USB Interface

Programming:  USBm DLL Programming    Download Files

Application Notes:  U4x1 Application Notes    Misc Applications and Information    FAQ

While every effort has been made to make sure that the information posted on this site is correct, the author can not be held liable for any damages whatsoever for losses as a result of the application of this information. Use this information at your own risk.

USBmicro can design your custom and semi-custom USB product. Email about USB design can be directed to " Robert " at usbmicro.com.

Copyright © USBmicro, L.L.C., 2002-2010

Previous  |  Next ]     [ Up  |  First  |  Last ]     (Article 110 of 126)

This page is created with TreePad