LCD not showing anything.

Go To Last Post
61 posts / 0 new
Author
Message
#1
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I've checked all the wirings, everything looks fine, the LCD emits light, except that the LCD is not showing anything. I've made another thread about the voltage dropping problem, I got that fixed(although it wasn't the problem), now using a transformer giving 9v output, connected to a regulator giving output 5v, i'm using PORTB for main output(D0-D7), PORTC 0,1,2 are for RS,RW,E respectively.

 

I'm sure about the PORTB, but i'm not sure about the PORTC in my code.

 

i'm using that table.

 

Register Selector
RS R/W  
0 0 Sends a command to LCD
0 1 Read busy flag (DB7) and address counter (DB0 to DB6)
1 0 Sends information to LCD
1 1 Reads information from LCD

I've got code from this page, I've change the code a lot to fit my needs. i'm using atmega328p

#include <avr/io.h>
#include <util/delay.h>
//PORTC = 0,0,0,0,0, E, RW,RS
//PORTC = 7,6,5,4,3, 2, 1, 0

//Function for sending Commands to the command register of LCD
void lcdcmd(unsigned char value){
    PORTB=value;
    PORTC = 0x04;   // E = 1, RW = 0, RS = 0
    _delay_ms(50);
    PORTC = 0x00;   // what should be the value here ?
    _delay_ms(50);
}
//Function for sending data to the data register of LCD
void display(unsigned char value){
    PORTB=value;
    PORTC = 0x05;   // E = 1, RW = 0, RS = 1
    _delay_ms(500);
    PORTC = 0x00;   // what should be the value here ?
    _delay_ms(50);
}

//Function to initialize the registers and pins of LCD
void lcdinti(void){
    PORTB=0x00;
    PORTC=0x00;
    _delay_ms(150);display(0x30);_delay_ms(4500);display(0x30);_delay_ms(300);
    display(0x30);_delay_ms(650);lcdcmd(0x38);_delay_ms(50);lcdcmd(0x0F);
    _delay_ms(50);lcdcmd(0x01);_delay_ms(50);lcdcmd(0x06);_delay_ms(50);lcdcmd(0x80);
    _delay_ms(50);
}
//MAIN FUNCTION
void main(){
    int k = 0;
    char u[]={"FIRST LINE"};
    lcdinti();
    lcdcmd(0x01);
    lcdcmd(0x80);
    _delay_ms(50);
    while(u[k]!='\0'){
        display(u[k++]);
        _delay_ms(50);
    }
}

 

This topic has a solution.

Last Edited: Mon. Feb 29, 2016 - 04:34 AM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0
    PORTC = 0x00;   // what should be the value here ?

0x00 is OK. It just sets the pins on PORTC low, and this is what you want.

 

 

What have you done regarding contrast control?

As of January 15, 2018, Site fix-up work has begun! Now do your part and report any bugs or deficiencies here

No guarantees, but if we don't report problems they won't get much of  a chance to be fixed! Details/discussions at link given just above.

 

"Some questions have no answers."[C Baird] "There comes a point where the spoon-feeding has to stop and the independent thinking has to start." [C Lawson] "There are always ways to disagree, without being disagreeable."[E Weddington] "Words represent concepts. Use the wrong words, communicate the wrong concept." [J Morin] "Persistence only goes so far if you set yourself up for failure." [Kartman]

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

JohanEkdahl wrote:

    PORTC = 0x00;   // what should be the value here ?

0x00 is OK. It just sets the pins on PORTC low, and this is what you want.

 

 

What have you done regarding contrast control?

 

i've got 2 potentiometers, one for contrast control and another for the backlight, i can see the effect of the backlight if i do a change. But I don't see a change in the LCD when i try to change the contrast, i'm assuming that is because there are no characters yet.

 

Last Edited: Sun. Feb 28, 2016 - 12:03 AM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

There's probably some setup and hold time required for the control pins vs the E pin which your code will violate.
https://www.sparkfun.com/datasheets/LCD/HD44780.pdf

Yes you have. Parameter tas. 60ns min. This means rw and rs have to be stable at least 60ns before E goes high. So set rs and rw to the required levels then set E high. There's also hold times to obey as well.

Yet another who has decided to 'roll their own' and fall for the same pitfalls.how many million is the count up to?

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Kartman wrote:
There's probably some setup and hold time required for the control pins vs the E pin which your code will violate. https://www.sparkfun.com/datashe... Yes you have. Parameter tas. 60ns min. This means rw and rs have to be stable at least 60ns before E goes high. So set rs and rw to the required levels then set E high. There's also hold times to obey as well. Yet another who has decided to 'roll their own' and fall for the same pitfalls.how many million is the count up to?

 

in my code, every single change in the port is followed with a 50ms delay. should i add more ?

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

no, read the data sheet and use the delay specified!   In most cases 50mS will be to long, in others it will be too short!

 

 

 

 

(Possum Lodge oath) Quando omni flunkus, moritati.

"I thought growing old would take longer"

 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

ki0bk wrote:

no, read the data sheet and use the delay specified!   In most cases 50mS will be to long, in others it will be too short!

 

 

 

ok, i'm gonna go read a 60 pages sheet and come back in 2018, meet me in the future :P

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Ok, the easy way is go download a known good LCD driver and move on to the next part of your project!  q:-)

 

 

 

(Possum Lodge oath) Quando omni flunkus, moritati.

"I thought growing old would take longer"

 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 1

Those things aren't the easiest things to make work. Download somebody's example code and follow it closely in the init section where it's setting registers and delaying.

 

You're almost there when you get to the stage of all the characters are black boxes.

If you don't know my whole story, keep your mouth shut.

If you know my whole story, you're an accomplice. Keep your mouth shut. 

Last Edited: Sun. Feb 28, 2016 - 01:40 AM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

But I don't see a change in the LCD when i try to change the contrast, i'm assuming that is because there are no characters yet.

You don't need any characters present to set the contrast - you don't even need a microcontroller.  Get the backlight working first (pins 15 and 16).  Then connect the power and contrast (pins 1, 2 and 3).  Don't bother with anything else until you can see the effect of the contrast potentiometer.  You should have a blank screen at one end and some 'boxes' at the other.

 

Have you done a Google search for something like LCD Programming Examples?

 

Don

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

floresta1212 wrote:

But I don't see a change in the LCD when i try to change the contrast, i'm assuming that is because there are no characters yet.

You don't need any characters present to set the contrast - you don't even need a microcontroller.  Get the backlight working first (pins 15 and 16).  Then connect the power and contrast (pins 1, 2 and 3).  Don't bother with anything else until you can see the effect of the contrast potentiometer.  You should have a blank screen at one end and some 'boxes' at the other.

 

Have you done a Google search for something like LCD Programming Examples?

 

Don

The backlight is working fine. I'm gonna double check the wiring for the contrast again.

 

Did I do a google search ? google servers are gonna explode due to my overload searching about this.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Your photo seems to show that you have a resistor in series with the wiper of the contrast pot. If yes... why? It is not needed.

