Netduino home hardware projects downloads community

Jump to content


The Netduino forums have been replaced by new forums at community.wildernesslabs.co. This site has been preserved for archival purposes only and the ability to make new accounts or posts has been turned off.
Photo

Need KS0108 or similar display, GLCD

LCD Graphic

  • Please log in to reply
4 replies to this topic

#1 stotech

stotech

    Advanced Member

  • Members
  • PipPipPip
  • 143 posts
  • LocationAustralia

Posted 03 November 2013 - 12:04 PM

Check out these totally mad GLCD videos on You Tube by ab9pdonteh.

 

They were done in C# and managed code at that. Fair enough it is on a FEZ and not a Netduino but that's still pretty amazing. I've had one of these displays for a while now and been dying to get something simple on it. Just drawing lines, boxes, circles and a little text is all I really need.

 

I got in touch with him earlier today and he kindly agreed to share the coding under Apache2 for the benefit of the whole Netduino community. Hopefully, with a bit of help from all you guys we can port it across. I read that the .netmf is meant to be really good at this type of thing cause of some of the tools available in the windows phone libraries? I wouldn't know though cause I'm not up to there yet.

 

It would be dream come true if we could get this implemented and able to work with the .netmf toolbox. That way we could get the extra pins needed using Stefans famous bit shifting library.

 

What do you say? Who can help me out here? Or could even tell me where to start? :) No really?

 

Here is the type of display I'm talking about.

 

http://www.adafruit.com/products/188

 

The code is attached.

 

Attached File  G Reagan GLCD.zip   320.02KB   17 downloads



#2 stotech

stotech

    Advanced Member

  • Members
  • PipPipPip
  • 143 posts
  • LocationAustralia

Posted 04 November 2013 - 02:33 AM

Here is the part of the code that I think needs changing.

