mattycha
Newbie level 5
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.
I appreciate any help that I can get.
Thanks!!
p.s. I am using C18.
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;
}
Thanks!!
p.s. I am using C18.