Ross McKenzie ValuSoft Melbourne Australia

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0
void lcdcmd(uint8_t value){
    PORTB = value;
    PORTC &= ~(1<<RW);
    PORTC &= ~(1<<RS);      //set the state of the control pins
    NOP();                  //ensure the setup time min 60ns. 1 clk @ 16MHz = 62.5ns
    PORTC |= (1<<E);        //set E high
    NOP();                  // E high time
    NOP();                  // E high time
    NOP();                  // E high time
    NOP();                  // E high time
    NOP();                  // E high time
    NOP();                  // E high time
    NOP();                  // E high time
    NOP();                  // E high time
    NOP();                  // E high time
    NOP();                  // E high time
    NOP();                  // E high time
    NOP();                  // E high time
    NOP();                  // E high time
    NOP();                  // E high time
    NOP();                  // E high time
    NOP();                  // E high time - I've assumed 16MHz, thus 16 nops
    PORTC &= ~(1<<E);       // E low
    _delay_ms(50);          //depends on the actual commnd!
}

The data sheet tells all! The hold times in the above code happen by default. You might want to understand how this is achieved.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Kartman wrote:

void lcdcmd(uint8_t value){
    PORTB = value;
    PORTC &= ~(1<<RW);
    PORTC &= ~(1<<RS);      //set the state of the control pins
    NOP();                  //ensure the setup time min 60ns. 1 clk @ 16MHz = 62.5ns
    PORTC |= (1<<E);        //set E high
    NOP();                  // E high time
    NOP();                  // E high time
    NOP();                  // E high time
    NOP();                  // E high time
    NOP();                  // E high time
    NOP();                  // E high time
    NOP();                  // E high time
    NOP();                  // E high time
    NOP();                  // E high time
    NOP();                  // E high time
    NOP();                  // E high time
    NOP();                  // E high time
    NOP();                  // E high time
    NOP();                  // E high time
    NOP();                  // E high time
    NOP();                  // E high time - I've assumed 16MHz, thus 16 nops
    PORTC &= ~(1<<E);       // E low
    _delay_ms(50);          //depends on the actual commnd!
}

The data sheet tells all! The hold times in the above code happen by default. You might want to understand how this is achieved.

I don't have RW,RS in my code, but i understand what you're saying.

 

also, these two images that i got from the sheet are the most useful ones so far, from the first image i deduce that 1ms delay would be enough.

 

 

this is useful for the initialization...

 

i'm gonna try again tomorrow, i gotta go sleep now, i'm dead tired.

 

thanks all for your helpful replies :)

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

valusoft wrote:

Your photo seems to show that you have a resistor in series with the wiper of the contrast pot. If yes... why? It is not needed.

yes, I just saw someone use it like that while testing it on a LED for protection, but I understand he only did that cuz it's a LED. 

 

I removed it and almost burned the potentiometer while doing so, wrong wiring can be catastrophic :D

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 1

Here is how to connect the LCD for 4 bit operation....note the Potentiometer for contrast:

 

Forget about the arduino being there.  AND connect the RW line as instructed below, not as you see it in the picture

 

 

I have attached a project I did for another freak that uses an LCD control from a very well know working library for the LCD.  I have it configured for PORTD - Assuming Mega328 running at 1MHZ

 

Pinouts from LCD to AVR - I am assuming you are using a mega328:

 

LCD DB4 = portd,0

 

LCD DB5 = portd,1

 

LCD DB6 = portd,2

 

LCD DB7 = portd,3

 

LCD RS = portd,4

 

LCD RW = portd,5

 

LCD E = portd,6

 

The functions to control the LCD are in the LCD.c file.  everyone here can help you from there.

 

Jim

 

EDIT:

I was correct, the project was done for a Mega324, not a 328.  I corrected that in this project:

 

Attachment(s): 

I would rather attempt something great and fail, than attempt nothing and succeed - Fortune Cookie

 

"The critical shortage here is not stuff, but time." - Johan Ekdahl

 

"Step N is required before you can do step N+1!" - ka7ehk

 

"If you want a career with a known path - become an undertaker. Dead people don't sue!" - Kartman

"Why is there a "Highway to Hell" and only a "Stairway to Heaven"? A prediction of the expected traffic load?"  - Lee "theusch"

 

Speak sweetly. It makes your words easier to digest when at a later date you have to eat them ;-)  - Source Unknown

Please Read: Code-of-Conduct

Atmel Studio6.2/AS7, DipTrace, Quartus, MPLAB, RSLogix user

Last Edited: Sun. Feb 28, 2016 - 01:29 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Jim,

 

That image does not render for me.

Ross McKenzie ValuSoft Melbourne Australia

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I think I did it for a tiny 2313 and forgot to change the avr to a mega 328 in the project.

As far as the zip not working for you Ross I seem to recall you and I had issues sending zips back and forth. I am on my tablet now and off to bed. If the OP cannot unzip it I will post the main in the morning. It's Peter fleury's library FWIW

Jim

I would rather attempt something great and fail, than attempt nothing and succeed - Fortune Cookie

 

"The critical shortage here is not stuff, but time." - Johan Ekdahl

 

"Step N is required before you can do step N+1!" - ka7ehk

 

"If you want a career with a known path - become an undertaker. Dead people don't sue!" - Kartman

"Why is there a "Highway to Hell" and only a "Stairway to Heaven"? A prediction of the expected traffic load?"  - Lee "theusch"

 

Speak sweetly. It makes your words easier to digest when at a later date you have to eat them ;-)  - Source Unknown

Please Read: Code-of-Conduct

Atmel Studio6.2/AS7, DipTrace, Quartus, MPLAB, RSLogix user

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

No it is not the zip file Jim. It is the embedded image at the start of your post. http://www.learningaboutelectron... does not render.

 

Ross McKenzie ValuSoft Melbourne Australia

Last Edited: Sun. Feb 28, 2016 - 06:49 AM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 1

ki0bk wrote:

...download a known good LCD driver...

Sadly these are few and far between. Bad LCD drivers on the other hand are very easy to find.

#1 Hardware Problem? https://www.avrfreaks.net/forum/...

#2 Hardware Problem? Read AVR042.

#3 All grounds are not created equal

#4 Have you proved your chip is running at xxMHz?

#5 "If you think you need floating point to solve the problem then you don't understand the problem. If you really do need floating point then you have a problem you do not understand."

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 1

In your photo it looks to me like the contrast potentiometer is wired up the wrong way.

 

The page you linked to in your original post definitively has got it wrong. The way it is wired up there, you will always have close to 0 Volts on the contrast pin.

 

It should be:

 

One end to ground.

Other end to supply voltage.

Middle tap to the contrast pin of the LCD display.

 

For a graphical representation of this, see Jims post above.

 

As has sbeen stated above, even with no microcontroller attached but only supply, ground and contrast you should be able to make the screen go completely blank with the pot at one endpoint and see at least one line of solid black boxes with the pot at the other endpoint. If that does not happen then the reasons might be

 

- Contrast pot wired up the wrong way

- Rare, but they do exist: You might have an LCD module requiring negative voltage on the contrast pin

 

Focus on wiring up the contrast correctly.

 

If you know the exact manufacturer and part number for the display then we might be able to determine if it needs negative contrast voltage. Again, these display modules are very rare so do not focus on going down this path.

 


 

The data sheet you're quoting do have very long timings for some things. E.g. the minimum E cycle time is stated as 1000 ns minimum. This might have been so a long time ago, but the number I consider standard these days is 500 ns. Doing things slower than necessary should not pose a problem per se, but I'm wondering where you got hold of that data sheet?

 


 

Regarding the web page code you've linked to, I find the all flush-left code, and also the several statements on one line in the init function, appalling. I would stay away from that page (although at a superficial inspection the init looks OK). (Having the contrast pot wiring wrong in three of four cases does not make it look better...)

