16x2 LCD only displaying blocks, no content? Atmega8

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

So I had this working on my attiny2313 and decided to switch to the atmega8.

Here is my breadboard.

http://s11.postimg.org/9qmqcu7b7...

 

Here is my code.

 

http://pastie.org/10070300

 

 

For some reason that I am unaware of the 16x2 LCD is not displaying any text. As far as I know, all of these pins can be used for digital in/out.

 

I'm at a loss as to why nothing is happening.

This topic has a solution.

Last Edited: Thu. Apr 2, 2015 - 06:53 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I can't see your PNG.

 

However,   your code has:

#define Enable_Pin		  1
#define RegSelect_Pin     4
#define ReadWrite_Pin     3
   ...
   CONTROL_DDR=0b1110000;//setting selected pins of control port for output //0b1110000 //0X70
   

It looks as if they 'tried' to make it configurable.    But then put in this magic value.

 

I would study some library calls.   e.g. look at the API for the common LCD functions.

 

By all means write your own code,   but I would 'design' the API first.

 

David.

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

What does "only displaying blocks" mean?

 

A powered but uninitialized character LCD will show solid black block characters on the odd numbered lines.  Not both lines on a 2x; only the top line.  Adjust your contrast until you see that.

You can put lipstick on a pig, but it is still a pig.

I've never met a pig I didn't like, as long as you have some salt and pepper.

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

png looks good here, but you need a couple caps (5V to gnd, vcc to gnd on avr). Does the trim pot need 5V? I see the gnd.

Imagecraft compiler user

Last Edited: Thu. Apr 2, 2015 - 07:01 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

david.prentice wrote:

I can't see your PNG.

 

However,   your code has:

#define Enable_Pin		  1
#define RegSelect_Pin     4
#define ReadWrite_Pin     3
   ...
   CONTROL_DDR=0b1110000;//setting selected pins of control port for output //0b1110000 //0X70
   

It looks as if they 'tried' to make it configurable.    But then put in this magic value.

 

I would study some library calls.   e.g. look at the API for the common LCD functions.

 

By all means write your own code,   but I would 'design' the API first.

 

David.

 

Oh so I need to change CONTROL_DDR as well to match the pins I'm using. Yes this was someone elses code but I'm modifying it and learning. I'm still a n00b.

 

How do I determine what value should be here with the ddrd pins all over the atmega? Does the bit value go in order? There are 8 ddrd pins but only 7 values in

CONTROL_DDR=0b1110000

 

I tried setting it to 0b10110000 and it didn't work as expected.. still only blocks being displayed.

 

 

I figured it out.. .apparently it's

(UPPER NIBBLE)(LOWER NIBBLE)

7654                  3210

 

CONTROL_DDR=0b00011010 WORKED LIKE A CHARM!

Last Edited: Thu. Apr 2, 2015 - 08:09 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Yes it is the solid black block characters on line 1. I see that on my LCD.

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

Hey bob right now I don't have any caps :(

 

The potentiometer I'm using works with the rear contact on ground and one of the legs to the pin.

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

How do I determine what value should be here with the ddrd pins all over the atmega?

They are the same bits on the same port that you use to set/clear the pin values.

Regards,
Steve A.

The Board helps those that help themselves.

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

I figured it out.. .apparently it's

(UPPER NIBBLE)(LOWER NIBBLE)

7654                  3210

 

CONTROL_DDR=0b00011010 WORKED LIKE A CHARM!

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

I think you need to wire the pot from 5V to gnd, then run the middle pin to VEE. Correct setting is about half a volt. And go get a piece of junk and unsolder 2 caps from it.

Imagecraft compiler user

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

http://www.ebay.com/itm/2-pcs-1K...

 

This is the part I'm using there.

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

If your 16x2 LCD is powered by 5V,   the contrast pin will be 'best' at 0V to 0.5V.

 

So you should get a readable display if you connect the pin#3 to GND.

 

Obviously,  with a potentiometer you can get the perfect contrast.

 

It also means that if your LCD is powered by 3.3V the contrast pin must be -ve.

 

David.

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

Here is my breadboard.

That is not your breadboard.  It is a (horrible) depiction of how you think the LCD should be connected.  We really need to see a photograph of your actual connections to evaluate if the wiring is correct.

 

Since you see a single row of blocks on your two row display your contrast setting is 'close enough' to proceed.

 

Your initialization routine has no chance of working properly since the 'function set' instruction cannot follow any other instruction.  Your routine won't work even with the 'function set' first since you are spitting out the instructions one right after the other without giving the LCD controller time to execute each one. 

 

It would be a good idea to follow the recommendations given in the datasheet flowchart.  Follow the LCD Initialization link at http://web.alfredstate.edu/weimandn if you would like to find out how to do the initialization correctly.

 

