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

Back to Subject List

Old thread has been locked -- no new posts accepted in this thread
???
08/31/05 07:39
Read: times


 
#100318 - *Groan* Here is my inital code
Responding to: ???'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            01/01/70 00:00      
   Lineks ?            01/01/70 00:00      
   UARTs and ASK            01/01/70 00:00      
      Software driven UART - Bit-banging            01/01/70 00:00      
         Channel coding            01/01/70 00:00      
            Yes but...            01/01/70 00:00      
               What is the hardware UART not doing?            01/01/70 00:00      
                  Hardware UART            01/01/70 00:00      
                     RF links pose challenges, but anyway...            01/01/70 00:00      
                     Spend the money or do the hard work?            01/01/70 00:00      
                        So many, so often, forget that design is            01/01/70 00:00      
   Rendering            01/01/70 00:00      
      Me too !            01/01/70 00:00      
      nope, just like any other (IE)            01/01/70 00:00      
         Disappointed!            01/01/70 00:00      
            What is the purpose of "learning" our co            01/01/70 00:00      
            Sorry but            01/01/70 00:00      
            End of wrong stick?            01/01/70 00:00      
            Learning? Dealing with disappoinment            01/01/70 00:00      
            What you need to learn            01/01/70 00:00      
               Apology            01/01/70 00:00      
                  Recommendation            01/01/70 00:00      
                  A short backgrounder            01/01/70 00:00      
                     Missing the point            01/01/70 00:00      
   The wise men have spoken            01/01/70 00:00      
   UARTs, the last word Mr. Joshi            01/01/70 00:00      
      *Groan* Here is my inital code            01/01/70 00:00      
         Does it work ?            01/01/70 00:00      
            Does it work at all?            01/01/70 00:00      
         The Point.            01/01/70 00:00      
            why analyze how deep the water is before            01/01/70 00:00      
         TF2 needs to be cleared in interrupt            01/01/70 00:00      
         the right way to get help definitely is            01/01/70 00:00      
         Pinching a loaf            01/01/70 00:00      

Back to Subject List