HC595 to LCD 8-bit mode interface

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

Dear all,I allready have the hardwear of atmega32 and 74hc595 and a 2x16 LCD connected on 8bit mode,the only thing I need is the c code for running the system.will you please help me in this regards?

more to say I had run a seperate system ie  atmega with lcd and another atmega  with 74595 and leds. but not the above system. please c code in codevision only!

Last Edited: Fri. Mar 3, 2017 - 09:58 AM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

azizollah wrote:

... please c code in codevision only!

 

Have you looked at any of the links provided above?

#1 This forum helps those that help themselves

#2 All grounds are not created equal

#3 How have you proved that your chip is running at xxMHz?

#4 "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." - Heater's ex-boss

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

azizollah wrote:
please c code in codevision only!

Are you inviting people to quote for this?

 

 

Top Tips:

  1. How to properly post source code - see: https://www.avrfreaks.net/comment... - also how to properly include images/pictures
  2. "Garbage" characters on a serial terminal are (almost?) invariably due to wrong baud rate - see: https://learn.sparkfun.com/tutorials/serial-communication
  3. Wrong baud rate is usually due to not running at the speed you thought; check by blinking a LED to see if you get the speed you expected
  4. Difference between a crystal, and a crystal oscillatorhttps://www.avrfreaks.net/comment...
  5. When your question is resolved, mark the solution: https://www.avrfreaks.net/comment...
  6. Beginner's "Getting Started" tips: https://www.avrfreaks.net/comment...
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I have looked to many links but the result is no sign in lcd.

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

Sorry I don,t understand you clearly . but if quote is a way please go on.

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

Please read my replies #10, #15, #20.

 

I have written the Codevision library for "sensible" SPI wiring.

If you produce a compelling reason for #9,   I will write a suitable "special".

 

It does appear to be a no-brainer.   I2C adapters are very cheap.   If you have other I2C devices,  the LCD takes no extra pins at all !

 

David.

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

David, as I said earlier I have written the code but don,t know why nothing appear on the screen of lcd.

 

this is part of my code:

 

 rs=1;rw=0;en=1; // RS and RW as LOW and EN as HIGH
    delay_ms(10);
         HC595Write(0x41) ;   //Write the data to HC595
         Wait();                 //Wait 
     
   rs=1;rw=0;en=0;
   delay_ms(20);

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

This is my code:

 

void main()
{
 DDRB=0xff;
 PORTB=0xff;
 DDRA=0xff;
 PORTA=0xff;

  
   HC595Init(); 
   HC595Write(0x38);   //Write the data to HC595 to set to 8bit mode
         Wait();                 //Wait 
 
  rs=0;rw=0;en=1; // RS and RW as LOW and EN as HIGH
    delay_ms(10);
   rs=0;rw=0;en=0;
   delay_ms(20);
  

  

   while(1)
   {
      
         rs=1;rw=0;en=1; // RS and RW as LOW and EN as HIGH
    delay_ms(10);
         HC595Write(0x41) ;   //Write the data to HC595 to show charecter A
         Wait();                 //Wait 
     
   rs=1;rw=0;en=0;
   delay_ms(20);
     rs=1;rw=0;en=1; // RS and RW as LOW and EN as HIGH
    delay_ms(10);
         HC595Write(0x34) ;   //Write the data to HC595 to show no.4
         Wait();                 //Wait 
     
   rs=1;rw=0;en=0;
   delay_ms(20); 
    rs=1;rw=0;en=1; // RS and RW as LOW and EN as HIGH
    delay_ms(10);
         HC595Write(0x42) ;//led_pattern[i]);   //Write the data to HC595
         Wait();                 //Wait 
     
   rs=1;rw=0;en=0;
   delay_ms(20);  
         
      
   }

}