As of January 15, 2018, Site fix-up work has begun! Now do your part and report any bugs or deficiencies here

No guarantees, but if we don't report problems they won't get much of  a chance to be fixed! Details/discussions at link given just above.

 

"Some questions have no answers."[C Baird] "There comes a point where the spoon-feeding has to stop and the independent thinking has to start." [C Lawson] "There are always ways to disagree, without being disagreeable."[E Weddington] "Words represent concepts. Use the wrong words, communicate the wrong concept." [J Morin] "Persistence only goes so far if you set yourself up for failure." [Kartman]

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

JohanEkdahl wrote:

...even with no microcontroller attached but only supply, ground and contrast you should be able to make the screen go completely blank with the pot at one endpoint and see at least one line of solid black boxes with the pot at the other endpoint. If that does not happen then the reasons might be

 

And for examples of that see this tutorial I wrote...

 

https://www.avrfreaks.net/forum/t...

#1 Hardware Problem? https://www.avrfreaks.net/forum/...

#2 Hardware Problem? Read AVR042.

#3 All grounds are not created equal

#4 Have you proved your chip is running at xxMHz?

#5 "If you think you need floating point to solve the problem then you don't understand the problem. If you really do need floating point then you have a problem you do not understand."

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

valusoft wrote:

No it is not the zip file Jim. It is the embedded image at the start of your post. http://www.learningaboutelectron... does not render.

 

 

My apologies Ross.  It was rather late and I mis-understood what you meant by "image" as I had just made an image of one of my hard drives, and did not realize you were referring to an actual IMAGE.  The picture shows up on all my devices, and Johan seems to be able to see it as he referenced it in his post.

 

MAybe your browser has a very discerning palate for imagery? wink

 

JIm

I would rather attempt something great and fail, than attempt nothing and succeed - Fortune Cookie

 

"The critical shortage here is not stuff, but time." - Johan Ekdahl

 

"Step N is required before you can do step N+1!" - ka7ehk

 

"If you want a career with a known path - become an undertaker. Dead people don't sue!" - Kartman

"Why is there a "Highway to Hell" and only a "Stairway to Heaven"? A prediction of the expected traffic load?"  - Lee "theusch"

 

Speak sweetly. It makes your words easier to digest when at a later date you have to eat them ;-)  - Source Unknown

Please Read: Code-of-Conduct

Atmel Studio6.2/AS7, DipTrace, Quartus, MPLAB, RSLogix user

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

jgmdesign wrote:
Johan seems to be able to see it

Acknowledged. (FireFox 44.0.2.)

As of January 15, 2018, Site fix-up work has begun! Now do your part and report any bugs or deficiencies here

No guarantees, but if we don't report problems they won't get much of  a chance to be fixed! Details/discussions at link given just above.

 

"Some questions have no answers."[C Baird] "There comes a point where the spoon-feeding has to stop and the independent thinking has to start." [C Lawson] "There are always ways to disagree, without being disagreeable."[E Weddington] "Words represent concepts. Use the wrong words, communicate the wrong concept." [J Morin] "Persistence only goes so far if you set yourself up for failure." [Kartman]

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I can see the first image in post #16 but not the copies in posts #19 and #23.  This is with Firefox (44.0.2), Chrome(48.0.2564.116), IE(11.103.10586.0), and Edge(25.10586.0.0).

 

Don

 

 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

floresta1212 wrote:
not the copies in posts #19 and #23

You are aware that those are screen-dumps of what Ross can not see? Do you see noting at all of the images, or do you see Jim's avatar (in he post proper) but not the image he posted?

As of January 15, 2018, Site fix-up work has begun! Now do your part and report any bugs or deficiencies here

No guarantees, but if we don't report problems they won't get much of  a chance to be fixed! Details/discussions at link given just above.

 

"Some questions have no answers."[C Baird] "There comes a point where the spoon-feeding has to stop and the independent thinking has to start." [C Lawson] "There are always ways to disagree, without being disagreeable."[E Weddington] "Words represent concepts. Use the wrong words, communicate the wrong concept." [J Morin] "Persistence only goes so far if you set yourself up for failure." [Kartman]

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Ok, regardless if the image is viewable or not, I did put text below with the connections from the LCD to the Mega328.

 

Let's see what the OP comes back with.

 

JIm

I would rather attempt something great and fail, than attempt nothing and succeed - Fortune Cookie

 

"The critical shortage here is not stuff, but time." - Johan Ekdahl

 

"Step N is required before you can do step N+1!" - ka7ehk

 

"If you want a career with a known path - become an undertaker. Dead people don't sue!" - Kartman

"Why is there a "Highway to Hell" and only a "Stairway to Heaven"? A prediction of the expected traffic load?"  - Lee "theusch"

 

Speak sweetly. It makes your words easier to digest when at a later date you have to eat them ;-)  - Source Unknown

Please Read: Code-of-Conduct

Atmel Studio6.2/AS7, DipTrace, Quartus, MPLAB, RSLogix user

Last Edited: Sun. Feb 28, 2016 - 06:56 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

jgmdesign wrote:

Here is how to connect the LCD for 4 bit operation....note the Potentiometer for contrast:

 

Forget about the arduino being there.  AND connect the RW line as instructed below, not as you see it in the picture

 

 

I have attached a project I did for another freak that uses an LCD control from a very well know working library for the LCD.  I have it configured for PORTD - Assuming Mega328 running at 1MHZ

 

Pinouts from LCD to AVR - I am assuming you are using a mega328:

 

LCD DB4 = portd,0

 

LCD DB5 = portd,1

 

LCD DB6 = portd,2

 

LCD DB7 = portd,3

 

LCD RS = portd,4

 

LCD RW = portd,5

 

LCD E = portd,6

 

The functions to control the LCD are in the LCD.c file.  everyone here can help you from there.

 

Jim

 

EDIT:

I was correct, the project was done for a Mega324, not a 328.  I corrected that in this project:

 

Sorry for the late response, I had an interview today. I wish all HR's just stop asking me to talk about myself and also the expected salary laugh

 

thanks for that code, I used it, but it still didn't work. the screen is just blank, and the contrast is not changing, i have 3 potentiometers, all 3 working with the backlight but not with the contrast.

off topic: dunno why when i keep playing with the potentiometers, i see smoke coming out of them,.. maybe cuz they're cheap ?  I figure out why.. 

 

The disappointing blank screen.

 

 

My setup for the wiring, i followed yours, jgm

 

 

 

The setup pic is in the attachment file.

 

Attachment(s): 

Last Edited: Sun. Feb 28, 2016 - 11:43 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Just for completeness and my own sanity.

 

Ross McKenzie ValuSoft Melbourne Australia

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Smoke?

 

I would say that you have a wiper attached to either the ground or the supply and when you wind the control you are creating a short circuit across your power supply.

 

Stop and measure correctly.

Ross McKenzie ValuSoft Melbourne Australia

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

fixed the potentiometer wrong wiring, now i've got the contrast, what confused me is that the wrong wiring worked fine with the backlight...

 

 

i've boxes, but i don't have the text output yet.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 1

You still have the contrast pot wired up wrong, it seems. Again:

 

One end to +, other end to GND. Sweeper to contrast pin.

 

