|
SCI.C
#include "sci.h"
//串口BGPIO初始化
void InitSciB()
{
EALLOW;
GpioCtrlRegs.GPAPUD.bit.GPIO18 = 0; // Enable pull-up for GPIO62 (SCITXDB)
GpioCtrlRegs.GPAPUD.bit.GPIO19 = 0; // Enable pull-up for GPIO63 (SCIRXDB)
GpioCtrlRegs.GPAQSEL2.bit.GPIO18 = 3; // Asynch input GPIO19 (SCITXDB)
GpioCtrlRegs.GPAQSEL2.bit.GPIO19 = 3; // Asynch input GPIO23 (SCIRXDB)
GpioCtrlRegs.GPAMUX2.bit.GPIO18 = 2; // Configure GPIO19 for SCITXDB operation
GpioCtrlRegs.GPAMUX2.bit.GPIO19 = 2; // Configure GPIO23 for SCIRXDB operation
EDIS;
ScibRegs.SCICCR.all =0x0007; // 1 stop bit, No loopback,No parity,8 char bits,async mode, idle-line protoco
ScibRegs.SCICTL1.all =0x0003; // enable TX, RX, internal SCICLK,
// Disable RX ERR, SLEEP, TXWAKE
ScibRegs.SCICTL2.all =0x0003; //接收中断使能
ScibRegs.SCICTL2.bit.RXBKINTENA =1;
#if (CPU_FRQ_150MHZ)
#if(BUADRATE_9600) //设置波特率
ScibRegs.SCIHBAUD =0x0001; // 9600 baud @LSPCLK = 37.5MHz.
ScibRegs.SCILBAUD =0x00E7;
#endif
#if(BUADRATE_115200)
ScibRegs.SCIHBAUD =0x0000; // 115200 baud @LSPCLK = 37.5MHz.
ScibRegs.SCILBAUD =0x0028;
#endif
#endif
#if (CPU_FRQ_100MHZ)
ScibRegs.SCIHBAUD =0x0001; // 9600 baud @LSPCLK = 20MHz.
ScibRegs.SCILBAUD =0x0044;
#endif
// ScibRegs.SCIFFTX.all=0xC000; //FIFO功能使能
ScibRegs.SCIFFRX.all=0x0021; //接收FIFO的深度为最低的5位,此处设置为1,没接受到一个字符都会产生接收中断
// ScibRegs.SCIFFCT.all=0x00;
ScibRegs.SCICTL1.all =0x0023; // Relinquish SCI from Reset
//ScibRegs.SCIFFRX.bit.RXFIFORESET=1; //复位接收FIFO
}
// Transmit a character from the SCI
void put_char(char a)
{
while (ScibRegs.SCICTL2.bit.TXRDY == 0);
ScibRegs.SCITXBUF=a;
}
void put_string(char * putchar)
{
while(*putchar!= 0x00)
{
put_char(*putchar++);
}
}
//串口B接收中断
interrupt void SciB_RxInterIsr(void)
{
u8 res;
res = (ScibRegs.SCIRXBUF.all) & 0x00FF;
// put_char(res);
switch(res)
{
case '0': put_char('I'); break;
case '1': put_char(' '); break;
case '2': put_char('l'); break;
case '3': put_char('O'); break;
case '4': put_char('V'); break;
case '5': put_char('E'); break;
case '6': put_char(' '); break;
case '7': put_char('Y'); break;
case '8': put_char('O'); break;
case '9': put_char('U'); break;
default : break;
}
ScibRegs.SCIFFRX.bit.RXFFOVRCLR=1; // Clear Overflow flag
ScibRegs.SCIFFRX.bit.RXFFINTCLR=1; // Clear Interrupt flag
PieCtrlRegs.PIEACK.all = PIEACK_GROUP9;
}
main函数中相关函数和设置
InitSciB(); //串口B初始化
PieVectTable.SCIRXINTB = &SciB_RxInterIsr; //SCIBX接收中断服务程序
IER |= M_INT9; //开启CPU中断 组9 SCI_RX CANB中断线1
PieCtrlRegs.PIEIER9.bit.INTx3=1; //串口B接收中断 PIE Group 9, INT3
|
|