Will you please say whats wrong with this?

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0
 HC595Write(0x38);   //Write the data to HC595 to set to 8bit mode
         Wait();                 //Wait 
 
  rs=0;rw=0;en=1; // RS and RW as LOW and EN as HIGH
    delay_ms(10);
   rs=0;rw=0;en=0;
   delay_ms(20);

Are you sure this is all it takes to init the 16x2 LCD display?  

 

Click Link: Get Free Stock: Retire early! PM for strategy

share.robinhood.com/jamesc3274
get $5 free gold/silver https://www.onegold.com/join/713...

 

 

 

 

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

this is that part

void HC595Init()
{
   //Make the Data(DS), Shift clock (SH_CP), Store Clock (ST_CP) lines output
   HC595_DDR|=((1<<HC595_SH_CP_POS)|(1<<HC595_ST_CP_POS)|(1<<HC595_DS_POS));
}

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

azizollah wrote:
This is my code:

I don't get it at all.

 

You posed a schematic in #9 that shows the shift register driving three control pins, and four data pins.

 

Now you post the code, with mysteries as to what en and rw and rs are, along with a comment about using 8-bit mode.

 

Tell what your connections really are.  Show your >>real<< code; a complete test program.  [and as always:  AVR model; clock speed; Vcc level; language; toolchain; version; optimization settings; ...]

 

 

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: 1

I am not #9 person I am somebody else.My problem is a bit different.

I have 3 control bit for lcd and 3 bit for 74595 .   8Mhz speed,atmega32a. codevision enviroment.

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

The solution to this problem is *all* over the internet from years ago. What people are asking for is a NO THOUGHT solution tailored to a specific chip and specific circuit for a specific compiler that just works on a pirated simulator. Good Lord! When I was in school, the point was you READ the data sheets and figured it out yourself because that is what your job required. Here is your solution: Type "arduino lcd hc595" into google for schematics and liquid crystal librarys. Or even go to this link that says Hookup an LCD to an Arduino in 6 seconds with 3 pins That's what it takes these days.

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

Well, the questions still remain...

 

Why would you want to save a single pin and add a part and a custom driver?

 

 

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: 1

Attaching your issues to another persons thread is rather rude.

 

Also, POST YOUR ENTIRE CODE.  Turning this thread into a cat and mouse game trying to figure out what you are doing is a waste of everyones time.

 

I'll split the thread.

 

JIm - Moderator

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. Mar 2, 2017 - 07:48 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 1

OK, so on a re-read the search is for 8-bit code to drive character LCD, and in CodeVision dialect.

 

I've used character LCDs in scores of production AVR8 apps over the years, but never in 8-bit mode.  Generally, the extra update time for 4-bit mode isn't as precious as the four extra port pins.

 

I use a modified CV driver based on a version of lcd.lib from many years ago.  With an understanding of the needed sequences, it should be straightforward to do the needed modifications.

 

Or, 8-bit should end up as fairly straightforward C code.  I'd think that a decent 8-bit driver found on the Web could be easily ported to CV.

 

To go further, you'd have to convince me of the value of insisting on 8-bit mode.

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: 1

first of all thank you for splitting my problem with other people. Actually I didn't know how to inter my question from the beginning .I am new to this. please quid me.

secondly I said my hard wear was already built in that way and can not be changed due to pcb. 

 

The complete code is this:

 

#include <io.h>
#include <delay.h>
#include <mega32a.h>
/***************************************

Configure Connections

****************************************/

#define HC595_PORT   PORTA
#define HC595_DDR    DDRA

#define HC595_DS_POS PORTA.4      //Data pin (DS) pin location

#define HC595_SH_CP_POS PORTA.5      //Shift Clock (SH_CP) pin location 
#define HC595_ST_CP_POS PORTA.6      //Store Clock (ST_CP) pin location

//#define LCD_DATA PORTA.4 // LCD data port
#define en PORTA.2 // enable signal
#define rw PORTA.1 // read/write signal
#define rs PORTA.0 // register select signal