If your pot is not very weird, then that would be left leg to +, right leg to GND.  Or the other way around. Does not matter much. The worst effect will be that contrast decrease when you turn the pot clockwise, and increase when you turn it counter-clockwise. If that bothers you, just switch the wires to the left and right leg on the pot.

 

Middle leg of pot goes to contrast pin. This is not negotiable.

 

This arrangement of the pot makes it form a voltage divider. It is varying voltage that is needed on the contrast pin -(not varying current). Think of your pot as two resistors in series with the contrast pin attached between them and + and  GND at the "outer ends", and since it's actually a potentiometer you can vary how the voltage divider actually "divides" the voltage. The net effect is that if you sweep the pot all the way to one end you will get + out on the middle pin, all the way to the other end you get GND to the middle pin. In any position in between you will get a voltage proportional to the position (what type of proportionality depends on the pot - it can be linear or logarithmic, but either will work for this application).

 

Until you get the contrast pot working it will be meaningless to fiddle with any code. Again: With only +, GND and contrast pin attached you should be able to get a blank screen and at least one line of black boxes by turning the potentiometer full CW and full CCW.

As of January 15, 2018, Site fix-up work has begun! Now do your part and report any bugs or deficiencies here

No guarantees, but if we don't report problems they won't get much of  a chance to be fixed! Details/discussions at link given just above.

 

"Some questions have no answers."[C Baird] "There comes a point where the spoon-feeding has to stop and the independent thinking has to start." [C Lawson] "There are always ways to disagree, without being disagreeable."[E Weddington] "Words represent concepts. Use the wrong words, communicate the wrong concept." [J Morin] "Persistence only goes so far if you set yourself up for failure." [Kartman]

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

JohanEkdahl wrote:

In your photo it looks to me like the contrast potentiometer is wired up the wrong way.

 

The page you linked to in your original post definitively has got it wrong. The way it is wired up there, you will always have close to 0 Volts on the contrast pin.

 

It should be:

 

One end to ground.

Other end to supply voltage.

Middle tap to the contrast pin of the LCD display.

 

For a graphical representation of this, see Jims post above.

 

As has sbeen stated above, even with no microcontroller attached but only supply, ground and contrast you should be able to make the screen go completely blank with the pot at one endpoint and see at least one line of solid black boxes with the pot at the other endpoint. If that does not happen then the reasons might be

 

- Contrast pot wired up the wrong way

- Rare, but they do exist: You might have an LCD module requiring negative voltage on the contrast pin

 

Focus on wiring up the contrast correctly.

 

If you know the exact manufacturer and part number for the display then we might be able to determine if it needs negative contrast voltage. Again, these display modules are very rare so do not focus on going down this path.

 


 

The data sheet you're quoting do have very long timings for some things. E.g. the minimum E cycle time is stated as 1000 ns minimum. This might have been so a long time ago, but the number I consider standard these days is 500 ns. Doing things slower than necessary should not pose a problem per se, but I'm wondering where you got hold of that data sheet?

 


 

Regarding the web page code you've linked to, I find the all flush-left code, and also the several statements on one line in the init function, appalling. I would stay away from that page (although at a superficial inspection the init looks OK). (Having the contrast pot wiring wrong in three of four cases does not make it look better...)

 

checked the wiring again and it worked.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Judging by your photos,  you are using male-male jumper cables.    You do not appear to have soldered header strip on to the LCD.

 

Unless you provide good connections,   you will never get reliable LCD display.

This means soldered joints or properly crimped wires mating with proper header strip.

 

And get your potentiometer wired correctly.    Mind you,  just connecting pin#3 of the LCD to GND should give you an acceptable contrast without any pot.    (if you are using a 5V supply)

 

David.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Writz Matz wrote:
checked the wiring again and it worked.

WOuld you please be so kind as to explain what "worked"?

 

Did you connect the LCD with ONE pot as my diagram showed?  FOrget about a pot on teh backlight.  Just connect it the way it is in the picture.

 

 

 

JIm

I would rather attempt something great and fail, than attempt nothing and succeed - Fortune Cookie

 

"The critical shortage here is not stuff, but time." - Johan Ekdahl

 

"Step N is required before you can do step N+1!" - ka7ehk

 

"If you want a career with a known path - become an undertaker. Dead people don't sue!" - Kartman

"Why is there a "Highway to Hell" and only a "Stairway to Heaven"? A prediction of the expected traffic load?"  - Lee "theusch"

 

Speak sweetly. It makes your words easier to digest when at a later date you have to eat them ;-)  - Source Unknown

Please Read: Code-of-Conduct

Atmel Studio6.2/AS7, DipTrace, Quartus, MPLAB, RSLogix user

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

david.prentice wrote:

Judging by your photos,  you are using male-male jumper cables.    You do not appear to have soldered header strip on to the LCD.

 

Unless you provide good connections,   you will never get reliable LCD display.

This means soldered joints or properly crimped wires mating with proper header strip.

 

And get your potentiometer wired correctly.    Mind you,  just connecting pin#3 of the LCD to GND should give you an acceptable contrast without any pot.    (if you are using a 5V supply)

 

David.

 

I had the same feely feel, I guess i'm gonna have to go to the next level and buy a solder.

 

Thanks for that useful tip, I tried it :)

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

So what "WORKED"  Your display?

 

Writz Matz wrote:
I had an interview today. I wish all HR's just stop asking me to talk about myself and also the expected salary

What kind of job were you interviewing for?

 

JIm

I would rather attempt something great and fail, than attempt nothing and succeed - Fortune Cookie

 

"The critical shortage here is not stuff, but time." - Johan Ekdahl

 

"Step N is required before you can do step N+1!" - ka7ehk

 

"If you want a career with a known path - become an undertaker. Dead people don't sue!" - Kartman

"Why is there a "Highway to Hell" and only a "Stairway to Heaven"? A prediction of the expected traffic load?"  - Lee "theusch"

 

Speak sweetly. It makes your words easier to digest when at a later date you have to eat them ;-)  - Source Unknown

Please Read: Code-of-Conduct

Atmel Studio6.2/AS7, DipTrace, Quartus, MPLAB, RSLogix user

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

jgmdesign wrote:

Writz Matz wrote:
checked the wiring again and it worked.

WOuld you please be so kind as to explain what "worked"?

 

Did you connect the LCD with ONE pot as my diagram showed?  FOrget about a pot on teh backlight.  Just connect it the way it is in the picture.

 

 

 

JIm

 

well, I assumed that when i see boxes that the contrast thing is working. I should be more specific, sry.

 

I did it exactly like you said, both the backlight and the contrast are working.

 

 

 

I followed this 

 

LCD DB4 = portd,0

 

LCD DB5 = portd,1

 

LCD DB6 = portd,2

 

LCD DB7 = portd,3

 

LCD RS = portd,4

 

LCD RW = portd,5

 

LCD E = portd,6

 

but ok, i'll follow the picture now. <=== brain fart sry, the pic is obviously for arduino :P , although I see in the pic that the RW is going for GND, should I do that ? since we're gonna write on only anyway.

Last Edited: Mon. Feb 29, 2016 - 12:08 AM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

No follow what I posted and you have highlighted:

 

LCD DB4 = portd,0

 

LCD DB5 = portd,1

 

LCD DB6 = portd,2

 

LCD DB7 = portd,3

 

LCD RS = portd,4

 

LCD RW = portd,5

 

LCD E = portd,6

 

 

