public void Initialize(VccType vcctype = VccType.SWITCHCAPVCC)
        {
            resetPin.Write(true);
            Thread.Sleep(1); // VDD (3.3V) goes high at start, lets just chill for a ms
            resetPin.Write(false); // bring reset low
            Thread.Sleep(10); // wait 10ms
            resetPin.Write(true); // bring out of reset

            dcPin.Write(DisplayCommand);

            SendCommand(Command.DISPLAYOFF);  // 0xAE
            SendCommand(Command.SETLOWCOLUMN | (Command)0x0);  // low col = 0
            SendCommand(Command.SETHIGHCOLUMN | (Command)0x0);  // hi col = 0
            SendCommand(Command.SETSTARTLINE | (Command)0x0); // line #0
            SendCommand(Command.SETCONTRAST);  // 0x81

            if (vcctype == VccType.EXTERNALVCC)
            {
                SendCommand((Command)0x9F);  // external 9V
            }
            else
            {
                SendCommand((Command)0xCF);  // chargepump
            }

            SendCommand((Command)0xA1);  // setment remap 95 to 0 (?)
            SendCommand(Command.NORMALDISPLAY); // 0xA6
            SendCommand(Command.DISPLAYALLON_RESUME); // 0xA4
            SendCommand(Command.SETMULTIPLEX); // 0xA8
            SendCommand((Command)0x3F);  // 0x3F 1/64 duty
            SendCommand(Command.SETDISPLAYOFFSET); // 0xD3
            SendCommand((Command)0x0); // no offset
            SendCommand(Command.SETDISPLAYCLOCKDIV);  // 0xD5
            SendCommand((Command)0x80);  // the suggested ratio 0x80
            SendCommand(Command.SETPRECHARGE); // 0xd9

            if (vcctype == VccType.EXTERNALVCC)
            {
                SendCommand((Command)0x22); // external 9V
            }
            else
            {
                SendCommand((Command)0xF1); // DC/DC
            }

            SendCommand(Command.SETCOMPINS); // 0xDA
            SendCommand((Command)0x12); // disable COM left/right remap

            SendCommand(Command.SETVCOMDETECT); // 0xDB
            SendCommand((Command)0x40); // 0x20 is default?

            SendCommand(Command.MEMORYMODE); // 0x20
            SendCommand((Command)0x00); // 0x0 act like ks0108

            // left to right scan
            SendCommand(Command.SEGREMAP | (Command)0x1);

            SendCommand(Command.COMSCANDEC);

            SendCommand(Command.CHARGEPUMP); //0x8D
            if (vcctype == VccType.EXTERNALVCC)
            {
                SendCommand((Command)0x10);  // disable
            }
            else
            {
                SendCommand((Command)0x14);  // disable    
            }

            SendCommand(Command.DISPLAYON);//--turn on oled panel

            // Switch to 'data' mode
            dcPin.Write(Data);
        }
        public void Initialize(VccType vcctype = VccType.SWITCHCAPVCC)
        {
            if (Spi != null)
            {
                resetPin.Write(true);

                Thread.Sleep(1);
                // VDD (3.3V) goes high at start, lets just chill for a ms

                resetPin.Write(false); // bring reset low

                Thread.Sleep(10);
                // wait 10ms

                resetPin.Write(true); // bring out of reset
                dcPin.Write(DisplayCommand);
                SendCommand(Command.DISPLAYOFF); // 0xAE
                SendCommand(Command.SETLOWCOLUMN | 0x0); // low col = 0
                SendCommand(Command.SETHIGHCOLUMN | 0x0); // hi col = 0
                SendCommand(Command.SETSTARTLINE | 0x0); // line #0
                SendCommand(Command.SETCONTRAST); // 0x81

                if (vcctype == VccType.EXTERNALVCC)
                {
                    SendCommand((Command) 0x9F); // external 9V
                }

                else
                {
                    SendCommand((Command) 0xCF); // chargepump
                }

                SendCommand((Command) 0xA1); // setment remap 95 to 0 (?)
                SendCommand(Command.NORMALDISPLAY); // 0xA6
                SendCommand(Command.DISPLAYALLON_RESUME); // 0xA4
                SendCommand(Command.SETMULTIPLEX); // 0xA8
                //SendCommand((Command)0x3F);  // 0x3F 1/64 duty
                SendCommand((Command) 0x1F); // 0x1F 1/32 duty
                SendCommand(Command.SETDISPLAYOFFSET); // 0xD3
                SendCommand(0x0); // no offset
                SendCommand(Command.SETDISPLAYCLOCKDIV); // 0xD5
                SendCommand((Command) 0x80); // the suggested ratio 0x80
                SendCommand(Command.SETPRECHARGE); // 0xd9

                if (vcctype == VccType.EXTERNALVCC)
                {
                    SendCommand((Command) 0x22); // external 9V
                }

                else
                {
                    SendCommand((Command) 0xF1); // DC/DC
                }

                SendCommand(Command.SETCOMPINS); // 0xDA
                //SendCommand((Command)0x12); // disable COM left/right remap
                SendCommand((Command) 0x02); ////128_32 = 02       128_64 = 12
                SendCommand(Command.SETVCOMDETECT); // 0xDB
                SendCommand((Command) 0x40); // 0x20 is default
                SendCommand(Command.MEMORYMODE); // 0x20
                SendCommand(0x00); // 0x0 act like ks0108

                // left to right scan
                SendCommand(Command.SEGREMAP | (Command) 0x1); //0xA0
                SendCommand(Command.COMSCANDEC);
                //0xC8
                SendCommand(Command.CHARGEPUMP); //0x8D

                if (vcctype == VccType.EXTERNALVCC)
                {
                    SendCommand((Command) 0x10); // disable
                }
                else
                {
                    SendCommand((Command) 0x14); // disable
                }

                SendCommand(Command.DISPLAYON); //--turn on oled panel
                // Switch to 'data' mode
                dcPin.Write(Data);
            }
            else
            {
                byte[] intBuffer;

                if (Height == 32)
                {
                    intBuffer = new byte[]
                    {
                        (byte) Command.DISPLAYOFF,

                        //turn off display(RESET=OFF)
                        0x00, 0x00,
                        //low column nibble(RESET=0),high column nibble(RESET=0)
                        0xB0,
                        //start page address(RESET=0)
                        (byte) Command.MEMORYMODE, 0x00,
                        //memory address mode(RESET=02 [page])
                        (byte) Command.SETDISPLAYCLOCKDIV, 0x80,
                        //oscillator frequency and divider(RESET=80)00
                        (byte) Command.SETMULTIPLEX, 0x1F,
                        //mux ratio(RESET=3F [64 lines]
                        (byte) Command.SETDISPLAYOFFSET, 0x00,
                        //display offset,COM vertical shift(RESET=0)
                        (byte) Command.CHARGEPUMP, (byte) (vcctype == VccType.EXTERNALVCC ? 0x10 : 0x14),
                        //enable charge pump(RESET=10 [OFF])
                        0xA1, 0x00,
                        //segment remap(RESET=SEG0, COL0) 00 mirror image
                        (byte) Command.COMSCANDEC,
                        //COM output scan(RESET=C0, C8 flips display)
                        (byte) Command.SETCOMPINS, 0x02,
                        //COM pins hardware config(RESET=12[alternate])
                        (byte) Command.SETCONTRAST, 0xCF,
                        //contrast CF(RESET=7F)
                        (byte) Command.SETPRECHARGE, (byte) (vcctype == VccType.EXTERNALVCC ? 0x22 : 0xF1),
                        //pre-charge period F1(RESET=22)
                        (byte) Command.SETVCOMDETECT, 0x30,
                        //Vcom deselect(RESET=20)
                        (byte) Command.DISPLAYALLON_RESUME,
                        //turn all on ignore RAM A5/RAM A4(RESET=A4)
                        (byte) Command.NORMALDISPLAY,
                        //normal display A6/inverted A7(RESET=A6)
                        (byte) Command.DISPLAYON
                    };

                    //turn on display
                }
                else if (Height == 64)
                {
                    intBuffer = new byte[]
                    {
                        (byte) Command.DISPLAYOFF,
                        //turn off display(RESET=OFF)
                        0x00, 0x00,
                        //low column nibble(RESET=0),high column nibble(RESET=0)
                        0xB0,
                        //start page address(RESET=0)
                        (byte) Command.MEMORYMODE, 0x00,
                        //memory address mode(RESET=02 [page])
                        (byte) Command.SETDISPLAYCLOCKDIV, 0x80,
                        //oscillator frequency and divider(RESET=80)00
                        (byte) Command.SETMULTIPLEX, 0x3F,
                        //mux ratio(RESET=3F [64 lines]
                        (byte) Command.SETDISPLAYOFFSET, 0x00,
                        //display offset,COM vertical shift(RESET=0)
                        (byte) Command.CHARGEPUMP, (byte) (vcctype == VccType.EXTERNALVCC ? 0x10 : 0x14),
                        //enable charge pump(RESET=10 [OFF])
                        0xA1, 0x00,
                        //segment remap(RESET=SEG0, COL0) 00 mirror image
                        (byte) Command.COMSCANDEC,
                        //COM output scan(RESET=C0, C8 flips display)
                        (byte) Command.SETCOMPINS, 0x12,
                        //COM pins hardware config(RESET=12[alternate])
                        (byte) Command.SETCONTRAST, 0xCF,
                        //contrast CF(RESET=7F)
                        (byte) Command.SETPRECHARGE, (byte) (vcctype == VccType.EXTERNALVCC ? 0x22 : 0xF1),
                        //pre-charge period F1(RESET=22)
                        (byte) Command.SETVCOMDETECT, 0x40,
                        //Vcom deselect(RESET=20)
                        (byte) Command.DISPLAYALLON_RESUME,
                        //turn all on ignore RAM A5/RAM A4(RESET=A4)
                        (byte) Command.NORMALDISPLAY,
                        //normal display A6/inverted A7(RESET=A6)
                        (byte) Command.DISPLAYON
                    };

                    //turn on display
                }

                I2CBus.GetInstance().Write(I2c, intBuffer, I2CTransactionTimeout);
            }
        }
