C51编程:关于8051和pc通讯!
我编制了一8051向pc发送数据的通讯程序,8051串口与pc的com1通过rs232连接。8051程序
用keiluvision2编译,pc上用tubo c ,采用了函数bioscom。二者波特率均设为9600,采用
中断查询方式。两段程序均分别编译通过,并且在keil上可以看到serial#1上有正确地的输
出,但是8051向pc发送数据时,pc上没有显示,就是说pc并没有收到8051发来的数据。迷惑
不解,不知那里出了问题,请高人指点!
具体程序如下:
8051:
#include "reg52.h"
#include "string.h"
#include "highbios.h"
void init_rs232()
{
SCON=0x50;
TMOD=0x20;
TH1=0xfb;
TR1=1;
TI=1;
}
tx_char(unsigned char c)
{
while(1)
{
if(TI==1) break;
}
TI=0;
SBUF=c;
}
main()
{
while(1)
{
unsigned char *title0="I LOVE you!";
init_rs232();
do{tx_char(*title0++);}
while(*title0!='\0');
}
}
pc:
#include <bios.h>
#include <stdio.h>
#include <conio.h>
#include <stdlib.h>
#include <string.h>
extern void clrscr();
extern int getch();
void receive();
main()
{
char c;
bioscom(0,0xe3,0);
clrscr();
puts("---------------------");
puts("com1 <9600 N 8 1>");
puts("---------------------");
c=getch();
receive();
}
void receive()
{
int s;
char c;
while(1)
{
s=bioscom(3,0,0)&0x100;
if(s)
{
c=bioscom(2,0,0);
printf("%c",c);
}
}
}
void send(char *title)
{
int s;
do {
bioscom(1,*title++,0);
while(1)
{
s=bioscom(3,0,0)&0x100;
if(s)
{
if(bioscom(2,0,0)==*title) break;
}
}
}while(*title!='\0');
}
发表时间:2001年8月18日22:35:00