|
#include
#include
#define _Nop() _nop_()
sbit BT_SND =P3^6;
sbit BT_REC =P3^7;
//9600BPS 11.0592M
void Delay1Bit()
{
unsigned char i;
for(i=36;i>0;i--);
_Nop();
}
void DelayHfBit()
{
unsigned char i;
for(i=15;i>0;i--);
}
/*
//19200BPS
void Delay1Bit()
{
unsigned char i;
for(i=12;i>0;i--);
_Nop();
}
void DelayHfBit()
{
unsigned char i;
for(i=3;i>0;i--);
}
*/
//
void PSendChar(unsigned char inch)
{
unsigned char ii;
ii=0;
BT_SND=0; //start bit
_Nop();
_Nop();
_Nop();
_Nop();
_Nop();
_Nop();
_Nop();
_Nop();
Delay1Bit();
while(ii<8)
{
if(inch&1)
{
BT_SND=1;
}
else
{
BT_SND=0;
_Nop();
_Nop();
}
Delay1Bit();
ii++;
inch>>=1;
}
BT_SND=1;
Delay1Bit();
}
//
unsigned char PGetChar()
{
unsigned char rch,ii;
ii=0;
rch=0;
Delay1Bit();
while(ii<8)
{
rch>>=1;
if(BT_REC)
{
rch|=0x80;
}
ii++;
Delay1Bit();
}
DelayHfBit();
return rch;
}
bit StartBitOn()
{
return (BT_REC==0);
}
|
|