Go Down

Topic: 4 bit bus mode for a LCD (Read 2334 times) previous topic - next topic

janeik

#15
Jan 15, 2012, 10:55 am Last Edit: Jan 15, 2012, 01:18 pm by janeik Reason: 1

Quote
Oh my, now the display doesnt react on anything. Tested it with lcd.lib following arduino, no response at all.

You probably just forgot to tell the LiquidCrystal library that you are using the RW pin.  Your best bet is to just connect it (LCD pin 5) to GND.

Your own initialization sequence is almost correct.  You messed up one bit in the 'Entry Mode Set' command.

Don

hi.

I tried what u suggested regarding rw withoout any response.

Im aware of the doc for  my display (link in op) regarding entry mode. That bit differ from what my dpy documentatin tells and the general description of lcd display. I tried both version regarding the state of the one bit.

Well, the display seemes not beeing able to receive commands. I think I might have written some to it that might have put it in a non listening mode or destroyed its internal function as there were
much altering of signals input to display until the code became somewhat usable.

Ill head into another dpy to check the above thoughts.

Edit: I have checked that the voltage supply and io from uC are correct according to digitalWrite instructions to display. Its either something buggy with my program or a soldering issue. (soldered all connections twice, no shortcircuits either). Could be static too. A new dpy will probably tell.

regards





floresta

Quote
Im aware of the doc for  my display (link in op) regarding entry mode. That bit differ from what my dpy documentatin tells and the general description of lcd display. I tried both version regarding the state of the one bit.

Your data sheet is wrong on page 6.  The correct version of the instruction code, with DB2 high is shown on page 5.

The controller determines which instruction you are intending to send it by looking for the most significant '1' bit.  You can clearly see the pattern, if you are looking for it, in the 'Instruction Table' on page 5.  Without having DB2 high for an 'Entry Mode Set' instruction the controller cannot distinguish between an 'Entry Mode Set' instruction with DB1 high and DB0 low and a 'Return Home' instruction.


Don

janeik


Quote
Im aware of the doc for  my display (link in op) regarding entry mode. That bit differ from what my dpy documentatin tells and the general description of lcd display. I tried both version regarding the state of the one bit.

Your data sheet is wrong on page 6.  The correct version of the instruction code, with DB2 high is shown on page 5.

The controller determines which instruction you are intending to send it by looking for the most significant '1' bit.  You can clearly see the pattern, if you are looking for it, in the 'Instruction Table' on page 5.  Without having DB2 high for an 'Entry Mode Set' instruction the controller cannot distinguish between an 'Entry Mode Set' instruction with DB1 high and DB0 low and a 'Return Home' instruction.


Don


Thank You very much for clearing up. Ill change the code.

regards jan

janeik

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

