各位高手帮我看看,为什么能接收串口助手发来的数据,串口助手却收不到回送的数据呢
/////////////////////////////////////
// Generated Initialization File //
/////////////////////////////////////
#include "C8051F330.h"
// Peripheral specific initialization functions,
// Called from the Init_Device() function
void PCA_Init()
{
PCA0MD &= ~0x40; //关看门狗
}
void Oscillator_Init()
{
OSCICN = 0x83; //24.5M
}
void Port_IO_Init()
{
// P0.0 - Unassigned, Open-Drain, Digital
// P0.1 - Unassigned, Open-Drain, Digital
// P0.2 - Unassigned, Open-Drain, Digital
// P0.3 - Unassigned, Open-Drain, Digital
// P0.4 - TX0 (UART0), Push-Pull, Digital
// P0.5 - RX0 (UART0), Push-Pull, Digital
// P0.6 - Unassigned, Open-Drain, Digital
// P0.7 - Unassigned, Open-Drain, Digital
// P1.0 - Unassigned, Open-Drain, Digital
// P1.1 - Unassigned, Open-Drain, Digital
// P1.2 - Unassigned, Open-Drain, Digital
// P1.3 - Unassigned, Open-Drain, Digital
// P1.4 - Unassigned, Open-Drain, Digital
// P1.5 - Unassigned, Open-Drain, Digital
// P1.6 - Unassigned, Open-Drain, Digital
// P1.7 - Unassigned, Open-Drain, Digital
P0MDOUT = 0x30;
XBR0 = 0x01;
XBR1 = 0x40;
}
// Initialization function for device,
// Call Init_Device() from your main program
void Init_Device(void)
{ Oscillator_Init();
PCA_Init();
Port_IO_Init();
}
unsigned char addr=0x01;//从机地址
void init_serial(void)
{SCON0=0xf0;//串口方式3,9位数据位,允许接收数据
TMOD=0x20;//定时器T1工作在方式2
CKCON=0x00;//使用默认的:系统时钟/12
TH1=0x96;//波特率9600
//TL1=0x96;
TR1=1;//计时开始
}
/*
void readRegisters(void)
{
addr=5;
}
*/
void serial_interrupt (void) interrupt 4
{
unsigned char temp;
unsigned char cmd;
RI0=0;//清接收中断标志
ES0=0;//关串行中断
temp=SBUF0;
if(temp!=addr)
{ES0=1;goto reti;} //非本机地址,继续监听
TI0=0;
TB80=0;
SBUF0=addr;
while(!TI0); TI0=0;
MCE0=0;//允许接收数据
addr=8;//用串手调试助手发送01H,可以运行到此步,但为什么串口助手收不到返回的地址呢?
reti:;
}
void main()
{Init_Device();
init_serial();
ES0=1;//开UART0中断
EA=1;//开总中断
RI0=0;//设置RI0初值
while(1);//原地等待
} |