Email: Password: Remember Me | Create Account (Free)

Back to Subject List

Old thread has been locked -- no new posts accepted in this thread
???
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 CHARACTERn15",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...


List of 30 messages in thread
TopicAuthorDate
bit banging program touble            01/01/70 00:00      
   why?            01/01/70 00:00      
      i need a second serial port            01/01/70 00:00      
         something like this , without any warranty :            01/01/70 00:00      
         a good start would be ...            01/01/70 00:00      
            only 3 'U's are commingout of 100            01/01/70 00:00      
               Separate the characters and look with scope            01/01/70 00:00      
                  finally it worked            01/01/70 00:00      
                     uart receiver in software            01/01/70 00:00      
   No I/O or No Timing            01/01/70 00:00      
      "No I/O or No Timing"            01/01/70 00:00      
   Someday you will learn...            01/01/70 00:00      
      this isnt the actual code            01/01/70 00:00      
         Well then another lesson to learn...            01/01/70 00:00      
   Assembler Manual will help you            01/01/70 00:00      
      assembler manual?            01/01/70 00:00      
   Data is 8 Bit??            01/01/70 00:00      
   Bit width timing and timer TH0,TL0 Values            01/01/70 00:00      
      checked values for TH0 and TL0            01/01/70 00:00      
         keil baud rate Calculator not for bit bang            01/01/70 00:00      
   LSB first            01/01/70 00:00      
   now reception....            01/01/70 00:00      
      1) din = din >> 1            01/01/70 00:00      
         working at 1200 baud            01/01/70 00:00      
            delayRS()            01/01/70 00:00      
               why do i have to sample stop bit            01/01/70 00:00      
                  Need not, but should            01/01/70 00:00      
                  because            01/01/70 00:00      
                     Much to a real UART            01/01/70 00:00      
                  1.5 bit delay            01/01/70 00:00      

Back to Subject List