Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

Help me fix an error in code for 74HC595 connecting to LCD

Status
Not open for further replies.

mattycha

Newbie level 5
Joined
Aug 30, 2008
Messages
8
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,281
Activity points
1,343
Hi. I was going all over the internet to find an answer to my problem but I
couldn't find any so far. Some of you may have seen this in other forum. But
please understand me as I have tried so many things and asking many questions
but getting nowhere.

Then I came across this forum where there are many questions regarding on
74HC595 whereas other forums don't. So I am keeping my hopes high and
hopefully getting a solution to my problem.

What I am trying to do is that I do not have enough pins on my PIC18 so I want
to use 74HC595. Few has suggested to move on to other PIC which has more
I/O pins but I do not want to do that. Also using 74HC595 could be a good
learning experience for me.

I want to use 74HC595 to connect to LCD. I have set RS, RW, E pins for LCD and
have connected ST_CP, SH_CP, DS o 74HC595 correctly. Also, OE to GND and
MR to high. I think the problem is within my code but I cannot find anything
wrong with it. So could someone else please take a look at it? Maybe others can
pinpoint what and where it is wrong.

Code:
#include <p18f2455.h>
#include <delays.h>

#pragma config FOSC = HS
#pragma config WDT = OFF
#pragma config LVP = OFF
#pragma config BOR = OFF
#pragma config MCLRE = OFF

#define rs PORTBbits.RB2
#define rw PORTAbits.RA5
#define en PORTAbits.RA2		

#define DR PORTBbits.RB3   // connect it to pin 14 on 74HC595
#define SH_CP PORTBbits.RB6	// pin 11 on 74HC595
#define ST_CP PORTBbits.RB7	// pin 12 on 74HC595

void OutPORT(unsigned char data);
void sendData(unsigned char send); 
void writeData(unsigned char write); 
void writeString(const char rom *str); 
void READ(void);

void main(void)
{
	ADCON1 = 0xFF;
	// 74HC594
	TRISBbits.TRISB3 = 0;		// DR
	TRISBbits.TRISB6 = 0;		// SHCP
	TRISBbits.TRISB7 = 0;		// STCP

	 // LCD
                TRISBbits.TRISB2 = 0;
                TRISAbits.TRISA5 = 0;
                TRISAbits.TRISA2 = 0;
	rs = 0;
	rw = 0;
	en = 0;
	PORTB = 0;
	PORTA = 0;
	
	for(;;)
	{
		READ();
		writeString("Not working!!");
	}
}


void READ()
{
	Delay1KTCYx(250);          // Wait 20ms 
  	sendData(0x38);     
  	Delay1KTCYx(250);          // Wait 2ms 
  	sendData(0x0E);     // Turn LCD display off, cursor off and blinker off 
  	Delay1KTCYx(150);          // Wait 2ms 
  	sendData(0x01);     // Clear LCD display 
  	Delay1KTCYx(15);          // Wait 2ms 
  	sendData(0x06);       	
                Delay1KTCYx(15);         // Wait 2ms 
  	sendData(0x83); 			// start at line 1, position 3	
}

void sendData(unsigned char send) { 
        OutPORT(send);
        rs = 0; 
        rw = 0;
        en = 1; 
        Delay1KTCYx(1); 
        en = 0; 
} 

void writeData(unsigned char write) { 
        OutPORT(write); 
        rs = 1; 
        rw = 0;
        en = 1; 
        Delay1KTCYx(1); 
        en = 0; 
} 

void writeString(const char rom *str) { 
       while( *str ) { 
       writeData(*str); 
       str++;    
       } 
}

void OutPORT(unsigned char data) {
	unsigned char bits;
	for (bits=0x80; bits!=0; bits >> 1)
	{
		if ((bits & data) == bits)            // send DR
			DR = 1;
		else
			DR = 0;
		SH_CP = 1;			// clock SHCP
		SH_CP = 0;
	}
	ST_CP = 1;				// clock STCP
	ST_CP = 0;
}
I appreciate any help that I can get.
Thanks!!

p.s. I am using C18.
 

lcd with 74hc595

Hi,
You need to give LCD busy delay after command (83) and in between chrs in the string, or you could have included the delay in send/write routines after EN signal is brought low. As regards HC595, things appear OK. You clould have used a 4bit interface directly using shift, store and serdata signal pins and r/w pin always grounded.

Regards,
Laktronics
 

74hc595 & lcd

Strange... when I directly connected LCD to PIC, it worked fine without
delay line. Anyway, I did as you have suggested but still LCD wouldn't display
anything....

So you are sure that my inside my send/write function, there is no error in
calling outPORT function?
 

74hc595 lcd

Hi,
Yah, I could n't find anything else wrong.

Regards,
Laktronics

Added after 26 minutes:

Hi,
In the out port,for loop, it should have been bits=0?
Regards,
Laktronics
 

pic 74hc594

You mean this line?

Change this
Code:
if ((bits & data) == bits)
to
Code:
if ((bits & data) == 0)
??

I did that and it still do not work..... :cry:

Did anyone try to interface LCD with 74HC595 using C18??
 

Re: 74HC595

hm... strange... nothing seems to work....
shoot.... i'm getting really really fraustrated.....

please help.... someone....
 

Re: 74HC595

Hi mattycha.

Try this:

....
READ();
for(;;)
{
writeString("Not working!!");
}
...
In this way you initialize the LCD once.

....
void READ()
{
Delay1KTCYx(250); // Wait 20ms
sendData(0x38);
Delay1KTCYx(250); // Wait 2ms
sendData(0x0E); // Turn LCD display off, cursor off and blinker off
Delay1KTCYx(150); // Wait 2ms
sendData(0x06); // Sets mode to increment address by one
Delay1KTCYx(150); // Wait 2ms
sendData(0x01); // Clear LCD display
Delay1KTCYx(15); // Wait 2ms
sendData(0x06);
Delay1KTCYx(15); // Wait 2ms
sendData(0x83); // start at line 1, position 3
}
....

Are you using ICD2? Have you got a scope? If you have both, you can step the PIC and see if the outputs of the 74HC595 are as expected.

Luca.
 

Status
Not open for further replies.

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top