hi.
Ive posted my last version of code in this posting. Anyone dare run it on their own arduino and a 2x16 text LCD?
I have no idea if its my dpy or uC that doesnt work. Absolutely nothing visual happens on my display
running the code.
regards
/*
testing av lcd display
*/
byte t60=60;
int pin4=4; // pinnumber of datapin LSB
int pin5=5;
int pin6=6;
int pin7=7;
int enable = 8;
int registerselect= 9;
int readwrite = 10; // or ground
int enablepulse();
int init4dpy();
void setup()
{
Serial.begin(9600);
pinMode(pin4, OUTPUT);
pinMode(pin5, OUTPUT);
pinMode(pin6, OUTPUT);
pinMode(pin7, OUTPUT);
pinMode(enable, OUTPUT);
pinMode(registerselect, OUTPUT);
pinMode(readwrite, OUTPUT);
digitalWrite(enable,LOW);
digitalWrite(registerselect,LOW);
digitalWrite(readwrite,LOW);
init4dpy();
digitalWrite(enable,HIGH);
}
void loop()
{
}
int enablepulse() //send a pulse to the enable output
{
digitalWrite(enable,LOW);
digitalWrite(enable,HIGH);
delayMicroseconds(1);
digitalWrite(enable,LOW);
}
int init4dpy()
{
// delayMicroseconds(150000); //await start process to finish
// write 3times to lcd with content ox03
digitalWrite(pin4,HIGH);
digitalWrite(pin5,HIGH);
digitalWrite(pin6,LOW);
digitalWrite(pin7,LOW);
enablepulse();
delayMicroseconds(5000);
digitalWrite(pin4,HIGH);
digitalWrite(pin5,HIGH);
digitalWrite(pin6,LOW);
digitalWrite(pin7,LOW);
enablepulse();
delayMicroseconds(150);
digitalWrite(pin4,HIGH);
digitalWrite(pin5,HIGH);
digitalWrite(pin6,LOW);
digitalWrite(pin7,LOW);
enablepulse();
delayMicroseconds(150);
//set 4 bit data mode
digitalWrite(pin4,LOW);
digitalWrite(pin5,HIGH);
digitalWrite(pin6,LOW);
digitalWrite(pin7,LOW);
enablepulse();
delayMicroseconds(150);
// 4 bit mode start from here and downwards
// function set: 4 bit bus mode, 2 line dpy, 5x8dots format
digitalWrite(pin4,LOW);
digitalWrite(pin5,HIGH);
digitalWrite(pin6,LOW);
digitalWrite(pin7,LOW);
enablepulse();
digitalWrite(pin4,LOW);
digitalWrite(pin5,LOW);
digitalWrite(pin6,LOW);
digitalWrite(pin7,HIGH);
enablepulse();
delayMicroseconds(t60);
// turn off dpy, cursor and blink (ddram still exists)
digitalWrite(pin4,LOW);
digitalWrite(pin5,LOW);
digitalWrite(pin6,LOW);
digitalWrite(pin7,LOW);
enablepulse();
digitalWrite(pin4,LOW);
digitalWrite(pin5,LOW);
digitalWrite(pin6,LOW);
digitalWrite(pin7,HIGH);
enablepulse();
delayMicroseconds(t60);
// clear dpy
digitalWrite(pin4,LOW);
digitalWrite(pin5,LOW);
digitalWrite(pin6,LOW);
digitalWrite(pin7,LOW);
enablepulse();
digitalWrite(pin4,HIGH);
digitalWrite(pin5,LOW);
digitalWrite(pin6,LOW);
digitalWrite(pin7,LOW);
enablepulse();
delayMicroseconds(4000);
// entry mode: cursor/blink moves to right and ddram adress is increased by 1 and shift right. I dont fully understand SH parameter yet.
digitalWrite(pin4,LOW);
digitalWrite(pin5,LOW);
digitalWrite(pin6,LOW);
digitalWrite(pin7,LOW);
enablepulse();
digitalWrite(pin4,LOW);
digitalWrite(pin5,HIGH);
digitalWrite(pin6,HIGH);
digitalWrite(pin7,LOW);
enablepulse();
delayMicroseconds(t60);
// end of initializing
// turn dpy, cursor on and blinking off
digitalWrite(pin4,LOW);
digitalWrite(pin5,LOW);
digitalWrite(pin6,LOW);
digitalWrite(pin7,LOW);
enablepulse();
digitalWrite(pin4,LOW);
digitalWrite(pin5,LOW);
digitalWrite(pin6,HIGH);
digitalWrite(pin7,HIGH);
enablepulse();
delayMicroseconds(t60);
delay(1000);
// write 'A' to dpy
digitalWrite(registerselect,HIGH);
delayMicroseconds(60);
digitalWrite(pin4,LOW);
digitalWrite(pin5,LOW);
digitalWrite(pin6,HIGH);
digitalWrite(pin7,LOW);
enablepulse();
digitalWrite(pin4,HIGH);
digitalWrite(pin5,LOW);
digitalWrite(pin6,LOW);
digitalWrite(pin7,LOW);
enablepulse();
delayMicroseconds(t60);
digitalWrite(registerselect,LOW);
}