| ??? 03/29/09 20:47 Read: times |
#163975 - formatted Responding to: ???'s previous message |
# 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);
}
|
| Topic | Author | Date |
| INTERFACING AT93C46A(EEPROM) WITH P89V51RB2 | 01/01/70 00:00 | |
| you have no idea ... | 01/01/70 00:00 | |
| Delay loops in 'C' (or any other HLL) | 01/01/70 00:00 | |
| How to post legible source code | 01/01/70 00:00 | |
| delay's functions are not that useful | 01/01/70 00:00 | |
| do it in ASM! | 01/01/70 00:00 | |
| what's wrong, exactly? | 01/01/70 00:00 | |
| MY FINDINGS AND HARDWARE CONFIG | 01/01/70 00:00 | |
| Can your device support a 16-bit write? | 01/01/70 00:00 | |
| not understood | 01/01/70 00:00 | |
| 16 bits or 9 bits? | 01/01/70 00:00 | |
| 8 bit controller,64*16 bit eeprom | 01/01/70 00:00 | |
| formatted | 01/01/70 00:00 | |
EEPROM | 01/01/70 00:00 |



