|
本帖最后由 eyven0519 于 2020-3-3 20:37 编辑
同一个程序,烧在最小系统里的结果与烧在开发板里的结果不一样,为什么 ?请大神指导。
最小系统在串口助手显示结果正常如下:
开发板连接串口助手显示结果不下确,结果如下:
程序如下:
#include "stc8.h"
#include "intrins.h"
typedef unsigned char uchar;
typedef unsigned int uint;
#define FOSC 11059200L //系统频率
#define BAUD 9600 //串口波特率
bit busy;
sbit RS485_DIR = P0^4;
uchar tmp=0xf0;
void UartWrite(uchar dat);
void ConfigUART(uint Baud)
{
RS485_DIR=0;
P0M0=0x02;
P0M1=0x00;
S3CON = 0x10;
AUXR |= 0x14;
T2L = (65536 - (FOSC/4/Baud));
T2H = (65536 - (FOSC/4/Baud))>>8;
}
void main()
{
P_SW2 = 0x00;
ConfigUART(BAUD);
IE2 = 0x08;
EA = 1;
while(1)
{
UartWrite(tmp);
delay(10000);
}
}
void Uart3() interrupt 17 using 1
{
if(S3CON & 0x02)
{
S3CON &= ~0x02; //清除S3RI位
busy=0;
}
if(S3CON & 0x01)
{
S3CON &= ~0x01; //清除S3RI位
tmp=S3BUF;
P1=tmp;
}
}
void UartWrite(uchar dat)
{
RS485_DIR=1;
while(busy);
busy=1;
S3BUF = dat; //写数据到UART3数据寄存器
delay(5);
RS485_DIR=0;
}
|
|