求高手解答虚拟串口问题 我仿写的程序帮忙看下 哪有问题 万分感激。
#include<reg51.h>
#define uint unsigned int #define uchar unsigned char
uchar bdata DataBuf; sbit DataBuf0=DataBuf^0; sbit DataBuf1=DataBuf^1; sbit DataBuf2=DataBuf^2; sbit DataBuf3=DataBuf^3; sbit DataBuf4=DataBuf^4; sbit DataBuf5=DataBuf^5; sbit DataBuf6=DataBuf^6; sbit DataBuf7=DataBuf^7;
sbit Rxd=P1^0; sbit Txd=P1^1;
void delay(uint z) { int x,y; for(x=z;x>0;x--) for(y=110;y>0;y--); }
void init() { TMOD=0x02; P1=0xff; TL0=0x40; //波特率 9600 TH0=0x40;
}
void send(uchar aa) { uint i=0;
DataBuf=aa;
TR0=1;
Txd=1; //起始位 while(!TF0); TF0=0;
Txd=DataBuf0; while(!TF0); TF0=0;
Txd=DataBuf1; while(!TF0); TF0=0;
Txd=DataBuf2; while(!TF0); TF0=0;
Txd=DataBuf3; while(!TF0); TF0=0;
Txd=DataBuf4; while(!TF0); TF0=0;
Txd=DataBuf5; while(!TF0); TF0=0;
Txd=DataBuf6; while(!TF0); TF0=0;
Txd=DataBuf7; while(!TF0); TF0=0;
Txd=1; //停止位 while(!TF0); TF0=0;
TR0=0; } void main() { init(); while(1) { send('A'); delay(100); } }
[ 本帖最后由 wsy412571405 于 2011-12-15 15:21 编辑 ]
|