给你改了,对比一下就知道哪里错了。
- #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
- {
- IE2 &= 0xF7; // 串口3中断关闭
- if(S3CON&0x02) //在停止位开始发送时,该位置1
- {
- S3CON &= ~0x02; //清除S3CON寄存器对应S3TI位(该位必须软件清零)
- busy=0;
- }
- if(S3CON&0x01) //串行接收到停止位的中间时刻时,该位置1
- {
- S3CON &= ~0x01; //清除S3CON寄存器对应S3RI位(该位必须软件清零)
- buffer[wptr++]=S3BUF;
- wptr&=0x0f;
- if((buffer[7]==0x00)&&(buffer[8]==0x00))
- {
- RUN11=RUN21=RUN31=RUN41=0;
- STOP11=STOP21=STOP31=STOP41=0;
- }
- }
- IE2 |= 0x08; // 串口3中断打开
- }
- void Uart3Init()
- {
- RE485=0;//RS485设置为接收方向
- //S3CON=0x50;
- S3CON |= 0x50; //串口3选择定时器3为波特率发生器,启动串行接收器
- S3CON &= 0x70; //8位数据,可变波特率
- 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()
- {
- P0M1 &= 0xFE; P0M0 &= 0xFE; //设置P0.0为准双向口
- P0M1 &= 0xFD; P0M0 |= 0x02; //设置P0.1为推挽输出
- P_SW2=0x02;
- Uart3Init();
- //IE2=0x08;
- IE2 |= 0x08; // 串口3中断打开
- IE2 &= 0xDF; // 关闭定时器3中断
- EA=1;
- while(1)
- {
- if(rptr!=wptr)
- {
- Uart3Send(buffer[rptr++]);
- rptr&=0x0f;
- }
- }
- }
复制代码 |