sv_shady
Joined: 07 Mar 2008 Posts: 28
|
EEPROM 93C56 16bit support |
Posted: Tue Apr 29, 2008 12:25 pm |
|
|
This is an enhanced 9356.c file which supports EEPROM Disable Function and 16bit mode of organizing eeprom memory. It is extensively tested and it works fine.
Code: |
#define EEPROM_SELECT PIN_C7
#define EEPROM_CLK PIN_C6
#define EEPROM_DI PIN_C5
#define EEPROM_DO PIN_C4
#define EEPROM_SIZE 256
void Enable_ext_EEPROM()
{
int cmd[2];
int i;
output_low(EEPROM_DI);
output_low(EEPROM_CLK);
output_low(EEPROM_SELECT);
cmd[0]=0x80;
cmd[1]=0x9;
for(i=1;i<=4;++i)
shift_left(cmd,2,0);
output_high(EEPROM_SELECT);
for(i=1;i<=12;++i)
{
output_bit(EEPROM_DI, shift_left(cmd,2,0));
output_high(EEPROM_CLK);
output_low(EEPROM_CLK);
}
output_low(EEPROM_DI);
output_low(EEPROM_SELECT);
}
void Disable_ext_EEPROM()
{
int cmd[2];
int i;
output_low(EEPROM_DI);
output_low(EEPROM_CLK);
output_low(EEPROM_SELECT);
cmd[0]=0x00;
cmd[1]=0x08;
for(i=1;i<=4;++i)
shift_left(cmd,2,0);
output_high(EEPROM_SELECT);
for(i=1;i<=12;++i)
{
output_bit(EEPROM_DI, shift_left(cmd,2,0));
output_high(EEPROM_CLK);
output_low(EEPROM_CLK);
}
output_low(EEPROM_DI);
output_low(EEPROM_SELECT);
}
void write_ext_eeprom(int address, int data)
{
int cmd[3];
int i;
cmd[0]=data;
cmd[1]=address;
cmd[2]=0xa;
for(i=1;i<=4;++i)
shift_left(cmd,3,0);
output_high(EEPROM_SELECT);
for(i=1;i<=20;++i)
{
output_bit(EEPROM_DI, shift_left(cmd,3,0));
output_high(EEPROM_CLK);
output_low(EEPROM_CLK);
}
output_low(EEPROM_DI);
output_low(EEPROM_SELECT);
delay_ms(11);
}
void write_ext_eeprom16(int address, int16 data)
{
int16 cmd[2];
int i, code;
code = 0x05;
cmd[0] = data;
cmd[1] = make16(code, address);
for(i=1;i<=5;++i)
shift_left(cmd,4,0);
output_high(EEPROM_SELECT);
for(i=1;i<=27;++i)
{
output_bit(EEPROM_DI, shift_left(cmd,4,0));
output_high(EEPROM_CLK);
output_low(EEPROM_CLK);
}
output_low(EEPROM_DI);
output_low(EEPROM_SELECT);
delay_ms(11);
}
int read_ext_eeprom(int address)
{
int cmd[3];
int i,data;
cmd[0]=0;
cmd[1]=address;
cmd[2]=0xc;
for(i=1;i<=4;++i)
shift_left(cmd,3,0);
output_high(EEPROM_SELECT);
for(i=1;i<=20;++i)
{
output_bit(EEPROM_DI, shift_left(cmd,3,0));
output_high(EEPROM_CLK);
output_low(EEPROM_CLK);
if(i>12)
shift_left(&data,1,input(EEPROM_DO));
}
output_low(EEPROM_SELECT);
return(data);
}
int16 read_ext_eeprom16(int address)
{
int16 cmd[2], data;
int i, code;
code = 0x06;
cmd[0] = 0;
cmd[1] = make16(code, address);
for(i=1;i<=5;++i)
shift_left(cmd,4,0);
output_high(EEPROM_SELECT);
for(i=1;i<=27;++i)
{
output_bit(EEPROM_DI, shift_left(cmd,4,0));
output_high(EEPROM_CLK);
output_low(EEPROM_CLK);
if(i>11)
shift_left(&data,2,input(EEPROM_DO));
}
output_low(EEPROM_SELECT);
return(data);
} |
|
|