使用串口3定时器3做波特率发生器写了一个小程序,但是通讯实现不了,求指教
#include "STC81.h"
#include "intrins.h"
#include "485.h"
#define FOSC 24000000UL
#define BRT (65536-FOSC/9600/4)
#define uchar unsigned char
bit busy;
char wptr;
char rptr;
char buffer[16];
void Uart3Isr()interrupt 17 using 1
{
if(S3CON&0x02)
{
S3CON&=~0x02;
busy=0;
}
if(S3CON&0x01)
{
S3CON&=~0x01;
buffer[wptr++]=S3BUF;
wptr&=0x0f;
if((buffer[7]==0x00)&&(buffer[8]==0x00))
{
RUN11=RUN21=RUN31=RUN41=0;
STOP11=STOP21=STOP31=STOP41=0;
}
}
}
void Uart3Init()
{
RE485=0;//RS485设置为接收方向
S3CON=0x50;
T3L=BRT;
T3H=BRT>>8;
T4T3M=0x0a;
wptr=0x00;
rptr=0x00;
busy=0;
}
void Uart3Send(char dat)
{
while(busy);
busy=1;
S3BUF=dat;
}
void main()
{
P_SW2=0x02;
Uart3Init();
IE2=0x08;
EA=1;
while(1)
{
if(rptr!=wptr)
{
Uart3Send(buffer[rptr++]);
rptr&=0x0f;
}
}
}