| ??? 08/04/11 13:56 Modified: 08/04/11 13:59 Read: times |
#183196 - now reception.... Responding to: ???'s previous message |
this is the code i wrote for reception...
but as you all can guess it isn't working #include <reg52.h>
#include <intrins.h>
#define TH833 0xFD //1200 baud
#define TL833 0x07
#define TH416 0xFE //2400 baud
#define TL416 0x87
#define TH208 0xFF //4800 baud
#define TL208 0x48
#define TH104 0xFF //9600 baud
#define TL104 0xA8
unsigned char bdata dat;
unsigned char bdata din;
sbit TX = P3^1;
sbit RX = P3^0;
sbit out = dat^0;
sbit in = din^7;
void delay1us(unsigned int x)
{
for(x;x!=0;x--)
_nop_();
}
void delayRS()
{
TR2 = 1;
while(!TF2);
TR2 = 0;
TF2 = 0;
}
// TX function
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;
while(RX == 1);
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();
}
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);
}
send_byte(input);
i=0;
}
}
and i dont know where to start checking... |



