| ??? 08/05/11 12:20 Read: times |
#183216 - delayRS() Responding to: ???'s previous message |
how long is that delayRS?
If==halfbit( i suppose this from function rec_byte) , then Your sender produces too short start and stop bits. If==onebit , then Your receiver "rec_byte" is not very precise; See code for additional comments. regards
void send_byte(unsigned char x)
{
unsigned char i;
RCAP2L = TL833;
RCAP2H = TH833;
TL2 = TL833;
TH2 = TH833;
dat = x;
TX = 0;
???????????
delayRS();
for(i=0;i<8;i++)
{
TX = out;
delayRS();
dat = dat >> 1;
}
TX = 1;
?????????????????
delayRS();
}
// RX function
void rec_byte(unsigned char *x)
{
unsigned char i;
bit t=1;
//T2CON = 0x00;
RCAP2L = TL416;
RCAP2H = TH416;
TL2 = TL416;
TH2 = TH416;
din = 0;
waitagain: //?????????
while(RX == 1);
// check in the middle of start bit!!!!!!!
delayRS() ;//half bit
if (RX==1) goto waitagain; //????????
?????????????
delayRS();delayRS();delayRS(); // 1.5 bit delay
for(i=0;i<8;i++)
{
in = RX; //sample bit
din = din << 1;
delayRS();delayRS(); // 1 bit delay
}
*x = din;
//?????????
delayRS();
//here You can check validity of stop bit!!!
}
void main()
{
unsigned char i,send[]="SEND A CHARACTERn�15",rec[]="character recieved:";
unsigned char input='0';
TX = 1;
T2CON = 0x00;
RCAP2L = TL833;
RCAP2H = TH833;
TL2 = TL833;
TH2 = TH833;
while(1)
{
while(send[i])
{
send_byte(send[i++]);
//delay1us(400);
}
i=0;
rec_byte(&input);
while(rec[i])
{
send_byte(rec[i++]);
delay1us(50); //????????? too short pause
// allowed, but too short
// make delayRS()
}
send_byte(input);
i=0;
}
}
|



