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

Back to Subject List

Old thread has been locked -- no new posts accepted in this thread
???
01/11/12 07:47
Read: 1021 times


 
#185428 - Interfacing 89C51 with matlab
Hi,
I want to send data from 89C51 to a matlab program-if P1^0 is set, one data will be sent which will cause an action in the matlab program, if not some other data will cause a different result. I have no clue how to send data to matlab. I tried sending data to the hyperterminal but it either sends no data or some garbage data. Here's the code I've used:

#include <reg51.h>
sbit d1=P1^0;
void main(void)
{

 PCON=0xFF;                     //to set PCON.7 for baud rate
 TMOD=0x20;                     //timer 1 mode 2
 TH1=0xFA;                      //for baud rate 9600
 SCON=0x50;
 TR1=1;                         //start timer 1
 if(d1==1)
    {SBUF='Y';                  //sends Y
     while(TI==0);
     TI=0;
    }

 else
     {SBUF='N';                 //sends N
     while(TI==0);
     TI=0;
     }
 SBUF=0x0D;                     //sends carriage return and line feed
 while(TI==0);
 TI=0;
 SBUF=0x0A;
 while(TI==0);
 TI=0;

}
 

When I run this in Keil, it shows the baud rate to be 9598 instead if 9600.


List of 5 messages in thread
TopicAuthorDate
Interfacing 89C51 with matlab      Aniket Deshpande      01/11/12 07:47      
   Clearing TI      Michael Karas      01/11/12 08:05      
      Re: Clearing TI      Aniket Deshpande      01/11/12 08:21      
   split personality????      Erik Malund      01/11/12 08:45      
      Re: split personality????      Aniket Deshpande      01/11/12 09:18      

Back to Subject List