/******* PC Read one byte from MCU51 ******************/
char ReadDataByte(void)
{
char ch=0;
outportb(SPP_CONTROL, 0x24); //Dir=1, Read.
outportb(SPP_CONTROL, inportb(SPP_CONTROL)|0x01); //nWrite=1, is Read.
while(inportb(SPP_STATUS)&0x80);//Wait for nWait=0; bit 8
outportb(SPP_CONTROL, inportb(SPP_CONTROL)& 0xFD);//nDATASTB=0,Ask device to read.
//Host waits for Acknowledgment by nWait going high
while(!((inportb(SPP_STATUS))&0x80));//nWait=1, go out
ch = inportb(EPP_DATA);//Read data
outportb(SPP_CONTROL, (inportb(SPP_CONTROL)|0x02));//nDATASTB=1,Read Finished.
return ch;
}
char ReadAddr(void)
{
char ch=0;
outportb(SPP_CONTROL, 0x24); //Dir=1, Read.
outportb(SPP_CONTROL, inportb(SPP_CONTROL)|0x01); //nWrite=1, is Read.
while(inportb(SPP_STATUS)&0x80);//Wait for nWait=0; bit 8
outportb(SPP_CONTROL, inportb(SPP_CONTROL)& 0xF7);//nADDRSTB=0,Ask device to read.
while(!((inportb(SPP_STATUS))&0x80));//nWait=1, go out
ch = inportb(EPP_ADDR);//读数
outportb(SPP_CONTROL, (inportb(SPP_CONTROL)|0x08));//nADDRSTB=1,Read Finished.
return ch;
}