/***************************************
Configure Connections ***ENDS***
****************************************/

//Initialize HC595 System

void HC595Init()
{
   //Make the Data(DS), Shift clock (SH_CP), Store Clock (ST_CP) lines output
   HC595_DDR|=((1<<HC595_SH_CP_POS)|(1<<HC595_ST_CP_POS)|(1<<HC595_DS_POS));
}

//Low level macros to change data (DS)lines
#define HC595DataHigh() (HC595_PORT|=(1<<HC595_DS_POS))

#define HC595DataLow() (HC595_PORT&=(~(1<<HC595_DS_POS)))

//Sends a clock pulse on SH_CP line
void HC595Pulse()
{
   //Pulse the Shift Clock

   HC595_PORT|=(1<<HC595_SH_CP_POS);//HIGH

   HC595_PORT&=(~(1<<HC595_SH_CP_POS));//LOW

}

//Sends a clock pulse on ST_CP line
void HC595Latch()
{
   //Pulse the Store Clock

   HC595_PORT|=(1<<HC595_ST_CP_POS);//HIGH
   delay_ms(10);

   HC595_PORT&=(~(1<<HC595_ST_CP_POS));//LOW
   delay_ms(10);
}

/*

Main High level function to write a single byte to
Output shift register 74HC595. 

Arguments:
   single byte to write to the 74HC595 IC

Returns:
   NONE

Description:
   The byte is serially transfered to 74HC595
   and then latched. The byte is then available on
   output line Q0 to Q7 of the HC595 IC.

*/
//unsigned int data ;
void HC595Write(unsigned int data)
{
   //Send each 8 bits serially
    int i=0;
   //Order is MSB first
   for(i=0;i<8;i++)
   {
      //Output the data on DS line according to the
      //Value of MSB
      if(data & 0b10000000)
      {
         //MSB is 1 so output high

         HC595DataHigh();
      }
      else
      {
         //MSB is 0 so output high
         HC595DataLow();
      }

      HC595Pulse();  //Pulse the Clock line
      delay_ms(10);
      data=data<<1;  //Now bring next bit at MSB position

   }

   //Now all 8 bits have been transferred to shift register
   //Move them to output latch at one
   HC595Latch();
   
}

/*

Simple Delay function approx 0.5 seconds

*/

void Wait()
{
int i=0;
   for(i=0;i<30;i++)
   {
      delay_ms(10);
   }
}
  int i=0;
 // uint_t data;     //Initialize HC595 system
void main()
{
 DDRB=0xff;
 PORTB=0xff;
 DDRA=0xff;
 PORTA=0xff;

  for(i=0;i<=3;i++) //Startup Led
  {
  PORTB.4=~PORTB.4;
  delay_ms(200);
  }             
  PORTB.4=1;
   HC595Init(); 
   HC595Write(0x38);   //Write the data to HC595
         Wait();                 //Wait 
 
  rs=0;rw=0;en=1; // RS and RW as LOW and EN as HIGH
    delay_ms(10);
   rs=0;rw=0;en=0;
   delay_ms(20);
  

  

   while(1)
   {
      PORTA.7=1;  // back light on/off
    delay_ms(1000);
         rs=1;rw=0;en=1; // RS and RW as LOW and EN as HIGH
    delay_ms(10);
         HC595Write(0x41) ; //Write the data to HC595
         Wait();                 //Wait 
     
   rs=1;rw=0;en=0;
   delay_ms(20);
     rs=1;rw=0;en=1; // RS and RW as LOW and EN as HIGH
    delay_ms(10);
         HC595Write(0x14) ;   //Write the data to HC595
         Wait();                 //Wait 
     
   rs=1;rw=0;en=0;
   delay_ms(20); 
    rs=1;rw=0;en=1; // RS and RW as LOW and EN as HIGH
    delay_ms(10);
         HC595Write(0x24) ;   //Write the data to HC595
         Wait();                 //Wait 
     
   rs=1;rw=0;en=0;
   delay_ms(20);  
     PORTA.7=0;
    delay_ms(1000);
      
      
   }

}

 

