electronics forum

Rules | Recent posts | topic RSS | Search | Register  | Log in

AT89C51 to AT89C51 via wire


Post new topic  Reply to topic    EDAboard.com Forum Index -> Microcontrollers -> AT89C51 to AT89C51 via wire
Author Message
Maverickmax



Joined: 06 Dec 2004
Posts: 406
Helped: 3


Post11 Nov 2005 10:08   

AT89C51 to AT89C51 via wire


Hello

I am trying to transmit a simple character across another device such as AT89C51 via wire in order to identify the character and switch red_led on for a short of time and switch it off.

What I get - NOTHING!

I am using 12MHz as an oscillator and the baud rate is 9600. So any help would be appreicated.

Here is two codes such as transmitter and receiver

Transmitter

Code:

// header files
#include "main.h"
#include "port.h"
#include "delay_loop.h"

//Function Prototypes

void serial_init();
void send_serial(unsigned char *s);


void serial_init()
{
   SCON=0x50;      //Setup for 8-bit data
   TMOD=0x20;      //Setup timer 1 for auto-reload
   TH1=0xF9;      //Setup for 9600 Baud
   TR1=1;         //Turn on timer 1
   TI=1;         //Indicate ready to transmit
}

void send_serial(unsigned char *s)
{
   while(*s !=0x00)
   {
      SBUF=*s;
      while(! TI)
      {

      }
      TI=0;

      s++;
   }
}


void main(void)
{

serial_init();
BLUE_LED=OFF;
Delay_Loop(100);
BLUE_LED=ON;
Delay_Loop(100);
BLUE_LED=OFF;

Delay_Loop(100);
BLUE_LED=ON;
Delay_Loop(50);
send_serial('5');
BLUE_LED=OFF;
   
}



Receiver

Code:

// header files
#include "main.h"
#include "port.h"
#include "delay_loop.h"

//Global variable
tByte received_data_G;
int received_flag_G;

//Function Prototypes

void serial_init();    

void serial_init()
{
   SCON=0x50;      //Setup for 8-bit data
   TMOD=0x20;      //Setup timer 1 for auto-reload
   TH1=0xF9;      //Setup for 9600 Baud
   TR1=1;         //Turn on timer 1
   TI=1;         //Indicate ready to transmit
   EA=1;         //Enable Interrupts
   ES=1;         //Enable serial port interrupt
}

serial() interrupt 4
{
   if(RI)
   {
      received_data_G=SBUF;
      RI=0;
      received_flag_G=1;      //Set received flag
   }
}


void main(void)
{
RED_LED=OFF;
Delay_Loop(100);
RED_LED=ON;
Delay_Loop(100);
RED_LED=OFF;



received_flag_G=0;
serial_init();

   for(;;)
   {

      while(received_flag_G==0)
      {

      }

      received_flag_G=0;

      if (received_data_G==5)
      {
         RED_LED=ON;
         Delay_Loop(50);
         RED_LED=OFF;
      }
   }
}



Is the baud rate configuration correct?

Maverickmax
Back to top
IanP



Joined: 05 Oct 2004
Posts: 6490
Helped: 1542
Location: West Coast


Post11 Nov 2005 11:09   

Re: AT89C51 to AT89C51 via wire


Good idea is to test transmitter and receiver separately ..
You can use Windows Hyperterminal, or preferably other terminal software (there are plenty to choose from in EDA ) that allows you to see both ASCII and HEX, to check what is sent by the transmitter, and modify code, if required, unless you are satisfied that transmitter works correctly ..
The same can be done with the receiver; you can press keys from PC keyboard to simulate numbers; for example CTRL-A=01h, CTRL-B=02h and so on ..
At this stage I wouldn't use serial port interrupt at the receiver end .. try to follow the RI bit, and slow down the rate at which you ask the transmitter to send out bytes ..

For 9600bps and 12MHz crystal the re-load value should be FD ..
http://eserver.bell.ac.uk/mirrors/i8051/part5.htm

Regards,
IanP
Back to top
Maverickmax



Joined: 06 Dec 2004
Posts: 406
Helped: 3


Post13 Nov 2005 16:59   

Re: AT89C51 to AT89C51 via wire


Maverickmax wrote:


Thank you IanP. I have followed your suggestion.

I have found that my transmitter code works without any problem.

However the receiver code didn't work and I have been trying to pinpoint the problem for hours. Fortunately I have found the error in my receiver code.
I realised '5' should NOT be used because

ERROR - Receiver code

Code:


ERROR --> if (received_data_G==5)
      {
         RED_LED=ON;
         Delay_Loop(50);
         RED_LED=OFF;
      }




0x35 should be used instead of '5' because I did not realise that any letter must be changed into hexdecimal in accordance with ASCII codes. Therefore the receiver code should be like this:

Code:


      if (received_data_G==0x35)
      {
         RED_LED=ON;
         Delay_Loop(50);
         RED_LED=OFF;
      }





By the way, I have been using termv19b and I have not experience any problem with it as I could send and receive character.

However the hyperterminal from window would not allow me to enter character as I pressed one character and it didn't come on the screen but it accepts the data coming from my microcontroller chip. So can anyone explain why i experience that problem?

Maverick Max

Back to top
IanP



Joined: 05 Oct 2004
Posts: 6490
Helped: 1542
Location: West Coast


Post14 Nov 2005 2:10   

Re: AT89C51 to AT89C51 via wire


Hyperterminal is not ideal tool; it has a lot of downsides comparing with other terminal packages ..
For Hyperterminal all your keybord is ASCII .. And if you want to send out hexadecimal characters, say 01h, you have to use CTRL+A, 02H=CTRL+B ... and so on ..
So, try something like this: h**p://www.rfinnovations.com.au/Uploads/Images/RFI-Interm%20Rev1.1(1).zip
It is a very nice and easy to use terminal software ..
Regards,
IanP
Back to top
Maverickmax



Joined: 06 Dec 2004
Posts: 406
Helped: 3


Post14 Nov 2005 19:58   

Re: AT89C51 to AT89C51 via wire


Thank you again IanP

I have finally solved my problem. The serial communication between two AT89C51 work very well and I am very pleased with it.

There is one thing that I need to be sure about....

Since I use 12MHz and 9600 baud rate therefore TH1 would be 0xF9, I found out that the error would be approximately 7 percent.

So that means the serial communication between two AT89C51s would likely get error.

Would I solve the problem if I implement 11.059MHz in order to get no error - zero percent?

If yes, so that means I need to adjust TH1 = 0xFD. Does it that sense?


Maverick Max
Back to top
Google
AdSense
Google Adsense




Post14 Nov 2005 19:58   

Ads




Back to top
IanP



Joined: 05 Oct 2004
Posts: 6490
Helped: 1542
Location: West Coast


Post15 Nov 2005 1:40   

Re: AT89C51 to AT89C51 via wire


If both microcontrollers use the same crystals ad TH1 then the communication between them will go without errors ..
If, however, you would like to read ("spy") with, say PC, serial port what is sent the baud rate may be out of the standard 9600bps ..
In this case changing crystal to 11,095200 would be a good idea as this is the exact clock frequency for most of common baud rates ..
(FDh) ..
Rgards,
IanP
Back to top
Arabic versionBulgarian versionCatalan versionCzech versionDanish versionGerman versionGreek versionEnglish versionSpanish versionFinnish versionFrench versionHindi versionCroatian versionIndonesian versionItalian versionHebrew versionJapanese versionKorean versionLithuanian versionLatvian versionDutch versionNorwegian versionPolish versionPortuguese versionRomanian versionRussian versionSlovak versionSlovenian versionSerbian versionSwedish versionTagalog versionUkrainian versionVietnamese versionChinese version
Post new topic  Reply to topic    EDAboard.com Forum Index -> Microcontrollers -> AT89C51 to AT89C51 via wire
Page 1 of 1 All times are GMT + 1 Hour
Similar topics:
AT89C51 (2)
AT89c51 ??? (15)
performance of AT89C51 (13)
AT89C51 problem (6)
Delay() in at89c51 (3)
AT89c51 Propeller (3)
Help at89c51 (1)
at89c51 programmer (2)
AT89C51 downloader..!!! (21)
at89c51 vs 8051 (8)


Abuse || Administrator || Moderators || Support us || sitemap
topic RSS