Exemplo n.º 1
0
        /// <summary>
        /// Initializes the display by setting the specified columns and lines.
        /// </summary>
        private void Initialize(int rows)
        {
            // While the chip supports 5x10 pixel characters for one line displays they
            // don't seem to be generally available. Supporting 5x10 would require extra
            // support for CreateCustomCharacter
            if (GetTwoLineMode(rows))
            {
                _displayFunction |= DisplayFunction.TwoLine;
            }

            _displayControl |= DisplayControl.DisplayOn;
            _displayMode    |= DisplayEntryMode.Increment;

            ReadOnlySpan <byte> commands = stackalloc byte[]
            {
                // Function must be set first to ensure that we always have the basic
                // instruction set selected. (See PCF2119x datasheet Function_set note
                // for one documented example of where this is necessary.)
                (byte)_displayFunction,
                (byte)_displayControl,
                (byte)_displayMode,
                ClearDisplayCommand
            };

            SendCommands(commands);
        }
Exemplo n.º 2
0
        /// <summary>
        /// Initializes the display by setting the specified columns and lines.
        /// </summary>
        private void Initialize(int rows)
        {
            // Setup 4-bit mode
            // See Figure 24, on page 46

            // Wait for startup
            WaitForNotBusy(15000);

            // While the chip supports 5x10 pixel characters for one line displays they
            // don't seem to be generally available. Supporting 5x10 would require extra
            // support for CreateCustomCharacter

            // if (SetTwoLineMode(rows))
            //     _displayFunction |= DisplayFunction.TwoLine;

            _displayControl |= DisplayControl.DisplayOn;
            _displayMode    |= DisplayEntryMode.Increment;
            ReadOnlySpan <byte> commands = stackalloc byte[]
            {
                // Function must be set first to ensure that we always have the basic
                // instruction set selected. (See PCF2119x datasheet Function_set note
                // for one documented example of where this is necessary.)
                // @@ ReturnHomeCommand,    // 0x02
                // (byte)_displayFunction,  // 0x28
                (byte)_displayControl,      // 0x0c
                ClearDisplayCommand,        // 0x01
                (byte)_displayMode,         // 0x06
                (byte)0x80,                 // 0x80 - Sets address
                // (byte)0x0E,                 // 0x0E <-- not valid?
            };

            SendCommands(commands);
        }
Exemplo n.º 3
0
        /// <summary>
        /// Initializes the display by setting the specified columns and lines.
        /// </summary>
        protected void Initialize(int rows)
        {
            // While the chip supports 5x10 pixel characters for one line displays they
            // don't seem to be generally available. Supporting 5x10 would require extra
            // support for CreateCustomCharacter

            if (SetTwoLineMode(rows))
            {
                _displayFunction |= DisplayFunction.TwoLine;
            }

            _displayControl |= DisplayControl.DisplayOn;
            _displayMode    |= DisplayEntryMode.Increment;

            InitializeBitMode();

            // The busy flag cannot be checked until this point.

            Send((byte)_displayFunction);
            Send((byte)_displayControl);
            Send((byte)_displayMode);
            Clear();
        }
Exemplo n.º 4
0
        /// <summary>
        /// Initializes the display by setting the specified columns and lines.
        /// </summary>
        private void Initialize(int rows)
        {
            // While the chip supports 5x10 pixel characters for one line displays they
            // don't seem to be generally available. Supporting 5x10 would require extra
            // support for CreateCustomCharacter

            if (SetTwoLineMode(rows))
            {
                _displayFunction |= DisplayFunction.TwoLine;
            }

            _displayControl |= DisplayControl.DisplayOn;
            _displayMode    |= DisplayEntryMode.Increment;

            // Prep the pins
            _controller.OpenPin(_rsPin, PinMode.Output);

            if (_rwPin != -1)
            {
                _controller.OpenPin(_rwPin, PinMode.Output);
            }
            if (_backlight != -1)
            {
                _controller.OpenPin(_backlight, PinMode.Output);
                if (_backlightBrightness > 0)
                {
                    // Turn on the backlight
                    _controller.Write(_backlight, PinValue.High);
                }
            }
            _controller.OpenPin(_enablePin, PinMode.Output);

            for (int i = 0; i < _dataPins.Length; ++i)
            {
                _controller.OpenPin(_dataPins[i], PinMode.Output);
            }

            // The HD44780 self-initializes when power is turned on to the following settings:
            //
            //  - 8 bit, 1 line, 5x7 font
            //  - Display, cursor, and blink off
            //  - Increment with no shift
            //
            // It is possible that the initialization will fail if the power is not provided
            // within specific tolerances. As such, we'll always perform the software based
            // initialization as described on pages 45/46 of the HD44780 data sheet. We give
            // a little extra time to the required waits.

            if (_dataPins.Length == 8)
            {
                // Init to 8 bit mode
                DelayMicroseconds(50_000, checkBusy: false);
                Send(0b0011_0000);
                DelayMicroseconds(5_000, checkBusy: false);
                Send(0b0011_0000);
                DelayMicroseconds(100, checkBusy: false);
                Send(0b0011_0000);
            }
            else
            {
                // Init to 4 bit mode, setting _rspin to low as we're writing 4 bits directly.
                // (Send writes the whole byte in two 4bit/nybble chunks)
                _controller.Write(_rsPin, PinValue.Low);
                DelayMicroseconds(50_000, checkBusy: false);
                WriteBits(0b0011, 4);
                DelayMicroseconds(5_000, checkBusy: false);
                WriteBits(0b0011, 4);
                DelayMicroseconds(100, checkBusy: false);
                WriteBits(0b0011, 4);
                WriteBits(0b0010, 4);
            }

            // The busy flag cannot be checked until this point.

            Send((byte)_displayFunction);
            Send((byte)_displayControl);
            Send((byte)_displayMode);
            Clear();
        }