Last Edited: Thu. Mar 2, 2017 - 08:59 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Please use the CODE button <> above when posting code, I have edited your post.

John Samperi

Ampertronics Pty. Ltd.

www.ampertronics.com.au

* Electronic Design * Custom Products * Contract Assembly

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

Thanks Js . you are lovely! but i didn,t get you how I should do that. give an example.please. More important is please tell me what wrong with this code that I see nothing on lcd.

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

Ross McKenzie ValuSoft Melbourne Australia

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

azizollah wrote:

first of all thank you for splitting my problem with other people. Actually I didn't know how to inter my question from the beginning .I am new to this. please quid me.

secondly I said my hard wear was already built in that way and can not be changed due to pcb. 

 

The complete code is this:

 

#include <io.h>
#include <delay.h>
#include <mega32a.h>
/***************************************

Configure Connections

****************************************/

 

It was great thanks

 

 

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

What is great Azadfallah? the code? did it work for you?

It didn,t work for me anyway!

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

azizollah wrote:

It didn,t work for me anyway!

 

Maybe the code works but your hardware doesn't?

#1 This forum helps those that help themselves

#2 All grounds are not created equal

#3 How have you proved that your chip is running at xxMHz?

#4 "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." - Heater's ex-boss

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

azizollah wrote:

What is great Azadfallah? the code? did it work for you?

It didn,t work for me anyway!

 

I've tried does not work, But I'm working on

Last Edited: Fri. Mar 3, 2017 - 11:01 AM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Your clock pulse code below is pretty fast :

//Sends a clock pulse on SH_CP line
void HC595Pulse()
{
   //Pulse the Shift Clock

   HC595_PORT|=(1<<HC595_SH_CP_POS);//HIGH

   HC595_PORT&=(~(1<<HC595_SH_CP_POS));//LOW

}

You may want to try slowing it down a bit my adding a delay between the  high/low output:

 

//Sends a clock pulse on SH_CP line
void HC595Pulse()
{
   //Pulse the Shift Clock

   HC595_PORT|=(1<<HC595_SH_CP_POS);//HIGH
    //add some NOP's or a small delay of 100us to 1ms here
   HC595_PORT&=(~(1<<HC595_SH_CP_POS));//LOW

}

Just to see what happens!

 

Jim

Click Link: Get Free Stock: Retire early! PM for strategy

share.robinhood.com/jamesc3274
get $5 free gold/silver https://www.onegold.com/join/713...

 

 

 

 

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

Thank you Jim, its nice of you to spend some of your time on this. As you advised, I gave a delay of 20ms but no change!

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

At the risk of repeating myself, how do you know your hardware works?

#1 This forum helps those that help themselves

#2 All grounds are not created equal

#3 How have you proved that your chip is running at xxMHz?

#4 "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." - Heater's ex-boss

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

I am 100 percent sure the hardware is ok. Are you sure my code is ok?

Last Edited: Fri. Mar 3, 2017 - 09:59 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I am interested in this too. but I am supersized why no body seem to care and solve this problem!

Please help its my concern too.

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

This seems a rather pointless exercise:

1.  3 pins for RS, RW, EN and 3 pins for HC595_SH_CP_POS, HC595_ST_CP_POS, HC595_DS_POS

2.  a regular 4-bit LCD library only uses 6 pins (if you are write-only)

 

Yes,  it might be a good student exercise to write a regular 8-bit LCD driver.   i.e. 11 pins

 

Having got it working with an 8-bit PORT and 3 control lines,  you can replace the 8-bit PORT with your HC595 shift register.

 

You should be able to Simulate a 4-bit or 8-bit LCD in Proteus.   Both with a regular PORT or with the HC595.

 