Beispiel #3
0
        public void Initialize(VccType vcctype = VccType.SWITCHCAPVCC)
        {
            resetPin.Write(true);
            Thread.Sleep(1);       // VDD (3.3V) goes high at start, lets just chill for a ms
            resetPin.Write(false); // bring reset low
            Thread.Sleep(10);      // wait 10ms
            resetPin.Write(true);  // bring out of reset

            dcPin.Write(DisplayCommand);

            SendCommand(Command.DISPLAYOFF);                   // 0xAE
            SendCommand(Command.SETLOWCOLUMN | (Command)0x0);  // low col = 0
            SendCommand(Command.SETHIGHCOLUMN | (Command)0x0); // hi col = 0
            SendCommand(Command.SETSTARTLINE | (Command)0x0);  // line #0
            SendCommand(Command.SETCONTRAST);                  // 0x81

            if (vcctype == VccType.EXTERNALVCC)
            {
                SendCommand((Command)0x9F);  // external 9V
            }
            else
            {
                SendCommand((Command)0xCF);  // chargepump
            }

            SendCommand((Command)0xA1);               // setment remap 95 to 0 (?)
            SendCommand(Command.NORMALDISPLAY);       // 0xA6
            SendCommand(Command.DISPLAYALLON_RESUME); // 0xA4
            SendCommand(Command.SETMULTIPLEX);        // 0xA8
            SendCommand((Command)0x3F);               // 0x3F 1/64 duty
            SendCommand(Command.SETDISPLAYOFFSET);    // 0xD3
            SendCommand((Command)0x0);                // no offset
            SendCommand(Command.SETDISPLAYCLOCKDIV);  // 0xD5
            SendCommand((Command)0x80);               // the suggested ratio 0x80
            SendCommand(Command.SETPRECHARGE);        // 0xd9

            if (vcctype == VccType.EXTERNALVCC)
            {
                SendCommand((Command)0x22); // external 9V
            }
            else
            {
                SendCommand((Command)0xF1); // DC/DC
            }

            SendCommand(Command.SETCOMPINS);    // 0xDA
            SendCommand((Command)0x12);         // disable COM left/right remap

            SendCommand(Command.SETVCOMDETECT); // 0xDB
            SendCommand((Command)0x40);         // 0x20 is default?

            SendCommand(Command.MEMORYMODE);    // 0x20
            SendCommand((Command)0x00);         // 0x0 act like ks0108

            // left to right scan
            SendCommand(Command.SEGREMAP | (Command)0x1);

            SendCommand(Command.COMSCANDEC);

            SendCommand(Command.CHARGEPUMP); //0x8D
            if (vcctype == VccType.EXTERNALVCC)
            {
                SendCommand((Command)0x10);  // disable
            }
            else
            {
                SendCommand((Command)0x14);  // disable
            }

            SendCommand(Command.DISPLAYON);//--turn on oled panel

            // Switch to 'data' mode
            dcPin.Write(Data);
        }