|
//******************************************************
void SoftRx232(){// Вызов в прерывании с частотой BR*SAMPLE.
//******************************************************
static bit OldBit,NewBit;
if(RxD){
if(S232.RxMjr < 3) S232.RxMjr++;
}else{
if(S232.RxMjr > 0) S232.RxMjr--;
}
NewBit = 0;
if(S232.RxMjr > 1) NewBit = 1;
if(OldBit != NewBit) S232.RxTick = 0;// Synchronisation.
if(S232.RxCnt == 0){// Idle
if(OldBit && !NewBit){// Start condition.
S232.RxCnt = 1;
}
}else if(S232.RxTick == (SAMPLE_FOR_BIT232 >> 1)){// Half Interval.
if(S232.RxCnt++ < 10){// Data bits.
S232.RxShift >>= 1;// Старт проходит насквозь.
if(NewBit) S232.RxShift |= 0x80;
}else{// Stop bit.
S232.RxFlag = 1;
S232.RxData = S232.RxShift;
S232.RxCnt = 0;
}
}
S232.RxTick = ++S232.RxTick % SAMPLE_FOR_BIT232;
OldBit = NewBit;
}
E-mail: info@telesys.ru