I would always start by using a proven library.   Preferably one that is simple e.g. uses a whole PORT rather than trying to mix random pins.

Build your project.  Simulate it.   Study how it works,

 

Adapt it for your own style.  e.g. change names and comments to your own language.

Then make your final step to replace the LCDPORT = value statements into  write_HC595(value) statements.

 

There is nothing wrong with finding proven code and adapting it for your own purposes.    Providing that you understand how it works.

 

Ask a specific question.   Do not expect us to do your homework for you.

 

David.

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

azizollah wrote:
I am interested in this too. but I am supersized why no body seem to care and solve this problem!

NO!  YOU are interested in only wanting someone else to solve YOUR problem.

 

azizollah wrote:
I am 100 percent sure the hardware is ok.

PROVE IT!  How are you so sure?  You have nothing to test it with.

 

After looking at this, I cannot for the lie of me understand what you expect to gain from this configuration.  As it stands you need 5 signal lines to interface to the screen

 

Serial Data

Serial Clock

EN

R/W

RS

 

You could simply run the screen in 4bit mode and use a single port from the AVR and use 7 pins

 

D0

D1

D2

D3

EN

R/W

RS

 

And then use the 8th pin for turning the backlight LED on or off.  THere is a proven library by Peter Fleury for this very configuration, and there is a CodeVision library as well IIRC.

 

If you really want to save I/O pins then go the I2C route using either the MC23017 or PCF8754 and then you only need TWO I/O pins.

 

So before you start barking that there is nothing wrong with your Hardware setup and expecting everyone to look at your code....Which from what I can see does not initialise an LCD correctly, if at all, I would suggest you take another look at what you want to do, and reread this thread, as well as the one you originally hijacked and see that there have been far better solutions presented to you that in the end will make your life, and ours so much easier.

 

If you insist on continuing this path you are on, then look at your code AND your Hardware - To which since we have no schematic or picture of your setup we can only guess the mess.

 

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

I do not have Proteus to put a drawings so i can not draw a schematic here .The other fact is I have a pcb already  made and can not do any changes.

I thank those who care  to look to my problem and advise others to be kind and polite to new comers like me.We will learn from you .Be a good  symbol of humanity.

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

azizollah wrote:
I do not have Proteus to put a drawings so i can not draw a schematic here .

Do you have something called a PENCIL, and PAPER?  Draw it on that, and take a picture and post that.  At least thats something.  THere are also many Free Schematic capture programs out there

 

Here's one:

http://diptrace.com/download-dip...

Option #2 FREEWARE.

 

azizollah wrote:
I thank those who care to look to my problem and advise

Too bad you are not listening.  But you sure can make demands.

 

 

Ok, Time to backtrack then a little. 

Is the code you have in POST#17 the ENTIRE code? 

Who makes the LCD display? 

Is it the common HD44780 model?

 

If the code in POST#17 is not the entire application - then upload the .c and .h file(s) so they can be dissected.  Otherwise this is like trying to herd cats.

 

 

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

Dear Jim thank you for your attention.

This is my schematic.(sorry its a bit messy!)

