// 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);
}
// 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();
}
unsigned char ReadChar(unsigned char address) {
unsigned char temp=address>>1;
if(address&0x01) return((unsigned char)(Read_data(temp)>>8));
else return((unsigned char)(Read_data(temp)));
}
void WriteChar(unsigned char address,unsigned char InData) {
unsigned char temp=address>>1;
if(address&0x01) Write_data(temp,(unsigned int)(Read_data(temp)
&0x00ff|(InData<<8)));
else Write_data(temp,(unsigned int)(Read_data(temp)&0xff00|InData));
}
XBYTE[0x304d]=0x25; //port 1 add time slot
XBYTE[0x307d]=0x45; //port 2 add time slot
XBYTE[0x30ad]=0x65; //port 3 add time slot
XBYTE[0x30dd]=0x29; //port 4 add time slot
这样能看到我外围应用片子正常工作,但该为:
WriteChar(0x00,0x25) ;
WriteChar(0x01,0x45) ;
WriteChar(0x02,0x65) ;
WriteChar(0x03,0x29) ;
WriteChar(0x04,0x25) ;
WriteChar(0x05,0x45) ;
WriteChar(0x06,0x65) ;
WriteChar(0x07,0x29) ;
XBYTE[0x304c]=ReadChar(0x00) ; //port 1 drop time slot
XBYTE[0x307c]=ReadChar(0x01) ; //port 2 drop time slot
XBYTE[0x30ac]=ReadChar(0x02) ; //port 3 drop time slot
XBYTE[0x30dc]=ReadChar(0x03) ; //port 4 drop time slot
XBYTE[0x304d]=ReadChar(0x04) ; //port 1 add time slot
XBYTE[0x307d]=ReadChar(0x05) ; //port 2 add time slot
XBYTE[0x30ad]=ReadChar(0x06) ; //port 3 add time slot
XBYTE[0x30dd]=ReadChar(0x07) ; //port 4 add time slot
就不行了,硬件连接不会有问题吧,就那么几个脚。
// 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();
}