/*GLCD wiring 1 = Vdd +5v 2 = Vss GND 3 = V0 LCD contrast input 4-11 = DB0-DB712 = left chip13 = right chip14 = reset - to Vdd15 = R/W - to Vss16 = D/I - RS data instruction - H data - L cmd17 = E - enable - high clock18 = VEE - connect to 1kR -> V0/10kR -> Vdd19 = A - backlight Vdd20 = K - backlight to 100R -> Vss*/using System;using System.IO;using System.Threading;using Microsoft.SPOT;using Microsoft.SPOT.Hardware;using GHIElectronics.NETMF.FEZ;using GHIElectronics.NETMF.Hardware;using GHIElectronics.NETMF.System;namespace Graphics {    public enum Color {        Black = 255,        White = 0,        Grey = 127,        None = 128,    }    public enum FontType {        Size5x7 = 5,        Size6x8 = 6,    }    public class GraphicsDevice {        private enum Command {            YADDR = 0x40,            XADDR = 0xB8,            ZADDR = 0xC0,            DISPON = 0x3E,        }        #region Definition        OutputPort CS1;        OutputPort CS2;        OutputPort DI;        ParallelPort Data;        public int Width {            get { return width; }        }        protected int width = 128;        public int Height {            get { return height; }        }        protected int height = 64;        public byte[] frameBuffer;        byte[] font = null;        FontType fontType;        #endregion        #region Low level control and init        public GraphicsDevice(Cpu.Pin CS1, Cpu.Pin CS2, Cpu.Pin DI, Cpu.Pin Enable,            Cpu.Pin D0, Cpu.Pin D1, Cpu.Pin D2, Cpu.Pin D3, Cpu.Pin D4, Cpu.Pin D5, Cpu.Pin D6, Cpu.Pin D7) {            this.CS1 = new OutputPort(CS1, false);            this.CS2 = new OutputPort(CS2, false);            this.DI = new OutputPort(DI, false);            Cpu.Pin[] pins = { D0, D1, D2, D3, D4, D5, D6, D7 };            Data = new ParallelPort(pins, Enable, Cpu.Pin.GPIO_NONE);            Init();            frameBuffer = new byte[1024];            ClearBuffer(Color.White);        }        private void Init() {            Write((byte)Command.ZADDR, false, false);            Write((byte)Command.ZADDR, true, false);            Write((byte)Command.DISPON | 0x01, false, false);            Write((byte)Command.DISPON | 0x01, true, false);            Thread.Sleep(1000);        }        private void Write(byte dataval, bool chipval, bool dival) {            CS1.Write(!chipval);            CS2.Write(chipval);            DI.Write(dival);            SetData(dataval);        }        private byte[] buffer = new byte[1];        private void SetData(byte dataval) {            buffer[0] = dataval;            Data.Write(buffer, 0, 1);        }        public void ClearBuffer(Color color) {            if (color == Color.White) {                Array.Clear(frameBuffer, 0, 1024);            } else if(color == Color.Black) {                for (int i = 0; i < 1024; i++) {                    frameBuffer[i] = 255;                }            }        }        public void DrawBuffer() {            DrawLeft();            DrawRight();        }        private void DrawLeft() {            Write((byte)Command.YADDR, false, false);            for (int i = 0; i < 8; i++) {                int width_i = i * width;                Write((byte)((byte)Command.XADDR | i), false, false);                DI.Write(true);                CS1.Write(true);                CS2.Write(false);                Data.Write(frameBuffer, width_i, (width >> 1));            }        }        private void DrawRight() {            Write((byte)Command.YADDR, true, false);            for (int i = 0; i < 8; i++) {                int width_i = (i * width) + (width >> 1);                Write((byte)((byte)Command.XADDR | i), true, false);                DI.Write(true);                CS1.Write(false);                CS2.Write(true);                Data.Write(frameBuffer, width_i, (width >> 1));            }        }        public int SetPixel(int pos_x, int pos_y, Color color) {            if (pos_x >= width || pos_y >= height || pos_x < 0 || pos_y < 0) return -1;            int mod_y = (pos_y % 8);            int index = (pos_x + ((pos_y - mod_y) << 4));            if (color == Color.White) {                frameBuffer[index] = (byte)(frameBuffer[index] & ~(0x01 << mod_y));            } else {                frameBuffer[index] = (byte)(frameBuffer[index] | (0x01 << mod_y));            }            return 0;        }        private int GetBufferIndex(int posX, int posY) {            if (posX >= width || posY >= height || posX < 0 || posY < 0) return -1;            return (posX + ((posY - (posY % 8)) << 4));        }        #endregion        #region High level control        public void SetFont(byte[] font, FontType type) {            this.font = font;            this.fontType = type;        }        public void Print(int posX, int posY, string _string) {            if (font != null) {                int index = GetBufferIndex(posX, posY);                int offsetY = posY % 8;                for (int i = 0; i < _string.Length; i++) {                    if (_string[i] > 32 && _string[i] < 128) {                        int offset = ((_string[i] - 33) * 5);                        if (offsetY == 0) {                            Array.Copy(font, offset, frameBuffer, index, (int)fontType);                        } else {                            for (int j = 0; j < (int)fontType; j++) {                                byte val = font[offset + j];                                int indexOffset = index + j;                                if (indexOffset < 896) {                                    frameBuffer[indexOffset + 128] |= (byte)(val >> (8 - offsetY));                                }                                frameBuffer[indexOffset] |= (byte)(val << offsetY);                            }                        }                    }                    index += (int)fontType + 1;                }            }        }        public void SetFrameBufferLine(int offsetX, int line, byte[] buffer) {            int index = GetBufferIndex(0, (line << 3));            Array.Copy(buffer, offsetX, frameBuffer, index, (128 - offsetX));            Array.Copy(buffer, 0, frameBuffer, index + (128 - offsetX), offsetX);        }        #endregion    }}

Because the Netduino doesn't have a ParallelPort on line 53 I need to change it to the IParallelOut that is used by stefan's .net micro framework toolbox.

 

Probably something like the following but I can't quite work it out. I got the idea from here.

        IGPOPort[] MUX = new IGPOPort[8] {             Multi.LCDPins[0],             Multi.LCDPins[1],             Multi.LCDPins[2],             Multi.LCDPins[3],             Multi.LCDPins[4],             Multi.LCDPins[5],             Multi.LCDPins[6],             Multi.LCDPins[7],         };        IParallelOut ParallelPort = new IParallelOut(MUX.CreateParallelOut());

Hope this helps.



#3 TurBo

TurBo

    New Member

  • Members
  • Pip
  • 1 posts

Posted 18 January 2014 - 03:26 AM

Dear grant

 

any thanks for your great job!!



#4 stotech

stotech

    Advanced Member

  • Members
  • PipPipPip
  • 143 posts
  • LocationAustralia

Posted 04 October 2014 - 01:17 AM

Here are the finished display drivers for the KS0108.

 

Just use these 2 classes with stefan's .netmf toolbox and you've got a wicked cheap graphics display.

 

hope this helps someone.

Attached Files



#5 xmen

xmen

    Advanced Member

  • Members
  • PipPipPip
  • 72 posts

Posted 21 May 2015 - 09:28 AM

KS0108 require so many pins. Try ST7920 ?







Also tagged with one or more of these keywords: LCD, Graphic

0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users

home    hardware    projects    downloads    community    where to buy    contact Copyright © 2016 Wilderness Labs Inc.  |  Legal   |   CC BY-SA
This webpage is licensed under a Creative Commons Attribution-ShareAlike License.