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.