/// <summary>
        /// Construct a standard Hd44780-compatible character display driven from the commonly-available Pcf8574 backpack.
        /// </summary>
        /// <param name="ioExpander">A Pcf8574 instance to use.</param>
        /// <param name="columns">The number of columns in the display (defaults to 16)</param>
        /// <param name="rows">The number of rows in the display (defaults to 2)</param>
        /// <returns>An Hd44780 object supporting standard CharacterDisplay methods.</returns>
        /// <remarks>
        /// <para>
        /// This factory method takes an already-created <see cref="Pcf8574"/>, creates a <see cref="FlushableParallelInterface{PortExpanderPin}"/>
        /// parallel interface for it, assigns the correct pinout to this interface, and constructs a <see cref="Hd44780"/>
        /// display using this interface, using the slower 4-bit mode for operation.
        /// </para>
        /// <para>
        /// If you wish to produce custom hardware compatiable with this factory method, the correct pinout is:
        /// <list type="number">
        /// <item><term>Register Select (RS)</term><description>Pin 0</description></item>
        /// <item><term>Read/Write (RW)</term><description>Pin 1</description></item>
        /// <item><term>Enable (E)</term><description>Pin 2</description></item>
        /// <item><term>Backlight Enable</term><description>Pin 3</description></item>
        /// <item><term>Data 4</term><description>Pin 4</description></item>
        /// <item><term>Data 5</term><description>Pin 5</description></item>
        /// <item><term>Data 6</term><description>Pin 6</description></item>
        /// <item><term>Data 7</term><description>Pin 7</description></item>
        /// </list>
        /// 
        /// Note that when the Hd44780 is operated in 4-bit mode, only the high-nibble (D4-D7) is used, not the low-nibble.
        /// </para>
        /// </remarks>
        public static Hd44780 GetCharacterDisplayFromPcf8574(Pcf8574 ioExpander, int columns = 16, int rows = 2)
        {
            var parallelInterface = new FlushableParallelInterface<PortExpanderPin>(ioExpander);

            parallelInterface.RegisterSelectPin = ioExpander.Pins[0];
            parallelInterface.ReadWritePin = ioExpander.Pins[1];
            parallelInterface.EnablePin = ioExpander.Pins[2];

            parallelInterface.DataBus.Add(ioExpander.Pins[4]);
            parallelInterface.DataBus.Add(ioExpander.Pins[5]);
            parallelInterface.DataBus.Add(ioExpander.Pins[6]);
            parallelInterface.DataBus.Add(ioExpander.Pins[7]);

            parallelInterface.Enabled = true;

            return new Hd44780(parallelInterface, columns, rows, ioExpander.Pins[3]);
        }
Beispiel #2
0
        /// <summary>
        ///     Construct a standard Hd44780-compatible character display driven from the commonly-available Pcf8574 backpack.
        /// </summary>
        /// <param name="ioExpander">A Pcf8574 instance to use.</param>
        /// <param name="columns">The number of columns in the display (defaults to 16)</param>
        /// <param name="rows">The number of rows in the display (defaults to 2)</param>
        /// <returns>An Hd44780 object supporting standard CharacterDisplay methods.</returns>
        /// <remarks>
        ///     <para>
        ///         This factory method takes an already-created <see cref="Pcf8574" />, creates a
        ///         <see cref="FlushableParallelInterface{T}" />
        ///         parallel interface for it, assigns the correct pinout to this interface, and constructs a
        ///         <see cref="Hd44780" />
        ///         display using this interface, using the slower 4-bit mode for operation.
        ///     </para>
        ///     <para>
        ///         If you wish to produce custom hardware compatiable with this factory method, the correct pinout is:
        ///         <list type="number">
        ///             <item>
        ///                 <term>Register Select (RS)</term><description>Pin 0</description>
        ///             </item>
        ///             <item>
        ///                 <term>Read/Write (RW)</term><description>Pin 1</description>
        ///             </item>
        ///             <item>
        ///                 <term>Enable (E)</term><description>Pin 2</description>
        ///             </item>
        ///             <item>
        ///                 <term>Backlight Enable</term><description>Pin 3</description>
        ///             </item>
        ///             <item>
        ///                 <term>Data 4</term><description>Pin 4</description>
        ///             </item>
        ///             <item>
        ///                 <term>Data 5</term><description>Pin 5</description>
        ///             </item>
        ///             <item>
        ///                 <term>Data 6</term><description>Pin 6</description>
        ///             </item>
        ///             <item>
        ///                 <term>Data 7</term><description>Pin 7</description>
        ///             </item>
        ///         </list>
        ///         Note that when the Hd44780 is operated in 4-bit mode, only the high-nibble (D4-D7) is used, not the low-nibble.
        ///     </para>
        /// </remarks>
        public static Hd44780 GetCharacterDisplayFromPcf8574(Pcf8574 ioExpander, int columns = 16, int rows = 2)
        {
            ioExpander.AutoUpdateWhenPropertyRead = false;
            var parallelInterface = new FlushableParallelInterface <PortExpanderPin>(ioExpander);

            parallelInterface.RegisterSelectPin = ioExpander.Pins[0];
            parallelInterface.ReadWritePin      = ioExpander.Pins[1];
            parallelInterface.EnablePin         = ioExpander.Pins[2];

            parallelInterface.DataBus.Add(ioExpander.Pins[4]);
            parallelInterface.DataBus.Add(ioExpander.Pins[5]);
            parallelInterface.DataBus.Add(ioExpander.Pins[6]);
            parallelInterface.DataBus.Add(ioExpander.Pins[7]);

            parallelInterface.Enabled = true;

            return(new Hd44780(parallelInterface, columns, rows, ioExpander.Pins[3]));
        }