Code: [Select]
/*
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);
}

floresta

#19
Jan 15, 2012, 08:32 pm Last Edit: Jan 15, 2012, 09:43 pm by floresta Reason: 1
Quote
Anyone dare run it on their own arduino and a 2x16 text LCD?

I did.  It gives me a blank display.  

Without changing any wires I can run Hello World with LiquidCrystal lcd(10,9,8,4,5,6,7); and it functions properly.  I am running a Boarduino with Arduino v0022.

I will take a look at your code more closely now....


Don

Edit:  It's LiquidCrystal lcd(9,10,8,4,5,6,7);    -- sorry about that.

floresta

#20
Jan 15, 2012, 09:56 pm Last Edit: Jan 15, 2012, 09:58 pm by floresta Reason: 1
Well it seems that it does work when I get pins 9 and 10 oriented properly.  I don't know if this is good news or bad news.  

I suggest that you rip everything out and start over with the modified Hello World sketch and verify that your LCD is still alive.  If it is OK then try your version again.  Then, if that works, we can start to clean up and restructure your code.


Quote
Absolutely nothing visual happens on my display

I started my troubleshooting by making the cursor visible although I don't normally run the LCD that way.

Don

janeik

#21
Jan 15, 2012, 11:35 pm Last Edit: Jan 15, 2012, 11:43 pm by janeik Reason: 1

Well it seems that it does work when I get pins 9 and 10 oriented properly.  I don't know if this is good news or bad news.  

I suggest that you rip everything out and start over with the modified Hello World sketch and verify that your LCD is still alive.  If it is OK then try your version again.  Then, if that works, we can start to clean up and restructure your code.


Quote
Absolutely nothing visual happens on my display

I started my troubleshooting by making the cursor visible although I don't normally run the LCD that way.

Don



Hello there, thanks for Your time.
In your previous post I suppose You were talking about the hello world code working with Your arduino.

If my code works on Your equipment,as You say above,when You change orientation for 9 and 10 (Im not quite sure what You really mean by this), it must be error in my practical work/components.

I did take out all cables to uC and putting them back according to datasheet, with no improvement.

I'll try to get another dpy at school tomorrow and in addition check my solderings under a loupe.

Regarding the shineup of code, I want it simple stright forward for education purpose.

Personally Im thinking of shining it up regarding use of memory and shortening of instructions and possibly time.

( I plan to read in the two nibbles in one container and using bitfiddling to sort out bits from each nibble to respective
pinnumber. Reading the busybit in register seemes good in respect to get correct delaytimes and thereby saving time. But that have to wait until current problem is solved :-)

regards jan

regards





floresta

#22
Jan 16, 2012, 12:19 am Last Edit: Jan 16, 2012, 12:21 am by floresta Reason: 1
When I initially connected my LCD to run your software for some reason I thought that RW was driven from pin 9 and RS from pin 10, and naturally it didn't work.  I redid Hello World to match how I interpreted the connections and it worked.  When I went back to your sketch (with 9 and 10 still connected backwards) and made the cursor visible it showed up initially in position 00 and then it moved to row 2.  When I changed the data to print a 'C' it wound up two spaces over on row 2.  These addresses  are in the low 40's (in hex) just like the ASCII codes for the capital letters.  So now I knew that in trying to display 'A': (1) I wasn't getting RS high and, (2) I was actually sending a 'Set DDRAM Address' instruction.  It didn't take much more work to find the switched wires.

Let me know when you give up and I'll send you some (old) Arduino code that doesn't use any libraries.  I probably shouldn't post it here right now, your students may have heard of Google.  I think the PM system here is acting up but you can find an Email address for me at the link in Reply #10.


Don

janeik

#23
Jan 16, 2012, 12:57 pm Last Edit: Jan 16, 2012, 01:05 pm by janeik Reason: 1

When I initially connected my LCD to run your software for some reason I thought that RW was driven from pin 9 and RS from pin 10, and naturally it didn't work.  I redid Hello World to match how I interpreted the connections and it worked.  When I went back to your sketch (with 9 and 10 still connected backwards) and made the cursor visible it showed up initially in position 00 and then it moved to row 2.  When I changed the data to print a 'C' it wound up two spaces over on row 2.  These addresses  are in the low 40's (in hex) just like the ASCII codes for the capital letters.  So now I knew that in trying to display 'A': (1) I wasn't getting RS high and, (2) I was actually sending a 'Set DDRAM Address' instruction.  It didn't take much more work to find the switched wires.

Let me know when you give up and I'll send you some (old) Arduino code that doesn't use any libraries.  I probably shouldn't post it here right now, your students may have heard of Google.  I think the PM system here is acting up but you can find an Email address for me at the link in Reply #10.


Don


Hello Don.

Im very happy today cause I found the error and a nice A showed up on the leftmost part of the display at line 1, after correcting the error.

The cable between lcd DB7 and microcontroller was broken. The cable is one of those readymade which I bought in a store who sells Arduino components.

I suspect the wire might be broken as some pupils holds in the middle part of cable when removing cable from the lab.board.

Using a new cable, and the helloworld example application, both the hello worl at line1  and counter at line 2 showed up.

And so did the A letter using my program.

Now I can make functions that handle commands and textinformation for displays in general and the busy-check for LCD internal work.

I must say a big THANK YOU to all thats participating in my thread and especially to You.

The last version of my program is listed below

regards
Jan

Code: [Select]
/*
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);
}

floresta

Quote
Im very happy today cause I found the error and a nice A showed up on the leftmost part of the display at line 1, after correcting the error.

That's good news.  Now the very least you want to do is remove the display of the characters from your initialization routine and put that part in setup() or in it's own routine. 

Quote
Now I can make functions that handle commands and textinformation

Keep in mind that the routine to send a single text character and the routine to send a command are identical except for the level of the RS line.  The time delays required are the same as well, except for two of the commands.

Quote
and the busy-check for LCD internal work.

This is a bit more complicated than it first appears.  Don't even think about it until you are really comfortable with the simpler time-delay technique.  Keep in mind that you have to do two 'reads' from the LCD controller each time you want to check the busy flag.

Don

Go Up