中级会员
- 积分
- 352
- 威望
- 220
- 贡献
- 84
- 兑换币
- 0
- 注册时间
- 2012-3-18
- 在线时间
- 24 小时
- 毕业学校
- 河北工业大学
|
1贡献
以下为我的程序,使用断点可以用485调试助手正确收发,可是全速运行就会收到乱码,请问高手这是什么问题
#include <hidef.h>
#include <mc9s12ne64.h>
uchar data;
//----------PLL初始化----------//
void clockinit(void)
{
CLKSEL_PLLSEL=0;
PLLCTL_PLLON=0; //turn off PLL
SYNR =0x01;
REFDV=0x01; //pllclock=2*osc*(1+SYNR)/(1+REFDV)=50MHz,busclk=pllclk/2=25M;
PLLCTL_PLLON=1; //turn on PLL
_asm(nop);
_asm(nop);
_asm(nop);
_asm(nop);
while(!(CRGFLG_LOCK==1)); //the pll is stable
CLKSEL_PLLSEL =1; //engage PLL to system;
COPCTL = 0x00; //disable watchdog
}
//----------串口SCI1初始化----------//
void sciinit(void)
{
SCI1BDL=0xA3; //bus clock is 25M?baud rate is 9600
SCI1BDH=0x00;
SCI1CR1=0x00; //8 bits of data,1 bit of stop
SCI1CR2=0XAC; //admit receive and transmit interrupt,admit receive and transmit
}
//----------IO初始化----------//
void IOinit(void)
{
DDRG=0XFF;
PTG=0X00;
}
//----------主函数----------//
void main(void)
{
DisableInterrupts;
clockinit();
sciinit();
IOinit();
PEAR_NECLK=0;
EnableInterrupts;
while(1);
}
//----------SCI1中断响应函数----------//
#pragma CODE_SEG NON_BANKED
interrupt 21 void SCI1_Isr(void)
{
uchar r;
r=SCI1SR1;
//while(!SCI1SR1_RDRF);
data=SCI1DRL; //read received character + clear interrupt flag
PTG=0X40; //set transceiver chip for transmit
r=SCI1SR1;
while(!SCI1SR1_TDRE); //SC1DR is busy,wait
SCI1DRL=data; //set transceiver chip for receive
PTG=0X00;
}
#pragma CODE_SEG DEFAULT
|
|