#include "DSP28x_Project.h"
extern void MemCopy(Uint16 *SourceAddr, Uint16* SourceEndAddr, Uint16* DestAddr);
extern Uint16 RamfuncsLoadStart;
extern Uint16 RamfuncsLoadEnd;
extern Uint16 RamfuncsRunStart;
void Scia_xmit(int a);
void Uart_sendstring(char * ch);
void Scia_receive(void);
int Conversion(int number, int system, char output[]);
int Sci_Receivedata;
char str[3];
void main(void) {
char ch;
InitSysCtrl();
InitGpio();
InitSpiaGpio();
InitSciaGpio();
DINT;
InitPieCtrl();
IER = 0x0000;
IFR = 0x0000;
InitPieVectTable();
MemCopy(&RamfuncsLoadStart, &RamfuncsLoadEnd, &RamfuncsRunStart);
InitFlash();
EALLOW;
PieVectTable.SCIRXINTA=&SCITXINTA_ISR;
EDIS;
PieCtrlRegs.PIEIER9.bit.INTx2=1;
EINT;
ERTM;
InitSci();
InitSpi();
Sci_Receivedata=0x00;
while(1)
{
Sci_Receivedata=0x00;
Scia_receive();
if(Sci_Receivedata!=0x00)
{
ch=(char)Sci_Receivedata;
if(ch=='1')
{
GpioDataRegs.GPACLEAR.bit.GPIO0=1;
}
else
{
GpioDataRegs.GPASET.bit.GPIO0=1;
}
Scia_xmit(Sci_Receivedata);
}
/*(void)Conversion(Sci_Receivedata,10,str);
Uart_sendstring(str);
Uart_sendstring(" ");*/
}
}
void Scia_receive(void)
{
while(SciaRegs.SCIFFRX.bit.RXFFST!=0)
{
Sci_Receivedata=SciaRegs.SCIRXBUF.all;
}
}
void Scia_xmit(int a)
{
while (SciaRegs.SCIFFTX.bit.TXFFST != 0) {}
SciaRegs.SCITXBUF=a;
}
void Uart_sendstring(char * ch)
{
Uint16 i = 0;
while(ch != ' ')
{
Scia_xmit(ch);
i++;
}
}
int Conversion(int number, /*in 要转换的数据*/
int system, /*in 进制*/
char output[]) /*out 输出数据*/
{
// 商,余数和标记
int Quotient, Balance, i = 0;
int j,k;
Quotient = number;
do
{
Balance = Quotient % system;
output[i++] = Balance;
} while (Quotient /= system);
// 转换为char型
for(j = 0; j < i; j++)
if(output[j] > 9)
output[j] = output[j] + 55;
else output[j] += 48;
// 字符串取反
for(k = 0; k < i / 2; k++)
{
char tmp;
tmp = output[k];
output[k] = output[i - k - 1];
output[i - k - 1] = tmp;
}
output=' ';
return i;
}
void InitSci(void)
{
SciaRegs.SCICCR.all=0x0007;//1个结束位,无校验位,发送8个数据位
SciaRegs.SCICTL2.bit.TXINTENA=1;//发送中断使能
SciaRegs.SCICTL2.bit.RXBKINTENA=1;//接受中断使能
SciaRegs.SCIHBAUD=0x0000;
SciaRegs.SCILBAUD=BRR9600;//波特率设置为9600
SciaRegs.SCIFFTX.all=0xC021;//使能复位发送FIFO
SciaRegs.SCIFFRX.all=0xC021;//使能复位接受FIFO
SciaRegs.SCIFFCT.all=0x00;//FIFO控制寄存器延时时间位0
SciaRegs.SCICTL1.all=0x0023;//发送/接受中断使能位
//SciaRegs.SCIFFRX.bit.RXFFIL=7;
SciaRegs.SCIFFTX.bit.TXFIFOXRESET=1;//重新使能发送FIFO的操作
SciaRegs.SCIFFRX.bit.RXFIFORESET=1;//重新使能接受FIFO的操作
}
友情提示: 此问题已得到解决,问题已经关闭,关闭后问题禁止继续编辑,回答。
一周热门 更多>