@ Brett -
Success… after some “figgering” …
Hi… First i modified the standard HD44780 code (.cs) to use the configuration commands for the Fez-Mini.
( This meand taking out all reference to socket and using the NETMF.FEZ library in stead of the Gadgeteer library.
LCD_RS = new GT.Interfaces.DigitalOutput(socket, GT.Socket.Pin.Four, false, null);
became
LCD_RS = new OutputPort((Cpu.Pin)FEZ_Pin.Digital.Di4, false);
(The working code is attached at the end of this reply !)
I connected the HD44780 module (GHI) to an extentionboard wich fits snugly in my breadboard… NO GO
(i could only get the backlight to work)…
After checking all connections, i figured that , as i was using the extentionboard the wrong way (it probably didnt pass my signals to either of the 2 10pin connectors. It is probably protected by diodes…??
Well I opted for a direct approach before giving up totally…
So i connectede a 10pin-ribboncable to 10 headerpins that fit in the breadboard
wired up the pins (all exept the 3.3v pin(1)) to the pins on the Fez Mini.
rebooted the mini (didnt even have to connect to the PC, as the code was working after all)
and Voila!!!
see the results.
Now I am in for step 2 : getting some serial communication to display on the LCD…
regards
Bert
using System;
using System.Threading;
using Microsoft.SPOT;
using Microsoft.SPOT.Hardware;
using GHIElectronics.NETMF.FEZ;
namespace FezMiniWithLCD
{
public class Program
{
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 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
static void Main()
{
LCD_RS = new OutputPort((Cpu.Pin)FEZ_Pin.Digital.Di4, false);
LCD_E = new OutputPort((Cpu.Pin)FEZ_Pin.Digital.Di3, false);
LCD_D4 = new OutputPort((Cpu.Pin)FEZ_Pin.Digital.Di5, false);
LCD_D5 = new OutputPort((Cpu.Pin)FEZ_Pin.Digital.Di7, false);
LCD_D6 = new OutputPort((Cpu.Pin)FEZ_Pin.Digital.Di9, false);
LCD_D7 = new OutputPort((Cpu.Pin)FEZ_Pin.Digital.Di6, false);
BackLight = new OutputPort((Cpu.Pin)FEZ_Pin.Digital.Di8, false);
Initialize();
TurnBacklightOn();
Thread.Sleep(2000);
PrintString("Hello World");
}
static void Initialize()
{
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);
}
///<summary>
/// Sends an LCD command.
/// </summary>
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
}
/// <summary>
/// Prints the passed in string to the screen at the current cursor position. Note: This function will move the cursor position after.
/// </summary>
/// <param name="str">The string to print.</param>
static void PrintString(string str)
{
for (int i = 0; i < str.Length; i++)
Putc((byte)str[i]);
}
/// <summary>
/// Sends an ASCII character to the LCD at the current cursor position. Note: This function will move the cursor position after.
/// </summary>
/// <param name="c">The character to display.</param>
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);
}
/// <summary>
/// Clears the screen.
/// </summary>
static void Clear()
{
SendCmd(CLR_DISP);
}
/// <summary>
/// Places the cursor at the top left of the screen.
/// </summary>
static void CursorHome()
{
SendCmd(CUR_HOME);
}
/// <summary>
/// Set the cursor to the passed in position.
/// </summary>
/// <param name="row">Row of the desired cursor position.</param>
/// <param name="col">Column of the desired cursor position.</param>
static void SetCursor(byte row, byte col)
{
byte[] row_offsets = new byte[4] { 0x00, 0x40, 0x14, 0x54 };
SendCmd((byte)(SET_CURSOR | row_offsets[row] | col));
}
/// <summary>
/// Turns the backlight on.
/// </summary>
static void TurnBacklightOn()
{
BackLight.Write(true);
}
/// <summary>
/// Turns the backlight off.
/// </summary>
static void ShutBacklightOff()
{
BackLight.Write(false);
}
}
}