YOu are using a Mega328 correct?

 

JIm

I would rather attempt something great and fail, than attempt nothing and succeed - Fortune Cookie

 

"The critical shortage here is not stuff, but time." - Johan Ekdahl

 

"Step N is required before you can do step N+1!" - ka7ehk

 

"If you want a career with a known path - become an undertaker. Dead people don't sue!" - Kartman

"Why is there a "Highway to Hell" and only a "Stairway to Heaven"? A prediction of the expected traffic load?"  - Lee "theusch"

 

Speak sweetly. It makes your words easier to digest when at a later date you have to eat them ;-)  - Source Unknown

Please Read: Code-of-Conduct

Atmel Studio6.2/AS7, DipTrace, Quartus, MPLAB, RSLogix user

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

jgmdesign wrote:
YOu are using a Mega328 correct?
 

yes, ATmega328p.

 

jgmdesign wrote:

So what "WORKED"  Your display?

 

Writz Matz wrote:
I had an interview today. I wish all HR's just stop asking me to talk about myself and also the expected salary

What kind of job were you interviewing for?

 

JIm

 

It's a software engineer in Vodafone. *fingers crossed* 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Side comment: All your photos are showing the LCD upside down. Connector is at the top, not the bottom. The latest photo - showing black boxes - is progress. That is a row of boxes on line 1.

 

Now: For every try with software, vary the contrast to try to spot character output.

As of January 15, 2018, Site fix-up work has begun! Now do your part and report any bugs or deficiencies here

No guarantees, but if we don't report problems they won't get much of  a chance to be fixed! Details/discussions at link given just above.

 

"Some questions have no answers."[C Baird] "There comes a point where the spoon-feeding has to stop and the independent thinking has to start." [C Lawson] "There are always ways to disagree, without being disagreeable."[E Weddington] "Words represent concepts. Use the wrong words, communicate the wrong concept." [J Morin] "Persistence only goes so far if you set yourself up for failure." [Kartman]

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

THe code I provided prints on both lines.  So if you do not see anything on the first line you certainly will on the second.

 

JIm

I would rather attempt something great and fail, than attempt nothing and succeed - Fortune Cookie

 

"The critical shortage here is not stuff, but time." - Johan Ekdahl

 

"Step N is required before you can do step N+1!" - ka7ehk

 

"If you want a career with a known path - become an undertaker. Dead people don't sue!" - Kartman

"Why is there a "Highway to Hell" and only a "Stairway to Heaven"? A prediction of the expected traffic load?"  - Lee "theusch"

 

Speak sweetly. It makes your words easier to digest when at a later date you have to eat them ;-)  - Source Unknown

Please Read: Code-of-Conduct

Atmel Studio6.2/AS7, DipTrace, Quartus, MPLAB, RSLogix user

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Groundhog day again. Dodgy connections, dodgy code and dodgy process. Less than 10 minutes with an Arduino to validate the hardware with known code.

If you're trying to control backlight brightness with a pot, you're going to get smoke. The backlight draws around 100mA, the pot won't appreciate this unless it is a 2W wirewound.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Kartman wrote:
Less than 10 minutes with an Arduino to validate the hardware with known code.

Agreed, but apparently where the OP is located it's not easy, or inexpensive to get anything like that there.

 

JIm

I would rather attempt something great and fail, than attempt nothing and succeed - Fortune Cookie

 

"The critical shortage here is not stuff, but time." - Johan Ekdahl

 

"Step N is required before you can do step N+1!" - ka7ehk

 

"If you want a career with a known path - become an undertaker. Dead people don't sue!" - Kartman

"Why is there a "Highway to Hell" and only a "Stairway to Heaven"? A prediction of the expected traffic load?"  - Lee "theusch"

 

Speak sweetly. It makes your words easier to digest when at a later date you have to eat them ;-)  - Source Unknown

Please Read: Code-of-Conduct

Atmel Studio6.2/AS7, DipTrace, Quartus, MPLAB, RSLogix user

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

jgmdesign wrote:

Kartman wrote:
Less than 10 minutes with an Arduino to validate the hardware with known code.

Agreed, but apparently where the OP is located it's not easy, or inexpensive to get anything like that there.

 

JIm

 

They sell arduinos here, but costing around 200 EGP(about 18 sterling pounds), I am considering it as a last option though.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Unless you solder the pins to your LCD it will be very difficult for this operation to work reliably. 

NOw, have you made the connections? 

Have you established communications with the AVR?

 

If you have, then have you loaded up the project, run BUILD(F7), then programmed it into your AVR?  The project was done to work with a '328 right out of the box, that is, with the DIV8 fuse programmed for a 1MHZ clock from internal oscillator.

 

JIm

I would rather attempt something great and fail, than attempt nothing and succeed - Fortune Cookie

 

"The critical shortage here is not stuff, but time." - Johan Ekdahl

 

"Step N is required before you can do step N+1!" - ka7ehk

 

"If you want a career with a known path - become an undertaker. Dead people don't sue!" - Kartman

"Why is there a "Highway to Hell" and only a "Stairway to Heaven"? A prediction of the expected traffic load?"  - Lee "theusch"

 

Speak sweetly. It makes your words easier to digest when at a later date you have to eat them ;-)  - Source Unknown

Please Read: Code-of-Conduct

Atmel Studio6.2/AS7, DipTrace, Quartus, MPLAB, RSLogix user

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

jgmdesign wrote:

Unless you solder the pins to your LCD it will be very difficult for this operation to work reliably. 

NOw, have you made the connections? 

Have you established communications with the AVR?

 

If you have, then have you loaded up the project, run BUILD(F7), then programmed it into your AVR?  The project was done to work with a '328 right out of the box, that is, with the DIV8 fuse programmed for a 1MHZ clock from internal oscillator.

 

JIm

 

1MHZ clock ? I don't understand, in the datasheet, it says 128kHz

http://www.atmel.com/images/atme...

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Unless you played with the fuses the mega328 runs on a 8mhz RC internal oscillator that is divided by 8 to give a 1mhz internal clock.

 

Did you play with any of the fuses?

 

JIm

I would rather attempt something great and fail, than attempt nothing and succeed - Fortune Cookie

 

"The critical shortage here is not stuff, but time." - Johan Ekdahl

 

"Step N is required before you can do step N+1!" - ka7ehk

 

"If you want a career with a known path - become an undertaker. Dead people don't sue!" - Kartman

"Why is there a "Highway to Hell" and only a "Stairway to Heaven"? A prediction of the expected traffic load?"  - Lee "theusch"

 

Speak sweetly. It makes your words easier to digest when at a later date you have to eat them ;-)  - Source Unknown

Please Read: Code-of-Conduct

Atmel Studio6.2/AS7, DipTrace, Quartus, MPLAB, RSLogix user

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Is there a reason that you want to run so slow? I don't think I have ever seen anyone running at 128KHz...

Ross McKenzie ValuSoft Melbourne Australia

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

jgmdesign wrote:
Did you play with any of the fuses?

nope, i didn't

 

jgmdesign wrote:

Unless you solder the pins to your LCD it will be very difficult for this operation to work reliably. 

NOw, have you made the connections?

Have you established communications with the AVR?

 

 

If you have, then have you loaded up the project, run BUILD(F7), then programmed it into your AVR?  The project was done to work with a '328 right out of the box, that is, with the DIV8 fuse programmed for a 1MHZ clock from internal oscillator.

 

