#include "DSP28x_Project.h" // Device Headerfile and Examples Include Fil
#define LED10_OFF GpioDataRegs.GPASET.bit.GPIO0 = 1 //LED D10 熄灭
#define LED10_ON GpioDataRegs.GPACLEAR.bit.GPIO0 = 1 //LED D10 点亮
#define LED11_OFF GpioDataRegs.GPASET.bit.GPIO1 = 1 //LED D11 熄灭
#define LED11_ON GpioDataRegs.GPACLEAR.bit.GPIO1 = 1 //LED D11 点亮
#define DELAY_TIME 2000000 //延时时间
// Prototype statements for functions found within this file.
interrupt void scibRxFifoIsr(void);
interrupt void scicRxFifoIsr(void);
void scib_fifo_init(void);
void scic_fifo_init(void);
void delay(Uint32 t);
// Global variables
Uint16 rdataB[12]; // Received data for SCI-A
Uint16 rdataC[12];
void main(void)
{
Uint16 i;
InitSysCtrl();
InitSciGpio();
DINT;
InitPieCtrl();
IER = 0x0000;
IFR = 0x0000;
InitPieVectTable();
EALLOW; // This is needed to write to EALLOW protected registers
PieVectTable.SCIRXINTB = &scibRxFifoIsr;
PieVectTable.SCIRXINTC = &scicRxFifoIsr;
EDIS; // This is needed to disable write to EALLOW protected registers
scib_fifo_init(); // Init SCI-B
scic_fifo_init(); // Init SCI-B
// Enable interrupts required for this example
PieCtrlRegs.PIECTRL.bit.ENPIE = 1; // Enable the PIE block
PieCtrlRegs.PIEIER8.bit.INTx5 = 1; //for scirxintc
PieCtrlRegs.PIEIER9.bit.INTx3=1; // PIE Group 9, INT3 for scirxintb
IER = 0x180; // Enable CPU INT
EINT;
//初始化LED的端口
EALLOW;
GpioCtrlRegs.GPAPUD.bit.GPIO0 = 0; // Enable pullup on GPIO11
GpioDataRegs.GPASET.bit.GPIO0 = 1; // Load output latch
GpioCtrlRegs.GPAMUX1.bit.GPIO0 = 0; // GPIO11 = GPIO
GpioCtrlRegs.GPADIR.bit.GPIO0 = 1; // GPIO11 = output
GpioCtrlRegs.GPAPUD.bit.GPIO1 = 0; // Enable pullup on GPIO11
GpioDataRegs.GPASET.bit.GPIO1 = 1; // Load output latch
GpioCtrlRegs.GPAMUX1.bit.GPIO1 = 0; // GPIO11 = GPIO
GpioCtrlRegs.GPADIR.bit.GPIO1 = 1; // GPIO11 = output
EDIS;
LED10_ON; //LED1 D10 点亮
delay(DELAY_TIME); //延时
LED10_OFF; //LED1 D10 熄灭
LED11_ON; //LED1 D10 点亮
delay(DELAY_TIME); //延时
LED11_OFF;
// Step 6. IDLE loop. Just sit and loop forever (optional):
for(;;);
}
interrupt void scibRxFifoIsr(void)
{
Uint16 i;
LED10_ON; //LED1 D10 点亮
delay(DELAY_TIME); //延时
LED10_OFF; //LED1 D10 熄灭
for(i=0;i<12;i++)
{
rdataB[i]=ScibRegs.SCIRXBUF.all; // Read data
}
ScibRegs.SCIFFRX.bit.RXFFOVRCLR=1; // Clear Overflow flag
ScibRegs.SCIFFRX.bit.RXFFINTCLR=1; // Clear Interrupt flag
PieCtrlRegs.PIEACK.all|=0x100; // Issue PIE ack
}
void scib_fifo_init()
{
ScibRegs.SCICCR.all =0x0007; // 1 stop bit, No loopback
// No parity,8 char bits,
// async mode, idle-line protocol
ScibRegs.SCICTL1.all =0x0003; // enable TX, RX, internal SCICLK,
// Disable RX ERR, SLEEP, TXWAKE
ScibRegs.SCICTL2.bit.TXINTENA =1;
ScibRegs.SCICTL2.bit.RXBKINTENA =1;
ScibRegs.SCIHBAUD =0x0001;
ScibRegs.SCILBAUD =0x00e7;
ScibRegs.SCIFFTX.all=0xc000;
ScibRegs.SCIFFRX.all=0x002c;
ScibRegs.SCIFFCT.all=0x00;
ScibRegs.SCICTL1.all =0x0023; // Relinquish SCI from Reset
ScibRegs.SCIFFTX.bit.TXFIFOXRESET=1;
ScibRegs.SCIFFRX.bit.RXFIFORESET=1;
}
interrupt void scicRxFifoIsr(void)
{
Uint16 i;
LED11_ON; //LED1 D10 点亮
delay(DELAY_TIME); //延时
LED11_OFF; //LED1 D10 熄灭
for(i=0;i<12;i++)
{
rdataC[i]=ScicRegs.SCIRXBUF.all; // Read data
}
ScicRegs.SCIFFRX.bit.RXFFOVRCLR=1; // Clear Overflow flag
ScicRegs.SCIFFRX.bit.RXFFINTCLR=1; // Clear Interrupt flag
PieCtrlRegs.PIEACK.all|=0x080; // Issue PIE ack
}
void scic_fifo_init()
{
ScicRegs.SCICCR.all =0x0007; // 1 stop bit, No loopback
// No parity,8 char bits,
// async mode, idle-line protocol
ScicRegs.SCICTL1.all =0x0003; // enable TX, RX, internal SCICLK,
// Disable RX ERR, SLEEP, TXWAKE
ScicRegs.SCICTL2.bit.TXINTENA =1;
ScicRegs.SCICTL2.bit.RXBKINTENA =1;
ScicRegs.SCIHBAUD =0x0001;
ScicRegs.SCILBAUD =0x00e7;
ScicRegs.SCIFFTX.all=0xc000;
ScicRegs.SCIFFRX.all=0x002c;
ScicRegs.SCIFFCT.all=0x00;
ScicRegs.SCICTL1.all =0x0023; // Relinquish SCI from Reset
ScicRegs.SCIFFTX.bit.TXFIFOXRESET=1;
ScicRegs.SCIFFRX.bit.RXFIFORESET=1;
}
/*********************************************延时函数************************************************/
void delay(Uint32 t)
{
Uint32 i = 0;
for (i = 0; i < t; i++);
}