|
本帖最后由 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;
}
|
|