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.

PIC18f4550 interface with EEPROM 93c56 using SPI

Status
Not open for further replies.

sandippatelec

Newbie level 2
Joined
Sep 21, 2011
Messages
2
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,281
Location
Surat,Gujarat
Activity points
1,302
Hi,
I am trying to interface AT93c56 EEPROM to 18F4550.i'm using MCC18 compiler. The EEPROM is wired for x8 configuration. The Problem with it is
Every time I read EEPROM it returns 0xff only.
My code is as below..
If any one knows the solution plz Help me..

#include<p18f4550.h>
#include<spi.h>

#define READ 0xc0 /* 1 10 A8 A7A6A5A4 A3A2A1A0 */
#define EWEN 0x98 /* 1 001 1XXX XXXX */
#define WRITE 0xa0 /* 1 01 A8 A7A6A5A4 A3A2A1A0 */

//#define READ 0x06 /* 1 10 A8 A7A6A5A4 A3A2A1A0 */
//#define EWEN 0x13 /* 1 001 1XXX XXXX */
//#define WRITE 0x05 /* 1 01 A8 A7A6A5A4 A3A2A1A0 */


#define lcd_data PORTD
#define RS PORTEbits.RE0
#define EN PORTEbits.RE1

#define CS PORTAbits.RA5

void msdelay(unsigned int y)
{
unsigned int x;
T0CON = 0x00;
for(x=0;x<y;x++)
{
TMR0H = 0xF6;
TMR0L = 0x3C;
T0CONbits.TMR0ON = 1;
while(INTCONbits.TMR0IF == 0);
INTCONbits.TMR0IF = 0;
T0CONbits.TMR0ON = 0;
}

}
void command(unsigned char z)
{
RS=0;
EN=1;
lcd_data = z;
EN=0;
msdelay(200);

}

void print(unsigned char y)
{
RS=1;
EN=1;
lcd_data = y;
EN=0;
msdelay(100);

}

void main()
{
unsigned char x;
ADCON1 = 0x0f;

TRISB = 0x01;
TRISC = 0x00;
TRISA = 0x00;

TRISE = 0x00;
TRISD = 0x00;

command(0x38);
command(0x0C);
command(0x01);
command(0x06);

OpenSPI(SPI_FOSC_64,MODE_00,SMPMID);

CS = 1;
msdelay(5);
WriteSPI(EWEN);
msdelay(10);
CS = 0;

msdelay(10);

CS = 1;
msdelay(5);

WriteSPI(WRITE);
msdelay(5);

WriteSPI(0x00);
msdelay(5);
WriteSPI(0x50);
msdelay(5);

WriteSPI('R');
msdelay(5);
CS = 0;

msdelay(20);

CS = 1;
msdelay(5);

WriteSPI(READ);
msdelay(5);

WriteSPI(0x00);
msdelay(5);
WriteSPI(0x50);
msdelay(5);

x = getcSPI();
msdelay(5);
print(x);
CS = 0;
msdelay(5);

while(1);
}
 

What about the SK speed? Is that conform the Datasheet?
 

I'm using 20 Mhz..
i have select F0sc/64..
This code is working properly on Proteus But its not working on Hardware..

The main program execution didn't come out from Read function..
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top