void scia_fifo_init(int ibaud)
{
SciaRegs.SCICCR.all =0x0007; // 1 stop bit, No loopback
// No parity,8 char bits,
// async mode, idle-line protocol
SciaRegs.SCICTL1.all =0x0003; // enable TX, RX, internal SCICLK,
// Disable RX ERR, SLEEP, TXWAKE
SciaRegs.SCICTL2.bit.TXINTENA =1;
SciaRegs.SCICTL2.bit.RXBKINTENA =1;
if(ibaud==9600)
{
SciaRegs.SCIHBAUD =0x0001;//9600
SciaRegs.SCILBAUD =0x00e7;
}
if(ibaud==19200)
{
SciaRegs.SCIHBAUD =0x0000;
SciaRegs.SCILBAUD =0x00f3;
}
if(ibaud==38400)
{
SciaRegs.SCIHBAUD =0x0000;
SciaRegs.SCILBAUD =0x0079;
}
SciaRegs.SCICCR.bit.LOOPBKENA =0; // Enable loop back
SciaRegs.SCIFFTX.all=0xC028;
SciaRegs.SCIFFRX.all=0x0021;//
SciaRegs.SCIFFCT.all=0x00;
SciaRegs.SCICTL1.all =0x0023; // Relinquish SCI from Reset
SciaRegs.SCIFFTX.bit.TXFIFOXRESET=1;
SciaRegs.SCIFFRX.bit.RXFIFORESET=1;
}
unsigned char r232data[3]={0,0,0};
int int232cnt=0;
void scia_xmit(int a)
{
while (SciaRegs.SCIFFTX.bit.TXFFST != 0) {}
SciaRegs.SCITXBUF=a;
}
interrupt void sciaRxFifoIsr(void)
{
unsigned short ReceivedChar=SciaRegs.SCIRXBUF.all; // Read data
//
r232data[int232cnt%3]=ReceivedChar;
int232cnt++;
if((r232data[0]==0X42)&&(r232data[1]==0X42)&&(int232cnt%3==0))
{
//lslData = *(unsigned short*)(0x80000+0xb);//bit0 输出1的值,bit1 输出2的值
EALLOW;
GpioMuxRegs.GPEMUX.bit.XNMI_XINT13_GPIOE2 = 0; // IO 输入 拉低
GpioMuxRegs.GPEDIR.bit.GPIOE2 = 1; //B6输出
GpioDataRegs.GPEDAT.bit.GPIOE2 = (r232data[2]&0x2)>>1;
// GpioMuxRegs.GPBQUAL.all=0x0000; // Input qualifier disabled
EDIS;
//
EALLOW;
GpioMuxRegs.GPBMUX.bit.T3PWM_GPIOB6=0; // IO 输入 拉低
GpioMuxRegs.GPBDIR.bit.GPIOB6=1; //E2输出
GpioDataRegs.GPBDAT.bit.GPIOB6 = r232data[2]&0x1;
// GpioMuxRegs.GPBQUAL.all=0x0000; // Input qualifier disabled
EDIS;
scia_xmit(0x41);
scia_xmit(0x41);
}
SciaRegs.SCIFFRX.bit.RXFFOVRCLR=1; // Clear Overflow flag
SciaRegs.SCIFFRX.bit.RXFFINTCLR=1; // Clear Interrupt flag
PieCtrlRegs.PIEACK.all|=0x100; // Issue PIE ack
}
void main(void)
{
int ch=0;
InitSysCtrl();//设置外部时钟和系统时钟
/////////for sci-b////////////////////
EALLOW;
GpioMuxRegs.GPFMUX.all=0x0030; // Select GPIOs to be Scia pins
// Port F MUX - x000 0000 0011 0000
// GpioMuxRegs.GPGMUX.all=0x0030; // Select GPIOs to be Scib pins
// Port G MUX - x000 0000 0011 0000
EDIS;
///////////////////////////////////
DINT;
InitGpio(); // 2812原配,未改动
InitPieCtrl();
// Disable CPU interrupts and clear all CPU interrupt flags:
IER = 0x0000;
IFR = 0x0000;
InitPieVectTable();
EALLOW; // This is needed to write to EALLOW protected registers
// PieVectTable.TINT0 = &cpu_timer0_isr;
PieVectTable.RXAINT = &sciaRxFifoIsr;
EDIS;
scia_fifo_init(9600);
///*
PieCtrlRegs.PIECRTL.bit.ENPIE = 1; // Enable the PIE block
PieCtrlRegs.PIEIER9.bit.INTx1=1; // PIE Group 9, INT1
// PieCtrlRegs.PIEIER9.bit.INTx2=1; // PIE Group 9, INT2
// PieCtrlRegs.PIEIER9.bit.INTx3=1; // PIE Group 9, INT3
// PieCtrlRegs.PIEIER9.bit.INTx4=1; // PIE Group 9, INT4
IER |= 0x100; // Enable CPU INT
EINT;
ERTM;
//*/
// 将中断处理函数和InitFlash函数拷贝到RAM中运行,FLASH中运行时MemCopy和InitFlash必须有效
MemCopy(&RamfuncsLoadStart, &RamfuncsLoadEnd, &RamfuncsRunStart);
InitFlash();
// 对外部器件初始化必需放在InitFlash后
// 初始化timer0
// InitCpuTimers();
// ConfigCpuTimer(&CpuTimer0, 150, 0xffffffff);
// 初始化
while (1)
{
;
}
}