Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

how to build software UART ?

Status
Not open for further replies.
You did not answer my question.

Which compiler toolset did you use to compile this code, KEIL, IAR, SDCC, etc?

BigDog
 

I began to work on your code, when I soon realized you could not have successfully compiled it for the AT89C51.

To begin with the AT89C51 only has two timers, Timer0 and Timer1, and yet you have attempted to utilized a third timer, Timer2, which doesn't exist in an AT89C51.

Code:
void timer_set(  )  //    Sets the timer to 3 times the baud rate.
{
   [COLOR="#FF0000"]T2CON[/COLOR]   = 0x04;   // Load Timer 2 control register

   [COLOR="#FF0000"]TH2[/COLOR]     = 0xFF;  // Load Timer 2 high byte
   [COLOR="#FF0000"]RCAP2H[/COLOR]  = 0xFF;  // Load Timer 2 reload capt. reg. high byte
   [COLOR="#FF0000"]TL2[/COLOR]     = 0xE0; // Load Timer 2 low byte
   [COLOR="#FF0000"]RCAP2L[/COLOR]  = 0xE0; // Load Timer 2 reload capt. reg. low byte

   //Disable Interrupt Service Routine
   //ET2     = 0;
   //TR2   = 0;        
}


There are numerous other issues as well.

I do not mind assisting you, however I am not going to write the entire set of softUART routines.

You must at least show some effort and when you hit a snag, ask and I will assist.


BigDog
 

I began to work on your code, when I soon realized you could not have successfully compiled it for the AT89C51.

To begin with the AT89C51 only has two timers, Timer0 and Timer1, and yet you have attempted to utilized a third timer, Timer2, which doesn't exist in an AT89C51.

Code:
void timer_set(  )  //    Sets the timer to 3 times the baud rate.
{
   [COLOR="#FF0000"]T2CON[/COLOR]   = 0x04;   // Load Timer 2 control register

   [COLOR="#FF0000"]TH2[/COLOR]     = 0xFF;  // Load Timer 2 high byte
   [COLOR="#FF0000"]RCAP2H[/COLOR]  = 0xFF;  // Load Timer 2 reload capt. reg. high byte
   [COLOR="#FF0000"]TL2[/COLOR]     = 0xE0; // Load Timer 2 low byte
   [COLOR="#FF0000"]RCAP2L[/COLOR]  = 0xE0; // Load Timer 2 reload capt. reg. low byte

   //Disable Interrupt Service Routine
   //ET2     = 0;
   //TR2   = 0;        
}


There are numerous other issues as well.

I do not mind assisting you, however I am not going to write the entire set of softUART routines.

You must at least show some effort and when you hit a snag, ask and I will assist.


BigDog

actually i dont have 89c51....i have P89V51RD2BN...it has 3 timers...
what are other problems?
 


Try using MikroC pro for 8051 in that its easy to use and implement Software UART.because it got built in Libraries!
 

i got one program from internet...
i am attaching my KEIL compiled project file...
the code is compiled successfully but its not working...
i m not getting any data displayed on LCD...what must be reason?
kindly help....
 

Attachments

  • New Folder.zip
    8 KB · Views: 40

To receive data serially using UART or Soft UART you should use interrupts. Dta can come at any time so uC should be able to capture data at any time. If interrupts is not used data capture will not be successful.
 

To receive data serially using UART or Soft UART you should use interrupts. Dta can come at any time so uC should be able to capture data at any time. If interrupts is not used data capture will not be successful.

ok...polling cant be used?
can you tell me how to use interrupt for softUART?....it shud be timer based interrupt rt?
how to configure timer for 9600 baud?
 

i tried doing softUART using external hardware interrupt also(edge triggered)...
when rf-id sends data for start bit there will transition from high to low..so i think problem is my interrupt pin is not able to detect this transition bcz that might be too fast..can this be problem??
kindly help...
 

There are so many many methods to solve a same problem, but it matters which way you are going... The Ext interrupt will respond very faster no doubt It takes about two three machine cycles.. you need not use ext interrupt for soft uart... the timer interrupt only sufficient that has to tick for every bit in your baud rate after enabling the receiver section.... if you receive a low bit in the input start storing the upcoming bits for 8 locations and make it Idle... Use the same timer isr for transmit once your baud-rate perfectly matched with host then there will be no more problems.....
 

There are so many many methods to solve a same problem, but it matters which way you are going... The Ext interrupt will respond very faster no doubt It takes about two three machine cycles.. you need not use ext interrupt for soft uart... the timer interrupt only sufficient that has to tick for every bit in your baud rate after enabling the receiver section.... if you receive a low bit in the input start storing the upcoming bits for 8 locations and make it Idle... Use the same timer isr for transmit once your baud-rate perfectly matched with host then there will be no more problems.....

i tried using timer2....but its not responding...
can please tell me how to configure timer2 for 9600 baud for softUART?
There will be no transmit part for softUART as m interfacing RF-ID..
 

take your baud rate

you will get time requird (1/(baud rate))

now get your crystal frequency divide by (ex) 12 for hardware cycle now find the one machine cycle

time required / machine cycle time

you will get the value in decimal integer now subtract from 65536 (in16 bit mode) or 256 (in 8 bit)
now load this value in timer counter register...
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top