??? 01/11/12 14:47 Read: 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. |
Topic | Author | Date |
Interfacing 89C51 with matlab | 01/01/70 00:00 | |
Clearing TI | 01/01/70 00:00 | |
Re: Clearing TI | 01/01/70 00:00 | |
split personality???? | 01/01/70 00:00 | |
Re: split personality???? | 01/01/70 00:00 |