This project is read-only.

Toolbox.NETMF.Hardware.Ic74hc165


Toolbox.NETMF.Hardware.Ic74hc165(SPI_Module, LatchPin, Bytes, SpeedKHz)
Use this constructor if you want to use fast managed SPI
  • SPI_Module The SPI-module the chain is connected to
  • LatchPin The latch pin the chain is connected to
  • Bytes The amount of IC's in the chain (default: 1)
  • SpeedKHz The speed of the SPI bus (default: 1000)

Toolbox.NETMF.Hardware.Ic74hc165(ClockPin, DataPin, LatchPin, Bytes, SpeedKHz)
Use this constructor when using managed SPI is impossible for whatever reason
  • ClockPin The pin where the SPI SCLK is connected to
  • DataPin The pin where the SPI MISO is connected to
  • LatchPin The latch pin the chain is connected to
  • Bytes The amount of IC's in the chain (default: 1)
  • SpeedKHz The speed of the SPI bus (default: 1000)


Methods

  • DisableInterrupts() Disables all interrupts of all related pins
  • EnableInterrupts() Enables all interrupts of all related pins
  • Dispose() Releases the SPI pins (when using the bitbang constructor)

Property

How to connect

Toolbox.NETMF.Hardware.Ic74hc165.png

Sample code in C#

public static void Main()
{
    // Defining two 74HC165s daisychained on the SPI bus, pin 10 as latchpin
    Ic74hc165 IcInChain = new Ic74hc165(SPI_Devices.SPI1, Pins.GPIO_PIN_D10, 2);

    // Defines all 16 buttons
    IIRQPort[] Buttons = new IIRQPort[16];
    for (uint Counter = 0; Counter < 16; ++Counter)
    {
        Buttons[Counter] = IcInChain.Pins[Counter];
        Buttons[Counter].OnStateChange += new StateChange(Program_OnStateChange);
        Buttons[Counter].ID = Counter.ToString();
    }
    
    // Enables interrupts
    IcInChain.EnableInterrupts();

    // Wait infinite; let the events to their jobs
    Thread.Sleep(Timeout.Infinite);
}

static void Program_OnStateChange(IIRQPort Object, bool State, DateTime Time)
{
    Debug.Print("State changed of the 74HC165 port " + Object.ID.ToString() + " to " + State.ToString());
}

Sample code in VB

Sub Main()
    ' Defining two 74HC165s daisychained on the SPI bus, pin 10 as latchpin
    Dim IcInChain As Ic74hc165 = New Ic74hc165(SPI_Devices.SPI1, Pins.GPIO_PIN_D10, 2)
    
    ' Defines all 16 buttons
    ' Because 'WithEvents' variables cannot be typed as arrays, we need to allocate the events a bit different in Visual Basic, so we use the AddHandler method
    Dim Buttons(16) As IIRQPort
    For Counter = 0 To 15
        Buttons(Counter) = IcInChain.Pins(Counter)
        AddHandler Buttons(Counter).OnStateChange, AddressOf Program_OnStateChange
        Buttons(Counter).ID = Counter.ToString()
    Next
    
    ' Enables interrupts
    IcInChain.EnableInterrupts()
    
    ' Wait infinite; let the events to their jobs
    Thread.Sleep(Timeout.Infinite)
End Sub

Private Sub Program_OnStateChange(PinObject As IIRQPort, State As Boolean, Time As Date)
    Debug.Print("State changed of the 74HC165 port " + PinObject.ID.ToString() + " to " + State.ToString())
End Sub

Related documents

Last edited Jan 1, 2013 at 8:08 PM by Garrcomm, version 3