I suggest first trying to display a single character on the display before doing anything fancy.

 

Don

 

 

Last Edited: Thu. Apr 2, 2015 - 09:54 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

This is EXACTLY my breadboard and I've already got this working on the attiny2313 previous to this. All my wiring is correct because as posted I've already got it working on my atmega8 now, thank you for trying to help but you really should read the entire thread before commenting as with any other forum.

 

This topic can be CLOSED. Thank you.

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

To say that picture leaves much to be desired is an understatement.

 

As noted it is great that you want to write your own LCD code, why not first use something that will work, and confirm your hardware is operational first?

I cannot tell what those resistors on the 'board' are used for, but the Atmel Studio project I have attached will run on your AVR with the internal oscillator at either 8Mhz, and it will also run id the DIV8 fuse is enabled as well.

 

If your connections are all good, you will see  "Code From AVR  Freaks!!" on the two lines of the display, then the screen will blank for a second or two then the display will come back.  THis will happen over and over.

 

Once you confirm your hardware THEN you can work on your code.

 

Here are the pinouts of the AVR and what they are to be connected to on the LCD.  The code runs teh LCD in 4-bit mode, I used PORTD.

 

AVR                   LCD

PORTD.0            DATA PIN 4

PORTD.1            DATA PIN 5

PORTD.2            DATA PIN 6

PORTD.3            DATA PIN 7

 

PORTD.4            RS PIN

PORTD.5            R/W PIN

PORTD.6            E PIN

 

 

Edit:

I see you posted before I did.  Great that you were able to get it going.  Care to share what the issue was?  I doubt it based on your last response.

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: Thu. Apr 2, 2015 - 10:09 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Yes I posted up there what the issue was -

 

(Sorry I'm new to the forums I just realized I can mark a solution)

 

I figured it out.. .apparently it's

(UPPER NIBBLE)(LOWER NIBBLE)

7654                  3210

 

CONTROL_DDR=0b00011010 WORKED LIKE A CHARM!

Last Edited: Thu. Apr 2, 2015 - 10:33 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Hi everybody, first thanks to all of you for sharing your wisdom with other thus helping others to achieve something,

I am new to uc world after lot of pain I managed to blink a LED, now I am trying to put something on LCD, after going through various links, tutorials, schematics I managed to get all the things on breadboard, but nothing is on LCD, it is showing only blocks in one line. My uc-lcd pin details are:

 

Atmega8                              LCD

PORTD2                              PIN4

PORTD5                              PIN6

PORTD7                              PIN5

PORTB0                              PIN11  

PORTB1                              PIN12 

PORTB2                              PIN13

PORTB3                              PIN14

                                              PIN15 --- +5V

                                              PIN16 --- Gnd

                                              PIN1   --- Gnd

                                              PIN2   --- +5V

                                              PIN3   --- Centre tap of VR (10K)

 

Please find the code at attachment, please guide me to get something of my choice on LCD

Attachment(s): 

Sanju Diode

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

Well where are you setting 8 bit or 4 bit mode?

//	Send_A_Command(0x38); // To set the LCD in 8 bit mode

Send_A_Command(0b00001111);

If you want 8 bit mode you need all 8 pins of the LCD connected. If you want 4 bit mode you have to send the data 1 nibble at a time.

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

Hi, thanks for quick comment, i had tried with 8 bit mode also, with connecting the pin 7-10 of LCD to PortD (4-7), with uncommenting the above mentioned line in my code. But i could'nt get the desired result.

Sanju Diode

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

Could anyone clear the concept of "nibble" mentioned in previous comment

 

Sanju Diode

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

A nibble is four bits, or half of a byte.

 

If your LCD is showing only blocks in one line then it is not properly initialized.  There are some good libraries and example programs that do the initialization properly but the program posted earlier in this thread (in the original post) is not one of them.  Follow the link in reply #13 to see how to do this correctly.

 

Also, you really should stay away from the MrLCD example - it's really worthless.  Use do a Google search for the phrase: 'MrLCD site:avrfreaks.net' to get some previous comments about this.

 

Don

Last Edited: Fri. Apr 3, 2015 - 07:31 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

The lcd wants the E line to go hi for half a usec then lo. I always write a macro called EPULSE() that has EHI(); NOP(); .... NOP(); ELO(); in it; The number of nops has to do with how fast the computer is running. Example: 16MHz is 62.5ns per nop. 500/62.5 is about 8 nops. Compri?

 

Imagecraft compiler user

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

SAnjay,

 

If you run the project I attached above and connect your LCD according to what I laid out you should see a nice little welcome screen.  Which AVR are you using?

 

Also what IDE are you using? Studio?

Programmer?

 

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