金牌会员
- 积分
- 2561
- 威望
- 1316
- 贡献
- 757
- 兑换币
- 504
- 注册时间
- 2012-1-9
- 在线时间
- 244 小时
|
1#
楼主 |
发表于 2012-3-27 17:23:14
|
只看该作者
EnableInterrupts;
SCI0_SendByte(0x01);
SCI0_SendByte(0x02);
SCI0_SendByte(0x03);
for(;;) {
_FEED_COP(); /* feeds the dog */
if(SCI_Flag==1) {
SCI_Flag = 0;
SCI0_SendByte(SCI_Rev);
}
} /* loop forever */
/* please make sure that you never leave main */
}
void Service_WD(void)
{
CPMUARMCOP = 0x55;
CPMUARMCOP = 0xAA;
}
/*************总线频率40M***********/
void SetBusClock_40MHz(void)
{
CPMUOSC_OSCE = 1; /* enable ext osc */
CPMUSYNR = 0xc0 | 0x04; /* VCOFRQ[7:6], SYNDIV[5:0] */
CPMUREFDIV = 0xc0 | 0x01; /* REFFRQ[7:6], REFDIV[3:0] */
CPMUPOSTDIV = 0x00; /* POSTDIV = 0 FPLL = FVCO */
while(!CPMUFLG_LOCK); /* wait for VCO to stabilize*/
_FEED_COP();
CPMUCLKS_PLLSEL = 1; /* Switch clk to use PLL */
}
//串口初始化
void SCI0_Init(void)
{
SCI0CR1 = 0x00; /* 8 Data Bits, 1 Start Bit, 1 Stop Bit, No Parity */
SCI0CR2 = 0x2C; /* 使能接收中断;使能 Tx,Rx */
/* SCIASR1, SCIACR1, SCIACR2, SCISR1, SCISR2, SCIDRH & SCIDRL left at default values */
}
//串口波特率设置
void SCI0_BR(void)
{
/* Set the Baud Rate */
SCI0BDH = 0x01;
SCI0BDL = 0x04; //波特率 9600
}
//串口发送字节
void SCI0_SendByte(char ch)
{
/* check SCI transmit data register is empty */
while(SCI0SR1_TDRE == 0);
SCI0DRL = ch;
}
//串口中断
#pragma CODE_SEG __NEAR_SEG NON_BANKED
void interrupt VectorNumber_Vsci0 SCI0_ISR(void)
{
SCI0CR2_RIE=0;
while(SCI0SR1_RDRF == 0);
SCI_Rev = SCI0DRL;
SCI_Flag = 1;
SCI0CR2_RIE = 1;
}
#pragma CODE_SEG DEFAULT
|
|