And yes that is(#17) my code complete. 

LCD is just normal 16x2

Last Edited: Sat. Mar 4, 2017 - 11:00 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Teh schematic did not upload

 

If thats your entire code in post #17 to run the screen I think your problem is your code as it's nowhere near complete.

 

i suggest you read the following guide:

 

https://www.bipom.com/documents/...

 

It explains on page #4 the sequence of commands and the delays between those commands you need to follow.

 

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

Apart from the point David made ("why bother?") I'm wondering why anyone would bother to write the HD44780 part of this from scratch? The Internet is full of any number of existing codes for 16x2 LCDs. Get one of those and forget the 595 for the time being. Just start by wiring an HD44780 direct to the AVR. Again I'm not sure why anyone would choose to use 8bit when 4bit is just fine but most existing libraries will support both 4 or 8 so wire it with either. Meanwhile in a separate project work on the 595 stuff. Just ensure that you can light any combination of LEDs (say) on the output pins. Finally put the two "proven" pieces of work together. Moving the final IO driving of the LCD to route through the 595 instead. If you try to do it the way you are at the moment you have too many unknowns to be able to locate where faults may lie.

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

Dear Jim and clason.

Thanks for your quidence .I think I should study a bit more to understand your points.

Meanwhile pray for me.

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

clawson wrote:
I'm wondering why anyone would bother to write the HD44780 part of this from scratch?

Indeed, which got me thinking(uh oh)....

 

Way back in the day I worked at ADEMCO a Home/commercial burglar alarm manufacturer, and I remember they used a '595 to drive their 16x2 LCD and 4 lines from a National Semi HPC, or COP micro.  I happen to have an old keypad and looked at how it was set up which was run the LCD in 4 bit mode with the RS, R/W and 4 data lines connected to the '595, and a port pin as the E line.  I see no reason why one couldn't modify Peter Fleury's LCD library, which is already in four bit mode to send the output, not to a PORT, but to the SPI engine.  THe trick is modifying the parts that call out the actual port and the port pins, but it can be done as Davide Gironi has an I2C version of Fleury's library.

 

Basically the /SS, SCK, and MOSI get tied to the '595, and then you use the fourth line as your E for the LCD.

 

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

azizollah wrote:
The other fact is I have a pcb already made

Then Please post a picture of the board!!!

 

Click Link: Get Free Stock: Retire early! PM for strategy

share.robinhood.com/jamesc3274
get $5 free gold/silver https://www.onegold.com/join/713...

 

 

 

 

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

here you are .a pic for you. 

Attachment(s): 

Last Edited: Mon. Mar 6, 2017 - 09:26 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

azizollah wrote:
here you are a picture for you

Picture is missing.

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

Do you know the meaning of bypass caps? If not you may want to google that. Maybe they are under the board??

John Samperi

Ampertronics Pty. Ltd.

www.ampertronics.com.au

* Electronic Design * Custom Products * Contract Assembly

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

Yes dear I know and its there .I have reached an stage where I can see the data coming to LCD (by placing led and resistor in place of lcd).but when lcd is placed nothing is shown!

where is Bug!

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

You seem to be using Codevision for you compiler?

 

One of the reason not many people are able to help is that no one here has the hardware you have, but have another look at post #35 above.

 

You MUST use the correct timing and sequence of commands to initialise the LCD or it will never work.

 

Now in post 13 above you have a solution to test your hardware, once that works then change it the way you want once you understand what's going on, both in hardware and software.

John Samperi

Ampertronics Pty. Ltd.

www.ampertronics.com.au

* Electronic Design * Custom Products * Contract Assembly

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

Post a schematic. No way anyone is going to figure that picture out

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

This thread is dragging on way too long and we don't seem to be getting anywhere.

The assumption is that there is only one problem - there are probably many.

Here's some of the things I can see (others have mentioned some of these as well):

1. the construction -we can't see any bypass caps

2. ribbon cable used for high speed signals - you get crosstalk between wires and software delays aren't going to cure it.

3. startup delay - the lcd takes some time to start up - if you talk to it before it has started, then things won't happen.

4. random delays. Sit down and plan the system.

5. work from known good code

6. work from a known good hardware setup

 

Throwing up your hands and thinking that the problem is software then expecting us to magically solve it for you is folly. You can ask for divine intervention, but this is a man made problem - so man has to fix it.

Note: your circuit is built on dot board not a pcb.

Last Edited: Tue. Mar 7, 2017 - 02:44 AM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

azizollah wrote:
please c code in codevision only!

 

Since the OP is using a Mega32 I am guessing he paid for a copy of CV as the freeware version is limited to 4Kb according to the CV website.

 

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

azizollah wrote:

I have reached an stage where I can see the data coming to LCD (by placing led and resistor in place of lcd).but when lcd is placed nothing is shown!

where is Bug!

Please note that I use codevision and 4k is no limit .I think initialization of lcd is my problem.

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

Well I ordered some HC595's on Monday and arrived today.  Sat down to write this out and Realised that using the '595 is a huge waste of time!  I found an Arduino 'library'/sketch and looked at what they did and in 4 bit mode using the 595 to control everything it will take three transmissions in order to send one nibble of data or 6 transmissions per byte.

 

This is based on a three wire connection to the AVR

 

SCK - Serial data shift clock

SDAT - Serial DAta

RCLK - The storage registers clock

 

Adding a fourth line to handle the E pin on the LCD removes one transmission.

 

So, we have a picture of your setup, but no schematic as there is nothing that can be decoded from the picture other than its not a permanent PC board.

 

A schematic showing your connections is certainly a must.

 

JIm

 

EDIT:

Just remembered that the OP wants to use 8bit mode so the only savings in all of this would be one pin.  That makes life a little easier but instead of a software waste it's hardware

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: Wed. Mar 8, 2017 - 11:41 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

You must be bored like me. wink

John Samperi

Ampertronics Pty. Ltd.

www.ampertronics.com.au

* Electronic Design * Custom Products * Contract Assembly

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

Same urologist?

 

Ross McKenzie ValuSoft Melbourne Australia

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

No, poked in the eye this time with replacement a plastic bit..just like the million dollar man but cheaper.

John Samperi

Ampertronics Pty. Ltd.

www.ampertronics.com.au

* Electronic Design * Custom Products * Contract Assembly

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

js wrote:
You must be bored like me. wink

No jobs that pay decent on the desk so I have some time sadly.

 

I actually started thinking about how we did it at the alarm company back in the 80's and wanted to see if I could remember the signal lines and the protocol.  I am 90% sure we used 4 lines as I can remember the waveforms on the scope screens like it was yesterday......now where are my glasses? cool

 

Question I ask myself is should I bother?  The 10 pieces I bought were less than $4.00 so I am not out anything other than a cup of overpriced coffee.  It might be an accomplishment to write a driver as a self teach to finally learn how to use CodeVision for a project as I paid for the license, but only use it for configurations.

 

Why bother when I have a bunch of I2C LCD backpacks I had made using the PCF8754 which work great with Davide Gironi's adaptation of Peter Fleury's code and you only need TWO lines?  Not four like the '595 needs.

 

I shall debate this while on line getting a $2.00 cup of tea...wink

 

Meh...

 

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

You buy your $2 cup of tea online? Does it arrive hot?

 

Ross McKenzie ValuSoft Melbourne Australia

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

valusoft wrote:

You buy your $2 cup of tea online? Does it arrive hot?

 

As long as I don't order it FedEx!

 

Not going to hijack the OP's thread.

 

JIm

 

EDIT:  Just figured out the tongue in cheek you were insinuating Ross!  Good one

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. Mar 9, 2017 - 01:42 AM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

david.prentice wrote:
This seems a rather pointless exercise: 1. 3 pins for RS, RW, EN and 3 pins for HC595_SH_CP_POS, HC595_ST_CP_POS, HC595_DS_POS 2. a regular 4-bit LCD library only uses 6 pins (if you are write-only)
jgmdesign wrote:
Sat down to write this out and Realised that using the '595 is a huge waste of time!
clawson wrote:
Apart from the point David made ("why bother?")
Sooner or later the message will get through. Exactly what point is there in putting a 595 into this?

 

But if one is going to attempt it then I would take a lot of notice of:

Kartman wrote:
The assumption is that there is only one problem - there are probably many.

Which is why I said:

clawson wrote:
Just start by wiring an HD44780 direct to the AVR. Again I'm not sure why anyone would choose to use 8bit when 4bit is just fine but most existing libraries will support both 4 or 8 so wire it with either. Meanwhile in a separate project work on the 595 stuff. Just ensure that you can light any combination of LEDs (say) on the output pins. Finally put the two "proven" pieces of work together.
The way to find the faults in a complex system is to break it down into easily manageable/testable parts and ensure each small part is working OK. When you have proven each small part THEN put them together to build the larger/complex system.

If you hang the HD44780 directly off the 595 in step 1 and the whole thing "does not work" you have no idea whether it is in the HD44780 part of the 595 part or, worse yet. BOTH where the problems are located.

 

So develop each in turn separately and only put the "building blocks" together when each part is proven.

 

As I've said you can start by getting an LCD connected directly to the AVR to work. The "output" of that module is simply code that "wiggles" 4/8 data bits and 2/3 control signals. Later you can move the generation of those signals from direct port pin usage e.g. PORTB |= (1 << LCD_RW) to Shift_595_setoutput_bit(LCD_RW) or whatever.

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

I have not been following this thread recently.

 

From the code in #17 the idea could work but it is complicated.

Looking at your photo in #40,  it seems that this is a home-made project.

 

You have only got to use 6 GPIO pins to drive the LCD.   Codevision has already got < alcd.h> library and a GUI to configure it.

 

Incidentally,   I wrote a Codevision library when your colleague first suggested a HC595.   And I made a plug-in Adapter for the LCD.

My library uses 3 pins and the SPI bus.   The I2C version uses 2 pins and the I2C bus.   The bit-banged I2C version uses any pins.

 

I can not see any advantage in HC595 via SPI over PCF8574 via I2C.   3 pins against 2 pins.

Your method is quite possible but uses an awful lot of pins.

 

David.

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

david.prentice wrote:
My library uses 3 pins and the SPI bus.

Theres an Arduino example that also does this.  From what I saw it would appear that for each nibble you need to send three transactions with the E line control connected to the 595.  Send nibble with E line low to set up the data outputs, send the same nibble but with the E bit high, send the same nibble a third time with E bit low.  Lot of traffic.

 

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

Yes,  it is exactly the same as the PCF8574.   You simply wiggle the bits on the Port Expander.   It is 5 states per transaction.

Remember that I have a 4-bit data bus.

uint8_t IFACE_WRITESEQ(uint8_t slave, uint8_t *seq, uint8_t n)
{
    uint8_t i, ret = 0;
    for (i = 0; i < n; i++) {  // 5 states @ 1MHz = 40us
        HC595_CSLO;
        spi(seq[i]);
        HC595_CSHI;
    }
    delay_us(40);
    return ret;
}

bit-bash I2C:

uint8_t IFACE_WRITESEQ(uint8_t slave, uint8_t *seq, uint8_t n)
{
    uint8_t ret = 1;
    if (i2c_start() && i2c_write(slave << 1)) {
        uint8_t i;
        for (i = 0; i < n; i++)
            i2c_write(seq[i]);
        ret = 0;
    }
    i2c_stop();
    return ret;
}

and TWI:

#define IFACE_WRITESEQ(slave, buf, n)  twi_master_trans(slave, buf, n, 0, 0)

You can see that the TWI version is a lot simpler.

And the sequence is not difficult either:

    seq[0] = mode;                      // EN=0, RW=0, RS=mode
    seq[1] = (c & 0xF0) | mode | 4;     // EN=1, RW=0, RS=mode
    seq[2] = seq[1] & ~4;               // EN=0, RW=0, RS=mode
    seq[3] = (c << 4) | mode | 4;       // EN=1, RW=0, RS=mode
    seq[4] = seq[3] & ~4;               // EN=0, RW=0, RS=mode

Of course,  the OP's method of an 8-bit data bus on the Expander with the 3 separate control lines is simple to program but eats an awful lot of GPIO pins.

 

David.

Last Edited: Thu. Mar 9, 2017 - 03:53 PM