Beispiel #1
0
        /// <summary>
        /// Sets interface data length (DL), number of display lines (N), and character font (F).
        /// </summary>
        /// <param name="characterFont">Character font</param>
        /// <param name="lines">Number of display lines</param>
        /// <param name="dataLength">Interface data length</param>
        private void FunctionSet(CharacterFont characterFont, byte lines, DataLength dataLength)
        {
            //  DB7 DB6 DB5 DB4 DB3 DB2 DB1 DB0
            //  0   0   1   DL  N   F   -   -

            byte funcSetCmd = FUNCTION_SET;

            // char font 5x10 dots
            if (characterFont == CharacterFont.Dots5x10)
            {
                funcSetCmd |= CHAR_FONT_5x10DOTS;
            }

            // max two display lines
            funcSetCmd |= (lines > 1) ? DISPLAY_LINES_2LINE : DISPLAY_LINES_1LINE;

            // 8 bit data length
            if (dataLength == DataLength.DataBit8)
            {
                funcSetCmd |= DATA_LENGTH_8BIT;
            }

            this.SendCommand(funcSetCmd); // 37 us (datasheet)
        }
Beispiel #2
0
        /// <summary>
        /// Sets interface data length (DL), number of display lines (N), and character font (F).
        /// </summary>
        /// <param name="characterFont">Character font</param>
        /// <param name="lines">Number of display lines</param>
        /// <param name="dataLength">Interface data length</param>
        private void FunctionSet(CharacterFont characterFont, byte lines, DataLength dataLength)
        {
            //  DB7 DB6 DB5 DB4 DB3 DB2 DB1 DB0
            //  0   0   1   DL  N   F   -   -

            byte funcSetCmd = FUNCTION_SET;

            // char font 5x10 dots
            if (characterFont == CharacterFont.Dots5x10)
                funcSetCmd |= CHAR_FONT_5x10DOTS;

            // max two display lines
            funcSetCmd |= (lines > 1) ? DISPLAY_LINES_2LINE : DISPLAY_LINES_1LINE;

            // 8 bit data length
            if (dataLength == DataLength.DataBit8)
                funcSetCmd |= DATA_LENGTH_8BIT;

            this.SendCommand(funcSetCmd); // 37 us (datasheet)
        }
Beispiel #3
0
        /// <summary>
        /// Execute display initialization
        /// </summary>
        /// <param name="characterFont">Character font</param>
        /// <param name="lines">Number of display lines</param>
        /// <param name="columns">Number of characters per lines (columns)</param>
        public void Initialize(CharacterFont characterFont, byte lines, byte columns)
        {
            // change default set (1 line) to 2 lines if requested
            if (lines > 1)
            {
                this.functionSet |= DISPLAY_LINES_2LINE;
            }

            this.lines   = lines;
            this.columns = columns;

            // change default set (5 x 8 dots) to 5 x 10 dots if requested
            if (characterFont == CharacterFont.Dots5x10)
            {
                this.functionSet |= CHAR_FONT_5x10DOTS;
            }

            // Wait for more than 40 ms after VCC rises to 2.7 V
            // (Wait for more than 15 ms after VCC rises to 4.5 V)
            Thread.Sleep(50);

            // initialization (datasheet pag. 45 fig. 23)
            if (this.provider.InterfaceDataMode == InterfaceDataMode._8Bit)
            {
                this.SendCommand((byte)(FUNCTION_SET | this.functionSet));
                // Wait for more than 4.1 ms
                Thread.Sleep(5);

                this.SendCommand((byte)(FUNCTION_SET | this.functionSet));
                // Wait for more than 100 μs
                Thread.Sleep(1);

                this.SendCommand((byte)(FUNCTION_SET | this.functionSet));
            }
            // initialization (datasheet pag. 46 fig. 24)
            else
            {
                this.SendCommand(FUNCTION_SET | DATA_LENGTH_8BIT);
                // Wait for more than 4.1 ms
                Thread.Sleep(5);

                this.SendCommand(FUNCTION_SET | DATA_LENGTH_8BIT);
                // Wait for more than 4.1 ms
                Thread.Sleep(5);

                this.SendCommand(FUNCTION_SET | DATA_LENGTH_8BIT);
                // Wait for more than 100 μs
                Thread.Sleep(1);

                this.SendCommand(FUNCTION_SET | DATA_LENGTH_4BIT);
            }

            this.SendCommand((byte)(FUNCTION_SET | this.functionSet));

            // Display control
            this.blinkCursor = false;
            this.showCursor  = false;
            this.displayOn   = true;
            this.DisplayControl();
            // Display clear
            this.Clear();
            // Entry mode set
            this.EntryModeSet(DisplayShift.No, CursorDirection.Increment);
        }
Beispiel #4
0
        /// <summary>
        /// Execute display initialization
        /// </summary>
        /// <param name="characterFont">Character font</param>
        /// <param name="lines">Number of display lines</param>
        /// <param name="columns">Number of characters per lines (columns)</param>
        public void Initialize(CharacterFont characterFont, byte lines, byte columns)
        {
            // change default set (1 line) to 2 lines if requested
            if (lines > 1)
                this.functionSet |= DISPLAY_LINES_2LINE;

            this.lines = lines;
            this.columns = columns;

            // change default set (5 x 8 dots) to 5 x 10 dots if requested
            if (characterFont == CharacterFont.Dots5x10)
                this.functionSet |= CHAR_FONT_5x10DOTS;

            // Wait for more than 40 ms after VCC rises to 2.7 V
            // (Wait for more than 15 ms after VCC rises to 4.5 V)
            Thread.Sleep(50);

            // initialization (datasheet pag. 45 fig. 23)
            if (this.provider.InterfaceDataMode == InterfaceDataMode._8Bit)
            {
                this.SendCommand((byte)(FUNCTION_SET | this.functionSet));
                // Wait for more than 4.1 ms
                Thread.Sleep(5);

                this.SendCommand((byte)(FUNCTION_SET | this.functionSet));
                // Wait for more than 100 μs
                Thread.Sleep(1);

                this.SendCommand((byte)(FUNCTION_SET | this.functionSet));
            }
            // initialization (datasheet pag. 46 fig. 24)
            else
            {
                this.SendCommand(FUNCTION_SET | DATA_LENGTH_8BIT);
                // Wait for more than 4.1 ms
                Thread.Sleep(5);

                this.SendCommand(FUNCTION_SET | DATA_LENGTH_8BIT);
                // Wait for more than 4.1 ms
                Thread.Sleep(5);

                this.SendCommand(FUNCTION_SET | DATA_LENGTH_8BIT);
                // Wait for more than 100 μs
                Thread.Sleep(1);

                this.SendCommand(FUNCTION_SET | DATA_LENGTH_4BIT);
            }

            this.SendCommand((byte)(FUNCTION_SET | this.functionSet));

            // Display control
            this.blinkCursor = false;
            this.showCursor = false;
            this.displayOn = true;
            this.DisplayControl();
            // Display clear
            this.Clear();
            // Entry mode set
            this.EntryModeSet(DisplayShift.No, CursorDirection.Increment);
        }