Email: Password: Remember Me | Create Account (Free)

Back to Subject List

Old thread has been locked -- no new posts accepted in this thread
???
03/28/09 06:42
Read: times


 
#163918 - INTERFACING AT93C46A (EEPROM)WITH P89V51RB2 controller
Hi all, I am INTERFACING AT93C46A WITH P89V51RB2 controller, but it is not working while watching result on c.r.o,same signal showing while writing any data ffff,0000,aaaa etc and then reading it from miso pin.
I am posting my code
# include<SFR8032.H>
# include <stdio.h>

# define READ 0x01 // 0x03 // changed from c0
# define WRITE 0x01 //0x02 // changed from a0 //AGAIN CHANGE FROM 05

# define ERASE 0x03
//# define ERAL 0x90
//# define WRAL 0x88
//# define EWDS 0x80
unsigned char spi_insert( unsigned char data1);
void init_spi();
void delay_ms1(unsigned int Delval_ms);
void delay1(unsigned char Delval);
void write_spi(unsigned int dat , unsigned char address); //change from unsigned char dat
void erase_spi(unsigned char address);
unsigned char read_spi(unsigned char address);
void erasewriteenable_spi();
void eraseall_spi();
void writeall_spi(unsigned int ); //change from unsignedc char
unsigned char read_data = 0x00;
unsigned char read_data1 = 0x00;





void init_spi()
{
P11 = 1;
P15 = 1;
P16 = 1;
SPCTL = 0xDD;
SPCFG = 0x00;
delay_ms1(10);
P11 = 0;

}
//DELAY FUNCTIONS
//delay(10) = 200usec.


void erasewriteenable_spi()
{ // P22 = 1;
P11 = 1;
spi_insert(0x01);
spi_insert(0x30); // Make sure CS is high
//spi_insert( 0x02);

}

void delay1(unsigned char Delval)
{
unsigned char i=25;
for(;Delval!=0;Delval--)
for(;i!=0;i--);
}


void delay_ms1(unsigned int Delval_ms)
{
for(;Delval_ms!=0;Delval_ms--)
{
delay1(250);
delay1(250);
delay1(250);
delay1(250);
}
}


unsigned char spi_insert( unsigned char data1)
{
SPDAT = data1;
while(!(SPCFG & 0x80));
SPCFG = 0x00;
read_data = SPDAT;


return(read_data);
}





void write_spi(unsigned int dat , unsigned char address) //changed from unsigned char dat
{ unsigned char cat;
P11 = 1;
spi_insert(WRITE);
/* address /= 0x80; //added use this for 8 bit mode
spi_insert(address);
spi_insert(dat);*/
address &=0x7f;
address |=0x40;
spi_insert(address);
cat = dat & 0x00FF;
spi_insert(cat);
dat = dat >> 8;
cat = dat & 0x00FF;
spi_insert(cat);
P11=0;

delay_ms1(10);

P11 = 1;
while(P16!= 1);
P11=0;
/*
delay_ms1(15);
P11 = 1;
while(P16 != 1); */ }


unsigned char read_spi(unsigned char address)
{
P11 = 1;
spi_insert(READ);
address |=0x80;
address &=0xBF;
read_data1=spi_insert(address);
read_data1=spi_insert(0x00);

P11 = 0;
return(read_data1);
}



void erase_spi(unsigned char address)
{ P11 = 1;
spi_insert(ERASE);
address /= 0x80;
spi_insert(address);
P11 = 0;
delay_ms1(10);
}




void eraseall_spi()
{
P11 = 1;
spi_insert(0x01);
spi_insert(0x20);
P11 = 0;
delay_ms1(10);
}


void writeall_spi(unsigned int dat)
{ unsigned char cat;
P11 = 1;
spi_insert(0x01);
spi_insert(0x10);
cat = dat & 0x00FF;
spi_insert(cat);
dat = dat>>8;
cat = dat & 0xFF00;
spi_insert(cat);
P11 =0;
delay_ms1(15);
P11 = 1;
while(P16 !=1);
P11 = 0;
}
//delay_ms1(10);



void erasewritedisable_spi()
{ P11 = 1;
spi_insert(EWDS);
P11 = 0;
delay_ms1(10);
}

List of 2 messages in thread
TopicAuthorDate
INTERFACING AT93C46A (EEPROM)WITH P89V51RB2 controller            01/01/70 00:00      
   Duplicate thread            01/01/70 00:00      

Back to Subject List