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

Back to Subject List

Old thread has been locked -- no new posts accepted in this thread
Manoz Joshi
08/31/05 01:39
Read: 976 times


 
#100318 - *Groan* Here is my inital code
Responding to: Dan Henry's previous message
Okay okay guy. I understand your point. I have developed my bit-banging code in C...

I intend to use 4200 Baud therefore 1/baud which yields 416uS.

When the start bit occurs, the first delay will be generated bitwidth/2 (208uS). The Interrupt Service Routine activates which repeats at 8 times for every 416us in order to capture the data bits because i want to detect the data bit in the middle of data bit'speriod.


Finally the delay is generated at twice time (208us + 208us = 416us) to check if the stop bit is 1 then the data bits (buffer_G) is placed in the P1...


#include <AT89X52.H>

#define INTERRUPT_Timer_2_Overflow 5
#define OUTPUT P1

void Timer_2_Init(void);
void hardware_delay_208us();

/* --------------------------------------------------------------- */

char buffer_G;
int i_G=0;
sbit DATA_RX = P3^2;

void main(void)
{
Timer_2_Init(); // Set up Timer 2
EA = 1; // Globally enable interrupts

while(1)
{
// Wait for Start bit
while(DATA_RX == 1)
{
}

//Delay (208uS)
hardware_delay_208us();

// Is it logic zero
if (DATA_RX == 0)
{

// Activate Interrupt Service Routine
ET2=1;
TR2=1;

// Wait for Interrupt Service Routine completes 8 times

while(i_G != 8)
{

}

// set i_G to be zero
i_G=0;


// Hardware delay 208 (Repeat twice to get 416us)
hardware_delay_208us();
hardware_delay_208us();


// Stop bit
if (DATA_RX != 1)
{
// Remove the content in buffer_G
buffer_G = buffer_G & 0x00;
}
else
{
OUTPUT = OUTPUT & buffer_G;
}
}

}
}

/* --------------------------------------------------------------- */

void Timer_2_Init(void)
{

T2CON = 0x04; // Load Timer 2 control register

TH2 = 0xFE; // Load Timer 2 high byte
RCAP2H = 0xFE; // Load Timer 2 reload capt. reg. high byte
TL2 = 0x6F; // Load Timer 2 low byte
RCAP2L = 0x6F; // Load Timer 2 reload capt. reg. low byte


ET2 = 0;
TR2 = 0;
}

/* --------------------------------------------------------------- */

void X(void) interrupt INTERRUPT_Timer_2_Overflow
{



i_G++;
if ( DATA_RX ==1)
{
buffer_G=(buffer_G & 0x80);
}
else
{
buffer_G=(buffer_G & 0x00);
}

// Shift the data to right at seven times
if (i_G<7)
{
buffer_G=buffer_G>>1;
}

if (i_G == 8)
{
//Disable Interrupt Service Routine
ET2=0;
TR2=0;
}
}

/* --------------------------------------------------------------- */

void hardware_delay_208us()
{
// Configure Timer 0 as a 16-bit timer
TMOD &= 0xF0; // Clear all TO bits (T1 left unchanged)
TMOD |= 0x01; // Set required TO bits(T1 left unchanged)

ET0=0;

// Value for 50ms delay
TH0=0xFF; // Timer 0 initial value (High Byte)
TL0=0x3F; // Timer 0 initial value (LOW Byte)

TF0=0; // Clear overflow flag
TR0=1; // Start timer 0

while (TF0==0); //Loop until Timer 0 overflows (TF0==1)

TR0=0; // Stop Timer 0;
}

Any feedback?

Max

List of 34 messages in thread
TopicAuthorDate
Serial RF with AT89C51 to AT89C51      Manoz Joshi      08/28/05 07:35      
   Lineks ?      Steve M. Taylor      08/28/05 09:31      
   UARTs and ASK      Dan Henry      08/28/05 09:54      
      Software driven UART - Bit-banging      Manoz Joshi      08/28/05 17:23      
         Channel coding        Dan Henry      08/29/05 07:16      
            Yes but...      Manoz Joshi      08/29/05 13:47      
               What is the hardware UART not doing?      Dan Henry      08/29/05 14:27      
                  Hardware UART      Manoz Joshi      08/29/05 19:08      
                     RF links pose challenges, but anyway...      Dan Henry      08/29/05 20:58      
                     Spend the money or do the hard work?      Andy Neil      08/30/05 00:56      
                        So many, so often, forget that design is      Erik Malund      08/30/05 07:10      
   Rendering      Steve M. Taylor      08/30/05 09:06      
      Me too !      Farshid Jafari Harandi      08/30/05 09:21      
      nope, just like any other (IE)      Erik Malund      08/30/05 11:13      
         Disappointed!      Manoz Joshi      08/30/05 13:58      
            What is the purpose of "learning" our co      Erik Malund      08/30/05 14:40      
            Sorry but      Steve M. Taylor      08/30/05 14:43      
            End of wrong stick?      Andy Neil      08/30/05 16:42      
            Learning? Dealing with disappoinment      Dan Henry      08/30/05 18:01      
            What you need to learn      Andy Neil      08/31/05 03:31      
               Apology      Manoz Joshi      08/31/05 08:03      
                  Recommendation      Andy Neil      08/31/05 09:25      
                  A short backgrounder      Dan Henry      08/31/05 11:26      
                     Missing the point      Russell Bull      09/01/05 03:50      
   The wise men have spoken      Dan Henry      08/30/05 18:09      
   UARTs, the last word Mr. Joshi      Dan Henry      08/30/05 18:13      
      *Groan* Here is my inital code      Manoz Joshi      08/31/05 01:39      
         Does it work ?      Steve M. Taylor      08/31/05 01:53      
            Does it work at all?      Andy Neil      08/31/05 03:53      
         The Point.      Andy Neil      08/31/05 03:46      
            why analyze how deep the water is before      Erik Malund      08/31/05 07:14      
         TF2 needs to be cleared in interrupt      Charles Bannister      08/31/05 04:54      
         the right way to get help definitely is      Erik Malund      08/31/05 07:05      
         Pinching a loaf      Dan Henry      08/31/05 18:47      

Back to Subject List