#include "DSP28_Device.h"
void InitSysCtrl(void)
{
Uint16 i;
EALLOW;
// On TMX samples, to get the best performance of on chip RAM blocks M0/M1/L0/L1/H0 internal
// control registers bit have to be enabled. The bits are in Device emulation registers.
DevEmuRegs.M0RAMDFT = 0x0300;
DevEmuRegs.M1RAMDFT = 0x0300;
DevEmuRegs.L0RAMDFT = 0x0300;
DevEmuRegs.L1RAMDFT = 0x0300;
DevEmuRegs.H0RAMDFT = 0x0300;
// Disable watchdog module
SysCtrlRegs.WDCR= 0x0068;
// Initalize PLL
SysCtrlRegs.PLLCR = 0xA;
// Wait for PLL to lock
for(i= 0; i< 5000; i++){}
// HISPCP/LOSPCP prescale register settings, normally it will be set to default values
SysCtrlRegs.HISPCP.all = 0x0001;
SysCtrlRegs.LOSPCP.all = 0x0002;
// Peripheral clock enables set for the selected peripherals.
SysCtrlRegs.PCLKCR.bit.EVAENCLK=1;
SysCtrlRegs.PCLKCR.bit.EVBENCLK=1;
SysCtrlRegs.PCLKCR.bit.SCIENCLKA=1;
SysCtrlRegs.PCLKCR.bit.SCIENCLKB=1;
EDIS;
}
void InitGpio(void)
{
// Set GPIO F port pins,bit0 as ouput,bit1 as input,bit2 as output, bit3 as ouput
// Input Qualifier =0, none
EALLOW;
GpioMuxRegs.GPFMUX.bit.SPISIMOA_GPIOF0 = 0;
GpioMuxRegs.GPFMUX.bit.SPISOMIA_GPIOF1 = 0;
GpioMuxRegs.GPFMUX.bit.SPICLKA_GPIOF2 = 0;
GpioMuxRegs.GPFMUX.bit.SPISTEA_GPIOF3 = 0;
GpioMuxRegs.GPDMUX.bit.T3CTRIP_PDPB_GPIOD5 = 0;//蜂鸣器控制管脚,D5脚
GpioMuxRegs.GPFDIR.bit.GPIOF0 = 1;
GpioMuxRegs.GPFDIR.bit.GPIOF1 = 0; //求助这句话中为什么是0 ,0不是表示输入码,输出应该是1的啊。为什么??、?、/、/
GpioMuxRegs.GPFDIR.bit.GPIOF2 = 1;
GpioMuxRegs.GPFDIR.bit.GPIOF3 = 1;
GpioMuxRegs.GPDDIR.bit.GPIOD5 = 1; //D5脚配置为输出
EDIS;
}
unsigned int *LedADDR = (unsigned int *) 0x2800; //8个发光二极管寄存器地址
unsigned int Count,Flag;
/////////////////对应位低电平点亮该位发光二极管
const Uint16 LedCode[9]={0x7F,0xBF,0xDF,0xEF,0xF7,0xFB,0xFD,0xFE,0xFF};
interrupt void ISRTimer0(void);
void main(void)
{
InitSysCtrl(); //初始化系统主要配置cpu和外设时钟及看门狗。
DINT; //关中断
IER = 0x0000;
IFR = 0x0000;
InitPieCtrl(); //初始化PIE 禁止所有PIE通道使能。
InitPieVectTable(); //初始化PIE中断矢量表
InitPeripherals(); //初始化外设
InitGpio();
EALLOW;
PieVectTable.TINT0 = &ISRTimer0; //将中断程序地址写进对应的中断向量中。
EDIS;
Count = 0; //初始化变量
Flag=0;
ConfigCpuTimer(&CpuTimer0, 10, 1000000); //设置CPU
StartCpuTimer0(); //打开定时器0,实际是对TCR.bit.TSS位操作,定时器开关。
IER |= M_INT1; //开中断
PieCtrl.PIEIER1.bit.INTx7=1;
EINT; // 允许INTM
ERTM; // 允许DBGM
*LedADDR = 0x00; // 点亮全部8个LED灯
for(;;)
{ ; }
}
interrupt void ISRTimer0(void)
{
PieCtrl.PIEACK.bit.ACK7=1;
*LedADDR = LedCode[Count]; //依次点亮灯,置相应位低电平
if (Flag==0) Count++; else Count--;
if (Count>=8)//循环
{
Flag=1; }
if (Count<=0)//循环
{
Flag=0;
}
}
用的是2812的接CPLD i0口 |