- UID
- 874505
|
小弟开始用MC9S12NE64做串口转以太网的工程,可是程序使用PE BDM MULTILINK写到单片机里面,全速运行时出错,请高手指点下可能是什么问题,在板子上烧流水灯的程序可以正常运行下面是我的代码:
#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 25Mbaud 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(!SCI1SR1_RDRF);
}
//----------SCI1中断响应函数----------//
#pragma CODE_SEG NON_BANKED
interrupt 21 void SCI1_Isr(void)
{
data=SCI1SR1;
data=SCI1DRL; //read received character + clear interrupt flag
PTG=0X40; //set transceiver chip for transmit
while(!SCI1SR1_TDRE); //SC1DR is busy,wait
SCI1DRL=data; //set transceiver chip for receive
data=SCI1SR1;
PTG=0X00;
}
#pragma CODE_SEG DEFAULT |
|