我修改了一下
// Write enable must precede all programming modes.
void Ewen(void) {
unsigned char temp,InData;
CS=0;
SK=0;
CS=1;
InData=0x98; // 10011XXXX
for(temp=9;temp!=0;temp--) { // 9
//DI=InData&0x80;
if((InData&0x80) == 0x80)
{
DI=1;
}else{
DI=0;
}
InData<<=1;
SK=1; //必要时加延时 SK=0; //必要时加延时
//InData<<=1;
}
CS=0;
//必要时加延时
}
//参造Ewen
// Disables all programming instructions.
void Ewds(void) {
unsigned char temp,InData;
CS=0;
SK=0;
CS=1;
InData=0x80; // 10000XXXX
for(temp=9;temp!=0;temp--) { // 9
DI=InData&0x80;
SK=1; SK=0;
InData<<=1;
}
CS=0;
}
// Reads data stored in memory, at specified address.
unsigned int Read_data(unsigned char address) {
unsigned char temp;
unsigned int result;
//Ewen();去掉
SK=0; DI=1; // 110 A5-A0
CS=0; CS=1;
SK=1; SK=0; //
address=address&0x3f|0x80;
for(temp=8;temp!=0;temp--) { // 8
DI=address&0x80;
SK=1; SK=0;
address<<=1;
}
DO=1;
for(temp=16;temp!=0;temp--) { // 16
SK=1;
result=(result<<1)|DO;
SK=0;
}
CS=0;
//去掉 Ewds();
return(result);
}
//参造Ewen
// Write_datas memory location An - A0.
void Write_data(unsigned char address,unsigned int InData) {
unsigned char temp;
Ewen();
SK=0; DI=1; // 101 A5-A0
CS=0; CS=1;
SK=1; SK=0; // 1
address=address&0x3f|0x40;
for(temp=8;temp!=0;temp--) { // 8
DI=address&0x80;
SK=1; SK=0;
address<<=1;
}
for(temp=16;temp!=0;temp--) { // 16
DI=InData&0x8000;
SK=1; SK=0;
InData<<=1;
}
CS=0; DO=1;
CS=1; SK=1;
while(DO==0) { // busy test
SK=0; SK=1;
}
SK=0; CS=0;
Ewds();
}
发表时间:2002年11月7日17:37:00