JIm

 

I've done all that,

 

 

now, it's time for me to go get a soldering iron and wire, any recommendations ?

 

valusoft wrote:

Is there a reason that you want to run so slow? I don't think I have ever seen anyone running at 128KHz...

 

I don't want to use the 128kHz oscillator, it's just that it confused me seeing it there when Jim said that the at328 is using 1MHz clock.

Last Edited: Mon. Feb 29, 2016 - 01:38 AM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Then you should be good to go.  If you hold the lines against the holes you might see something show up in the screen within a couple of seconds.

 

In case you have not looked at teh main file, the code inits the screen, then prints something on the first and second lines and waits 2.5 seconds.  It then blanks the screen for 2.5 seconds and then repeats the init and screen print. etc.  The reason I keep doing the init is so should you have problems with your connections(which you do) once they are all solid the screen will fire up on it's own without having to reset the AVR.

 

JIm

I would rather attempt something great and fail, than attempt nothing and succeed - Fortune Cookie

 

"The critical shortage here is not stuff, but time." - Johan Ekdahl

 

"Step N is required before you can do step N+1!" - ka7ehk

 

"If you want a career with a known path - become an undertaker. Dead people don't sue!" - Kartman

"Why is there a "Highway to Hell" and only a "Stairway to Heaven"? A prediction of the expected traffic load?"  - Lee "theusch"

 

Speak sweetly. It makes your words easier to digest when at a later date you have to eat them ;-)  - Source Unknown

Please Read: Code-of-Conduct

Atmel Studio6.2/AS7, DipTrace, Quartus, MPLAB, RSLogix user

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Did you disable JTAG on Port C?
Not sure if it would be an issue on your MCU but it would be on an ATmega644.
It's enabled by default, you have to turn it off if using Port C for the LCD.

 

 

 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

We are not using PORTC, we are using PORTD, and the Mega328 does not have a JTAG, but good advice. laugh

 

Jim

I would rather attempt something great and fail, than attempt nothing and succeed - Fortune Cookie

 

"The critical shortage here is not stuff, but time." - Johan Ekdahl

 

"Step N is required before you can do step N+1!" - ka7ehk

 

"If you want a career with a known path - become an undertaker. Dead people don't sue!" - Kartman

"Why is there a "Highway to Hell" and only a "Stairway to Heaven"? A prediction of the expected traffic load?"  - Lee "theusch"

 

Speak sweetly. It makes your words easier to digest when at a later date you have to eat them ;-)  - Source Unknown

Please Read: Code-of-Conduct

Atmel Studio6.2/AS7, DipTrace, Quartus, MPLAB, RSLogix user

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

jgmdesign wrote:

Then you should be good to go.  If you hold the lines against the holes you might see something show up in the screen within a couple of seconds.

 

In case you have not looked at teh main file, the code inits the screen, then prints something on the first and second lines and waits 2.5 seconds.  It then blanks the screen for 2.5 seconds and then repeats the init and screen print. etc.  The reason I keep doing the init is so should you have problems with your connections(which you do) once they are all solid the screen will fire up on it's own without having to reset the AVR.

 

JIm

 

I read the main many times,I understood it very well, but the there is no while loop to do the repeat.

 

int main(void)
{	
	
	//Initialise LCD screen and clear it
	lcd_init(LCD_DISP_ON);
	lcd_clrscr();
	
	//put something on the screen
	lcd_puts("Writz Matz");
	lcd_gotoxy(2,1);
	lcd_puts("AVR Freaks!!");
	//just wait a couple of seconds, clear screen, and wait again
	_delay_ms(2500);
	lcd_clrscr();
	_delay_ms(500);
	
   
}

 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

You do not need one as the main only does one thing, and there are no interrupts.  So when the last line executes, it rolls over to the top of the MAIN.

 

YOu certainly could put a WHILE(1) loop in it if you want.

 

Jim

I would rather attempt something great and fail, than attempt nothing and succeed - Fortune Cookie

 

"The critical shortage here is not stuff, but time." - Johan Ekdahl

 

"Step N is required before you can do step N+1!" - ka7ehk

 

"If you want a career with a known path - become an undertaker. Dead people don't sue!" - Kartman

"Why is there a "Highway to Hell" and only a "Stairway to Heaven"? A prediction of the expected traffic load?"  - Lee "theusch"

 

Speak sweetly. It makes your words easier to digest when at a later date you have to eat them ;-)  - Source Unknown

Please Read: Code-of-Conduct

Atmel Studio6.2/AS7, DipTrace, Quartus, MPLAB, RSLogix user

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

The OP is using a mega328 - thus he can build a known good Arduino sketch for the lcd and burn it onto his chip. Besides, who would by a 'real' Arduino - these cost around $50 in my part of town when you can get clones for significantly less.

This reply has been marked as the solution. 
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 1

Kartman wrote:
he can build a known good Arduino sketch for the lcd and burn it onto his chip.

 

Russell has a point, and something told me to look at the project I sent....I found a bug.

 

In the LCD.h file I skipped a pin on the port.  Thus all the control pins were off by one.  You would never get anything on the screen... My apologies for my mistake. blush

 

The port/lcd pin assignment I posted is correct.  I corrected my error in the .h file and as such here is what you get:

 

I also included the while() loop as well.

 

A very long day and 1am in the morning is no excuse for missing that obvious blunder.

 

Please accept my apologies on this and understand it was not intentional.

 

I have attached the corrected project to this post.

 

Jim

Attachment(s): 

I would rather attempt something great and fail, than attempt nothing and succeed - Fortune Cookie

 

"The critical shortage here is not stuff, but time." - Johan Ekdahl

 

"Step N is required before you can do step N+1!" - ka7ehk

 

"If you want a career with a known path - become an undertaker. Dead people don't sue!" - Kartman

"Why is there a "Highway to Hell" and only a "Stairway to Heaven"? A prediction of the expected traffic load?"  - Lee "theusch"

 

Speak sweetly. It makes your words easier to digest when at a later date you have to eat them ;-)  - Source Unknown

Please Read: Code-of-Conduct

Atmel Studio6.2/AS7, DipTrace, Quartus, MPLAB, RSLogix user

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Try the attached code for HD44780 / Compatible 16x2, 20x2 and 20x4 LCDs. It is easier to use. Proteus 8.3 SP2 format simulation file included.

 

/*******************************************************
This program was created by the CodeWizardAVR V3.25 
Automatic Program Generator
© Copyright 1998-2016 Pavel Haiduc, HP InfoTech s.r.l.
http://www.hpinfotech.com
Project : HD44780 LCD Library
Version : 1.0
Date    : 2/28/2016
Author  : Jayanth D
Company : microElectronica
Comments: HD44780 / Compatible LCD Library
Chip type               : ATmega32
Program type            : Application
AVR Core Clock frequency: 4.000000 MHz
Memory model            : Small
External RAM size       : 0
Data Stack size         : 512
*******************************************************/
#include <io.h>
#include <delay.h>

// Declare your global variables here
#define _LCD_FIRST_ROW          0x80     //Move cursor to the 1st row
#define _LCD_SECOND_ROW         0xC0     //Move cursor to the 2nd row
#define _LCD_THIRD_ROW          0x94     //Move cursor to the 3rd row
#define _LCD_FOURTH_ROW         0xD4     //Move cursor to the 4th row
#define _LCD_CLEAR              0x01     //Clear display
#define _LCD_RETURN_HOME        0x02     //Return cursor to home position, returns a 
                                         //shifted display to its original position.
                                         //Display data RAM is unaffected.
