Dec
27
Written by:
Rimon
12/27/2010 6:24 AM
I got the microcontroller Teensy++ http://www.pjrc.com/teensy/index.html and I have a stander 8X2 LCD, and I wrote the driver in C to write strings to my LCD, here I am writing my name :-)
/*
* LCD Write
* By: Rimon Tadros
*
*/
void setup() // run once, when the sketch starts
{
InitializePorts(); //makes the pins as output pins
SetDisplay();
ConfigDisplay();
ClearDisplay();
WriteString("Rimon");
SelectSecondLine();
WriteString("Tadros");
}
void InitializePorts()
{
for(int i = 0; i < 8 ; i++)
{
pinMode(PIN_D0+i, OUTPUT);
}
pinMode(PIN_E0, OUTPUT);
pinMode(PIN_C0, OUTPUT);
}
void SelectSecondLine()
{
SendData(B11000000, true);
}
void ConfigDisplay()
{
SendData(B00111100, true);
}
void SetDisplay()
{
SendData(B00001100, true);
}
void ClearDisplay()
{
SendData(B00000001, true);
}
void WriteString(char* x)
{
int index=0;
while(x[index] != '\0')
{
WriteChar(x[index]);
index++;
}
}
void WriteChar(char x)
{
SendData(x,false);
}
void SendData(char x, boolean command)
{
for(int i = 0; i < 8 ; i++)
{
if( (x>>i) & 0x01 == 0x01)
digitalWrite(i, HIGH);
else
digitalWrite(i, LOW);
}
if(command)
digitalWrite(PIN_E0, LOW);
else
digitalWrite(PIN_E0, HIGH);
digitalWrite(PIN_C0, HIGH);
delay(1);
digitalWrite(PIN_C0, LOW);
}
void loop() // run over and over again
{
//nothing to do here ;)
}