In this episode we’ll show you a common display shield used in many different products. We’ll also show you how to modify it to work current 3.3 volt devices.
3 Likes
Nice.
Any reason why YouTube says the video is unlisted? Wouldn’t it make sense to make these as easy to find/share as possible?
1 Like
We don’t have the password to Gus’ account. When he gets back into the office then he will login and list it.
What? Is he having second lunch?
He’s learning bad habits from you, @ Gary.
Here is the example:
using System;
using Microsoft.SPOT;
using GHIElectronics.NETMF.FEZ;
namespace LCD_keypad
{
public class Program
{
public static void Main()
{
Debug.Print(Resources.GetString(Resources.StringResources.String1));
FEZ_Shields.KeypadLCD.Initialize();
FEZ_Shields.KeypadLCD.Print("FEZ is Great!");
System.Threading.Thread.Sleep(100);
FEZ_Shields.KeypadLCD.ShutBacklightOff();
System.Threading.Thread.Sleep(100);
FEZ_Shields.KeypadLCD.TurnBacklightOn();
//FEZ_Shields.KeypadLCD.SetCursor(0, 1);
//FEZ_Shields.KeypadLCD.Print("LCD Keypad Shield");
while (true)
{
switch (FEZ_Shields.KeypadLCD.GetKey())
{
case FEZ_Shields.KeypadLCD.Keys.Down:
FEZ_Shields.KeypadLCD.SetCursor(1, 0);
FEZ_Shields.KeypadLCD.Print("Down ");
break;
case FEZ_Shields.KeypadLCD.Keys.Up:
FEZ_Shields.KeypadLCD.SetCursor(1, 0);
FEZ_Shields.KeypadLCD.Print("Up ");
break;
case FEZ_Shields.KeypadLCD.Keys.Left:
FEZ_Shields.KeypadLCD.SetCursor(1, 0);
FEZ_Shields.KeypadLCD.Print("Left ");
break;
case FEZ_Shields.KeypadLCD.Keys.Right:
FEZ_Shields.KeypadLCD.SetCursor(1, 0);
FEZ_Shields.KeypadLCD.Print("Right ");
break;
case FEZ_Shields.KeypadLCD.Keys.Select:
FEZ_Shields.KeypadLCD.SetCursor(1, 0);
FEZ_Shields.KeypadLCD.Print("Sel ");
break;
}
System.Threading.Thread.Sleep(50);
}
}
}
}
and here is the driver
using System;
using System.Threading;
using Microsoft.SPOT;
using Microsoft.SPOT.Hardware;
//using GHIElectronics.NETMF.Hardware;
using GHI.Pins;
namespace GHIElectronics.NETMF.FEZ
{
public static partial class FEZ_Shields
{
static public class KeypadLCD
{
public enum Keys
{
Up,
Down,
Right,
Left,
Select,
None,
}
static OutputPort LCD_RS;
static OutputPort LCD_E;
static OutputPort LCD_D4;
static OutputPort LCD_D5;
static OutputPort LCD_D6;
static OutputPort LCD_D7;
static AnalogInput AnKey;
static OutputPort BackLight;
const byte DISP_ON = 0xC; //Turn visible LCD on
const byte CLR_DISP = 1; //Clear display
const byte CUR_HOME = 2; //Move cursor home and clear screen memory
const byte SET_CURSOR = 0x80; //SET_CURSOR + X : Sets cursor position to X
public static void Initialize()
{
LCD_RS = new OutputPort(FEZCobraIII.Gpio.D8, false);
LCD_E = new OutputPort(FEZCobraIII.Gpio.D9, false);
LCD_D4 = new OutputPort(FEZCobraIII.Gpio.D4, false);
LCD_D5 = new OutputPort(FEZCobraIII.Gpio.D5, false);
LCD_D6 = new OutputPort(FEZCobraIII.Gpio.D6, false);
LCD_D7 = new OutputPort(FEZCobraIII.Gpio.D7, false);
AnKey = new AnalogInput(FEZCobraIII.AnalogInput.D14);
BackLight = new OutputPort(FEZCobraIII.Gpio.D10, true);
LCD_RS.Write(false);
// 4 bit data communication
Thread.Sleep(50);
LCD_D7.Write(false);
LCD_D6.Write(false);
LCD_D5.Write(true);
LCD_D4.Write(true);
LCD_E.Write(true);
LCD_E.Write(false);
Thread.Sleep(50);
LCD_D7.Write(false);
LCD_D6.Write(false);
LCD_D5.Write(true);
LCD_D4.Write(true);
LCD_E.Write(true);
LCD_E.Write(false);
Thread.Sleep(50);
LCD_D7.Write(false);
LCD_D6.Write(false);
LCD_D5.Write(true);
LCD_D4.Write(true);
LCD_E.Write(true);
LCD_E.Write(false);
Thread.Sleep(50);
LCD_D7.Write(false);
LCD_D6.Write(false);
LCD_D5.Write(true);
LCD_D4.Write(false);
LCD_E.Write(true);
LCD_E.Write(false);
SendCmd(DISP_ON);
SendCmd(CLR_DISP);
}
//Sends an ASCII character to the LCD
static void Putc(byte c)
{
LCD_D7.Write((c & 0x80) != 0);
LCD_D6.Write((c & 0x40) != 0);
LCD_D5.Write((c & 0x20) != 0);
LCD_D4.Write((c & 0x10) != 0);
LCD_E.Write(true); LCD_E.Write(false); //Toggle the Enable Pin
LCD_D7.Write((c & 0x08) != 0);
LCD_D6.Write((c & 0x04) != 0);
LCD_D5.Write((c & 0x02) != 0);
LCD_D4.Write((c & 0x01) != 0);
LCD_E.Write(true); LCD_E.Write(false); //Toggle the Enable Pin
//Thread.Sleep(1);
}
//Sends an LCD command
static void SendCmd(byte c)
{
LCD_RS.Write(false); //set LCD to data mode
LCD_D7.Write((c & 0x80) != 0);
LCD_D6.Write((c & 0x40) != 0);
LCD_D5.Write((c & 0x20) != 0);
LCD_D4.Write((c & 0x10) != 0);
LCD_E.Write(true); LCD_E.Write(false); //Toggle the Enable Pin
LCD_D7.Write((c & 0x08) != 0);
LCD_D6.Write((c & 0x04) != 0);
LCD_D5.Write((c & 0x02) != 0);
LCD_D4.Write((c & 0x01) != 0);
LCD_E.Write(true); LCD_E.Write(false); //Toggle the Enable Pin
Thread.Sleep(1);
LCD_RS.Write(true); //set LCD to data mode
}
public static void Print(string str)
{
for (int i = 0; i < str.Length; i++)
Putc((byte)str[i]);
}
public static void Clear()
{
SendCmd(CLR_DISP);
}
public static void CursorHome()
{
SendCmd(CUR_HOME);
}
public static void SetCursor(byte row, byte col)
{
SendCmd((byte)(SET_CURSOR | row << 6 | col));
}
public static Keys GetKey()
{
double d = AnKey.Read();
int i = (int)(d * 1024);
// use this to read values to calibrate
/*while (true)
{
i = AnKey.Read();
Debug.Print(i.ToString());
Thread.Sleep(300);
}*/
const int ERROR = 15;
const int UP = 146;
const int DOWN = 330;
const int LEFT = 500;
const int SEL = 740;
if (i > 1024 - ERROR)
return Keys.None;
Debug.Print("An: " + i);
if (i < 0 + ERROR)
return Keys.Right;
if (i < UP + ERROR && i > UP - ERROR)
return Keys.Up;
if (i < DOWN + ERROR && i > DOWN - ERROR)
return Keys.Down;
if (i < LEFT + ERROR && i > LEFT - ERROR)
return Keys.Left;
if (i < SEL + ERROR && i > SEL - ERROR)
return Keys.Select;
return Keys.None;
}
public static void TurnBacklightOn()
{
BackLight.Write(true);
}
public static void ShutBacklightOff()
{
BackLight.Write(false);
}
}
}
}