#define _LCD_CURSOR_OFF         0x0C     //Turn off cursor
#define _LCD_UNDERLINE_ON       0x0E     //Underline cursor on
#define _LCD_BLINK_CURSOR_ON    0x0F     //Blink cursor on
#define _LCD_MOVE_CURSOR_LEFT   0x10     //Move cursor left without changing 
                                         //display data RAM
#define _LCD_MOVE_CURSOR_RIGHT  0x14     //Move cursor right without changing 
                                         //display data RAM
#define _LCD_TURN_ON            0x0C     //Turn Lcd display on
#define _LCD_TURN_OFF           0x08     //Turn Lcd display off
#define _LCD_SHIFT_LEFT         0x18     //Shift display left without changing 
                                         //display data RAM
#define _LCD_SHIFT_RIGHT        0x1E     //Shift display right without changing 
                                         //display data RAM
#define EN_DELAY 100
#define LCD_STROBE {LCD_EN = 1; delay_us(EN_DELAY); LCD_EN = 0; delay_us(EN_DELAY);};

#define LCD_RS PORTD.0
#define LCD_EN PORTD.1
#define LCD_D4 PORTD.2
#define LCD_D5 PORTD.3
#define LCD_D6 PORTD.4
#define LCD_D7 PORTD.5

#define LCD_RS_Direction DDRD.0
#define LCD_EN_Direction DDRD.1
#define LCD_D4_Direction DDRD.2
#define LCD_D5_Direction DDRD.3
#define LCD_D6_Direction DDRD.4
#define LCD_D7_Direction DDRD.5

#define LED PORTB.0

void LCD_Cmd(char out_char) {
    LCD_RS = 0;
    LCD_D4 = (out_char & 0x10)?1:0;
    LCD_D5 = (out_char & 0x20)?1:0;
    LCD_D6 = (out_char & 0x40)?1:0;
    LCD_D7 = (out_char & 0x80)?1:0;
    
    LCD_STROBE
    
    LCD_D4 = (out_char & 0x01)?1:0;
    LCD_D5 = (out_char & 0x02)?1:0;
    LCD_D6 = (out_char & 0x04)?1:0;
    LCD_D7 = (out_char & 0x08)?1:0;
    
    LCD_STROBE
    
    if(out_char == 0x01)delay_ms(2);
}

void LCD_Chr(char row, char column, char out_char) {
    switch(row){
        case 1:
        LCD_Cmd(0x80 + (column - 1));
        break;
        case 2:
        LCD_Cmd(0xC0 + (column - 1));
        break;
        case 3:
        LCD_Cmd(0x94 + (column - 1));
        break;
        case 4:
        LCD_Cmd(0xD4 + (column - 1));
        break;
    }
    
    LCD_RS = 1;
    LCD_D4 = (out_char & 0x10)?1:0;
    LCD_D5 = (out_char & 0x20)?1:0;
    LCD_D6 = (out_char & 0x40)?1:0;
    LCD_D7 = (out_char & 0x80)?1:0;
    
    LCD_STROBE
    
    LCD_D4 = (out_char & 0x01)?1:0;
    LCD_D5 = (out_char & 0x02)?1:0;
    LCD_D6 = (out_char & 0x04)?1:0;
    LCD_D7 = (out_char & 0x08)?1:0;
    
    LCD_EN = 1;
    
    LCD_STROBE
}

void LCD_Chr_Cp(char out_char) {
    LCD_RS = 1;
    LCD_D4 = (out_char & 0x10)?1:0;
    LCD_D5 = (out_char & 0x20)?1:0;
    LCD_D6 = (out_char & 0x40)?1:0;
    LCD_D7 = (out_char & 0x80)?1:0;
    LCD_STROBE
    LCD_D4 = (out_char & 0x01)?1:0;
    LCD_D5 = (out_char & 0x02)?1:0;
    LCD_D6 = (out_char & 0x04)?1:0;
    LCD_D7 = (out_char & 0x08)?1:0;
    LCD_EN = 1;
    LCD_STROBE
}

void LCD_Init() {
    
    delay_ms(200);
    
    LCD_RS_Direction = 1;
    LCD_EN_Direction = 1;
    LCD_D4_Direction = 1;
    LCD_D5_Direction = 1;
    LCD_D6_Direction = 1;
    LCD_D7_Direction = 1;
    
    LCD_RS = 0;
    LCD_EN = 0;
    LCD_D4 = 0;
    LCD_D5 = 0;
    LCD_D6 = 0;
    LCD_D7 = 0;    
    
    delay_ms(30);
    
    LCD_D4 = 1;
    LCD_D5 = 1;
    LCD_D6 = 0;
    LCD_D7 = 0;
    
    LCD_STROBE
    
    delay_ms(30);
    
    LCD_D4 = 1;
    LCD_D5 = 1;
    LCD_D6 = 0;
    LCD_D7 = 0;
    
    LCD_STROBE
    
    delay_ms(30);
    
    LCD_D4 = 1;
    LCD_D5 = 1;
    LCD_D6 = 0;
    LCD_D7 = 0;
    
    LCD_STROBE
    
    delay_ms(30);
    
    LCD_D4 = 0;
    LCD_D5 = 1;
    LCD_D6 = 0;
    LCD_D7 = 0;
    
    LCD_STROBE
    
    delay_ms(10);
    
    LCD_Cmd(0x28);
    LCD_Cmd(0x06);
}

void LCD_Out(char row, char col, char *text) {
    while(*text)
         LCD_Chr(row, col++, *text++);
}

void LCD_Out_Cp(char *text) {
    while(*text)
         LCD_Chr_Cp(*text++);
}

