905.c
来自「MS320F2812 Sci驱动程序」· C语言 代码 · 共 186 行
C
186 行
#include "DSP28_Device.h"
#define LED1_ON GpioDataRegs.GPFDAT.bit.GPIOF11=1
#define LED1_OFF GpioDataRegs.GPFDAT.bit.GPIOF11=0
int LedFlag = 1;
unsigned int i, j;
int rx, tx;
int data;
int WaitCnt = 0;
void main(void)
{
/*初始化系统*/
InitSysCtrl();
/*关中断*/
DINT;
IER = 0x0000;
IFR = 0x0000;
/*初始化PIE中断*/
InitPieCtrl();
/*初始化PIE中断矢量表*/
InitPieVectTable();
/*初始化外设*/
InitPeripherals();
InitGpio();
#if SCIA_INT
/*设置中断服务程序入口地址*/
EALLOW; // This is needed to write to EALLOW protected registers
PieVectTable.TXAINT = &SCITXINTA_ISR;
PieVectTable.RXAINT = &SCIRXINTA_ISR;
EDIS; // This is needed to disable write to EALLOW protected registers
/*开中断*/
IER |= M_INT9;
#endif
#if SCIB_INT
/*设置中断服务程序入口地址*/
EALLOW; // This is needed to write to EALLOW protected registers
PieVectTable.TXBINT = &SCITXINTB_ISR;
PieVectTable.RXBINT = &SCIRXINTB_ISR;
EDIS; // This is needed to disable write to EALLOW protected registers
/*开中断*/
IER |= M_INT9;
#endif
EINT; // Enable Global interrupt INTM
ERTM; // Enable Global realtime interrupt DBGM
IFR = 0x0000;
//Config Timer
ConfigCpuTimer(&CpuTimer0, 150, 500000); //at 75ms period
StartCpuTimer0();
PieCtrl.PIEIER1.bit.INTx7 = 1;
IER |= M_INT1;
EINT; // Enable Global interrupt INTM
ERTM; // Enable Global realtime interrupt DBGM
IFR = 0x0000;
for(WaitCnt = 0; WaitCnt < 4; WaitCnt ++) //wait 7.5s for controller start
{
while(SyncFlag == 0)
{
//NOP wait for Sync;
}
SyncFlag = 0;
}
// SendCommand(0);
// SendCommand(5);
for(;;)
{
if(LedFlag == 1)
{
LED1_ON;
LedFlag = 0;
}
else
{
LED1_OFF;
LedFlag = 1;
}
/*
//Process center computer command
RecvCmd();
if(ReadAzCmd(&data) == 1)
SendEncoder(1, data);
if(ReadElCmd(&data) == 1)
SendEncoder(2, data);
*/
//process key
if(SciRecv(1, &rx) == 1)
{
tx = rx;//ProcessKey();
if(tx != 0xFFFF)
{
SciSend(2, tx);
}
}
if(SciRecv(2, &rx) == 1)
{
tx = rx;//ProcessKey();
if(tx != 0xFFFF)
{
SciSend(1, tx);
}
}
/* if(SciRecv(2, &rx) == 1)
{
if(rx == 1)
{
ReadRDC(1);
}
if(rx == 4)
{
ReadRDC(2);
}
if(rx == 0x12)
{
WriteDigitalOutput(0xFF);
}
if(rx == 0x22)
{
WriteDigitalOutput(0x00);
}
if(rx == 0x10)
{
rx = ReadDigitalInput()>>8;
}
if(rx == 0x30)
{
// SetVelocity(-100);
SendCommand(12);
}
tx = rx;
SciSend(2, tx);
}
if(KeyInput() == 1)
{
SendEncoder(AZ, AzZeroPos);
}
*/
// MainLoop();
while(SyncFlag == 0)
{
//NOP wait for Sync;
}
SyncFlag = 0;
}
// StopCpuTimer0();
}
//===========================================================================
// No more.
//===========================================================================
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?