interfacing 74595 to 16x2 lcd in 8 bit mode

#4925740
Rate this post
useful
not useful
Look, the information you're providing is extremely sparse. It is almost 
impossible to help.

Nobody knows anything about the code you are running on the your atmega.
How do you expect anybody to be able to say something about software 
then?

Also: are you having a data signal to the 74xx595 data in (pin 14) now?
Your "schematic" doesn't show it, and you didn't confirm so far.

It would be good if you start debugging on your side, like attaching a 
scope or logic analyser and measuring some of the key signals (clk, 
data, cs).

Another possibility is that there is a difference in the wiring between 
the working system and the new one (wrong/missing signal connection). 
Please verify.
OP #4926238
Rate this post
useful
not useful
Ok let me forward the code for your inspection.

(This code is written for a separate set up on bread board.)
I must apologize to you for bothering you on 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 
));
   DDRA=0xff;
}


//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
   PORTA.5=1;
   delay_ms(20);
   //HC595_PORT&=(~(1<<HC595_SH_CP_POS));//LOW
   PORTA.5=0;

}

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

   //HC595_PORT|=(1<<HC595_ST_CP_POS);//HIGH
   PORTA.6=1;
   delay_ms(10);
   PORTA.6=0;
   //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();
         PORTA.4=1;
         delay_ms(1000);
      }
      else
      {
         //MSB is 0 so output high
         //HC595DataLow();
         PORTA.4=0;
         delay_ms(1000);
      }

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

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

/*

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;

    PORTA.7=0; //pin 13 595
  PORTA.1=0;   //w/r lcd
  PORTA.3=0;   //v0 lcd
  delay_ms(1000);
   HC595Init();
  // LCD init
   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(100);
   rs=0;rw=0;en=0;
   delay_ms(200);
    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(100);
   rs=0;rw=0;en=0;
   delay_ms(20);
    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(100);
   rs=0;rw=0;en=0;
   delay_ms(200);

   HC595Write(0x0f);   //Write the data to HC595
         Wait();                 //Wait

  rs=0;rw=0;en=1; // RS and RW as LOW and EN as HIGH
    delay_ms(100);
   rs=0;rw=0;en=0;
   delay_ms(200);
//  HC595Write(0x0f);   //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.3=0;  // back light on/off
    delay_ms(1000);
         rs=1;rw=0;en=1; // RS and RW as LOW and EN as HIGH
    delay_ms(100);
         HC595Write(0b01010101) ; //Write the data to HC595
         Wait();                 //Wait

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

   rs=1;rw=0;en=0;
   delay_ms(200);

//     rs=1;rw=0;en=1; // RS and RW as LOW and EN as HIGH
//    delay_ms(1000);
//         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(0xff) ;   //Write the data to HC595
//         Wait();                 //Wait
//
//   rs=1;rw=0;en=0;
//   delay_ms(20);
     PORTA.3=0;
    delay_ms(1000);


   }


}

Reply

Please log in before posting.

or

Log in with Google account

Registration is free and takes only a minute.

Register now