void main(void)
{
// Declare your local variables here
// Input/Output Ports initialization
// Port A initialization
// Function: Bit7=In Bit6=In Bit5=Out Bit4=Out Bit3=Out Bit2=Out Bit1=Out Bit0=Out 
DDRA=(0<<DDA7) | (0<<DDA6) | (1<<DDA5) | (1<<DDA4) | (1<<DDA3) | (1<<DDA2) | (1<<DDA1) | (1<<DDA0);
// State: Bit7=T Bit6=T Bit5=0 Bit4=0 Bit3=0 Bit2=0 Bit1=0 Bit0=0 
PORTA=(0<<PORTA7) | (0<<PORTA6) | (0<<PORTA5) | (0<<PORTA4) | (0<<PORTA3) | (0<<PORTA2) | (0<<PORTA1) | (0<<PORTA0);
// Port B initialization
// Function: Bit7=Out Bit6=Out Bit5=Out Bit4=Out Bit3=Out Bit2=Out Bit1=Out Bit0=Out 
DDRB=(1<<DDB7) | (1<<DDB6) | (1<<DDB5) | (1<<DDB4) | (1<<DDB3) | (1<<DDB2) | (1<<DDB1) | (1<<DDB0);
// State: Bit7=0 Bit6=0 Bit5=0 Bit4=0 Bit3=0 Bit2=0 Bit1=0 Bit0=0 
PORTB=(0<<PORTB7) | (0<<PORTB6) | (0<<PORTB5) | (0<<PORTB4) | (0<<PORTB3) | (0<<PORTB2) | (0<<PORTB1) | (0<<PORTB0);
// Port C initialization
// Function: Bit7=Out Bit6=Out Bit5=Out Bit4=Out Bit3=Out Bit2=Out Bit1=Out Bit0=Out 
DDRC=(1<<DDC7) | (1<<DDC6) | (1<<DDC5) | (1<<DDC4) | (1<<DDC3) | (1<<DDC2) | (1<<DDC1) | (1<<DDC0);
// State: Bit7=0 Bit6=0 Bit5=0 Bit4=0 Bit3=0 Bit2=0 Bit1=0 Bit0=0 
PORTC=(0<<PORTC7) | (0<<PORTC6) | (0<<PORTC5) | (0<<PORTC4) | (0<<PORTC3) | (0<<PORTC2) | (0<<PORTC1) | (0<<PORTC0);
// Port D initialization
// Function: Bit7=Out Bit6=Out Bit5=Out Bit4=Out Bit3=Out Bit2=Out Bit1=Out Bit0=Out 
DDRD=(1<<DDD7) | (1<<DDD6) | (1<<DDD5) | (1<<DDD4) | (1<<DDD3) | (1<<DDD2) | (1<<DDD1) | (1<<DDD0);
// State: Bit7=0 Bit6=0 Bit5=0 Bit4=0 Bit3=0 Bit2=0 Bit1=0 Bit0=0 
PORTD=(0<<PORTD7) | (0<<PORTD6) | (0<<PORTD5) | (0<<PORTD4) | (0<<PORTD3) | (0<<PORTD2) | (0<<PORTD1) | (0<<PORTD0);
// Timer/Counter 0 initialization
// Clock source: System Clock
// Clock value: Timer 0 Stopped
// Mode: Normal top=0xFF
// OC0 output: Disconnected
TCCR0=(0<<WGM00) | (0<<COM01) | (0<<COM00) | (0<<WGM01) | (0<<CS02) | (0<<CS01) | (0<<CS00);
TCNT0=0x00;
OCR0=0x00;
// Timer/Counter 1 initialization
// Clock source: System Clock
// Clock value: Timer1 Stopped
// Mode: Normal top=0xFFFF
// OC1A output: Disconnected
// OC1B output: Disconnected
// Noise Canceler: Off
// Input Capture on Falling Edge
// Timer1 Overflow Interrupt: Off
// Input Capture Interrupt: Off
// Compare A Match Interrupt: Off
// Compare B Match Interrupt: Off
TCCR1A=(0<<COM1A1) | (0<<COM1A0) | (0<<COM1B1) | (0<<COM1B0) | (0<<WGM11) | (0<<WGM10);
TCCR1B=(0<<ICNC1) | (0<<ICES1) | (0<<WGM13) | (0<<WGM12) | (0<<CS12) | (0<<CS11) | (0<<CS10);
TCNT1H=0x00;
TCNT1L=0x00;
ICR1H=0x00;
ICR1L=0x00;
OCR1AH=0x00;
OCR1AL=0x00;
OCR1BH=0x00;
OCR1BL=0x00;
// Timer/Counter 2 initialization
// Clock source: System Clock
// Clock value: Timer2 Stopped
// Mode: Normal top=0xFF
// OC2 output: Disconnected
ASSR=0<<AS2;
TCCR2=(0<<PWM2) | (0<<COM21) | (0<<COM20) | (0<<CTC2) | (0<<CS22) | (0<<CS21) | (0<<CS20);
TCNT2=0x00;
OCR2=0x00;
// Timer(s)/Counter(s) Interrupt(s) initialization
TIMSK=(0<<OCIE2) | (0<<TOIE2) | (0<<TICIE1) | (0<<OCIE1A) | (0<<OCIE1B) | (0<<TOIE1) | (0<<OCIE0) | (0<<TOIE0);
// External Interrupt(s) initialization
// INT0: Off
// INT1: Off
// INT2: Off
MCUCR=(0<<ISC11) | (0<<ISC10) | (0<<ISC01) | (0<<ISC00);
MCUCSR=(0<<ISC2);
// USART initialization
// USART disabled
UCSRB=(0<<RXCIE) | (0<<TXCIE) | (0<<UDRIE) | (0<<RXEN) | (0<<TXEN) | (0<<UCSZ2) | (0<<RXB8) | (0<<TXB8);
// Analog Comparator initialization
// Analog Comparator: Off
// The Analog Comparator's positive input is
// connected to the AIN0 pin
// The Analog Comparator's negative input is
// connected to the AIN1 pin
ACSR=(1<<ACD) | (0<<ACBG) | (0<<ACO) | (0<<ACI) | (0<<ACIE) | (0<<ACIC) | (0<<ACIS1) | (0<<ACIS0);
SFIOR=(0<<ACME);
// ADC initialization
// ADC disabled
ADCSRA=(0<<ADEN) | (0<<ADSC) | (0<<ADATE) | (0<<ADIF) | (0<<ADIE) | (0<<ADPS2) | (0<<ADPS1) | (0<<ADPS0);
// SPI initialization
// SPI disabled
SPCR=(0<<SPIE) | (0<<SPE) | (0<<DORD) | (0<<MSTR) | (0<<CPOL) | (0<<CPHA) | (0<<SPR1) | (0<<SPR0);
// TWI initialization
// TWI disabled
TWCR=(0<<TWEA) | (0<<TWSTA) | (0<<TWSTO) | (0<<TWEN) | (0<<TWIE);

LCD_Init();
LCD_Cmd(_LCD_CURSOR_OFF);
LCD_Cmd(_LCD_CLEAR);
LCD_Out(1,1,"ATMega32A");
LCD_Out(2,1,"4 MHz");
LCD_Out(3,1,"CodeVisionAVR");
LCD_Out(4,1,"LCD 20x4 4-Bit");

while (1)
      {
      // Place your code here 
      LED = ~LED;
      delay_ms(500);
      }
}

 

 

 

 

LCD 20x4 Proteus Simulation

Attachment(s): 

Regards

Jayanth D

Last Edited: Mon. Feb 29, 2016 - 04:08 AM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

jgmdesign wrote:

I found a bug.

you wot m8 ?

 

 

jgmdesign wrote:

Kartman wrote:
he can build a known good Arduino sketch for the lcd and burn it onto his chip.

 

Russell has a point, and something told me to look at the project I sent....I found a bug.

 

In the LCD.h file I skipped a pin on the port.  Thus all the control pins were off by one.  You would never get anything on the screen... My apologies for my mistake. blush

 

The port/lcd pin assignment I posted is correct.  I corrected my error in the .h file and as such here is what you get:

 

I also included the while() loop as well.

 

A very long day and 1am in the morning is no excuse for missing that obvious blunder.

 

Please accept my apologies on this and understand it was not intentional.

 

I have attached the corrected project to this post.

 

Jim

 

no worries, you've been absolutely terrific and very helpful, and it finally worked.

and I do need to get into soldering, cuz without that, it's glitchy and unreliable.

 

 

Here's the long waited output. Blue LCD looks really cool, green lcd is so yesterday cheeky

 

 

 

Last Edited: Mon. Feb 29, 2016 - 11:38 AM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

@JAYANTH.DEVARAYANADURGA 

thanks for your reply, but I don't use proteus unfortunately. 

Last Edited: Mon. Feb 29, 2016 - 05:03 AM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

My LCD library is tested in hardware also and it works fine.

Regards

Jayanth D