DSP_代码笔记(基于TMS320X281x)

2018-12-27 16:15:31 浏览数 (3)

系统初始化函数:

代码语言:javascript复制
void InitSysCtrl(void)
{
    Uint16 i;
    EALLOW;
    SysCtrlRegs.WDCR = 0x0068;
    SysCtrlRegs.PLLCR = 0xA;
    for(i=0;i<5000;i  ){}
    SysCtrlRegs.HISPCP.all = 0x0001;
    SysCtrlRegs.LOSPCP.all = 0x0002;
    SysCtrlRegs.PCLKCR.bit.EVAENCLK = 1;
    SysCtrlRegs.PCLKCR.bit.EVBENCLK = 1;
    SysCtrlRegs.PCLKCR.bit.SCIENCLKA = 1;
    EDIS;
}

GPIO初始化函数:

代码语言:javascript复制
void InitGpio(void)
{
    EALLOW;
    GpioMuxRegs.GPAMUX.bit.T1PWM_GPIOA6 = 1;
    GpioMuxRegs.GPAMUX.bit.T2PWM_GPIOA7 = 1;
    GpioMuxRegs.GPAMUX.bit.PWM1_GPIOA0=1;
    GpioMuxRegs.GPAMUX.bit.PWM2_GPIOA1=1;
    GpioMuxRegs.GPAMUX.bit.PWM3_GPIOA2=1;
    GpioMuxRegs.GPAMUX.bit.PWM4_GPIOA3=1;
    GpioMuxRegs.GPAMUX.bit.PWM5_GPIOA4=1;
    GpioMuxRegs.GPAMUX.bit.PWM6_GPIOA5=1;

    GpioMuxRegs.GPBMUX.bit.T3PWM_GPIOB6=1;
    GpioMuxRegs.GPBMUX.bit.T4PWM_GPIOB7=1;
    GpioMuxRegs.GPBMUX.bit.PWM7_GPIOB0=1;
    GpioMuxRegs.GPBMUX.bit.PWM8_GPIOB1=1;
    GpioMuxRegs.GPBMUX.bit.PWM9_GPIOB2=1;
    GpioMuxRegs.GPBMUX.bit.PWM10_GPIOB3=1;
    GpioMuxRegs.GPBMUX.bit.PWM11_GPIOB4=1;
    GpioMuxRegs.GPBMUX.bit.PWM12_GPIOB5=1;
    
    EDIS;

}

初始化EV函数:

代码语言:javascript复制
void InitEv(void)
{
    EvaRegs.T1CON.bit.TMODE=2;
    EvaRegs.T1CON.bit.TPS= 1;
    EvaRegs.T1CON.bit.TENABLE=0;
    EvaRegs.T1CON.bit.TCLKS10=0;
    EvaRegs.T1CON.bit.TECMPR=1;
    EvaRegs.T2CON.bit.TMODE=2;
    EvaRegs.T2CON.bit.TPS =1;
    EvaRegs.T2CON.bit.TENABLE=0;
    EvaRegs.T2CON.bit.TCLKS10=0;
    EvaRegs.T2CON.bit.TECMPR=1;
    EvaRegs.GPTCONA.bit.TCOMPOE=1;

    EvaRegs.GPTCONA.bit.T1PIN=1;
    EvaRegs.GPTCONA.bit.T2PIN=2;
    EvaRegs.T1PR=0x927B;
    EvaRegs.T1CMPR=0x3A98;
    EvaRegs.T1CNT=0;

    EvaRegs.T2PR=0x927B;
    EvaRegs.T2CMPR=0x57E4;
    EvaRegs.T2CNT=0;

    EvaRegs.COMCONA.bit.CENABLE=1;
    EvaRegs.COMCONA.bit.FCOMPOE=1;
    EvaRegs.COMCONA.bit.CLD=2;

    EvaRegs.DBTCONA.bit.DBT=10;
    EvaRegs.DBTCONA.bit.EDBT1=1;
    EvaRegs.DBTCONA.bit.EDBT2=1;
    EvaRegs.DBTCONA.bit.EDBT3=1;
    EvaRegs.DBTCONA.bit.DBTPS=4;

    EvaRegs.ACTR.all=0x0999;

    EvaRegs.CMPR1=0x3A98;
    EvaRegs.CMPR2=0x3A98;
    EvaRegs.CMPR3=0x3A98;

    EvbRegs.T3CON.bit.TMODE=1;
    EvbRegs.T3CON.bit.TPS=1;
    EvbRegs.T3CON.bit.TENABLE=0;
    EvbRegs.T3CON.bit.TCLKS10=0;
    EvbRegs.T3CON.bit.TECMPR=1;

    EvbRegs.T4CON.bit.TMODE=1;
    EvbRegs.T4CON.bit.TPS=1;
    EvbRegs.T4CON.bit.TENABLE=0;
    EvbRegs.T4CON.bit.TCLKS10=0;
    EvbRegs.T4CON.bit.TECMPR=1;

    EvbRegs.GPTCONB.bit.TCOMPOE=1;
    EvbRegs.GPTCONB.bit.T3PIN=1;
    EvbRegs.GPTCONB.bit.T4PIN=2;

    EvbRegs.T3PR=0x493E;
    EvbRegs.T3CMPR=0x1D4C;
    EvbRegs.T3CNT=0;

    EvbRegs.T4PR=0x493E;
    EvbRegs.T4CMPR=0x2BF2;
    EvbRegs.T4CNT=0;

    EvbRegs.COMCONB.bit.CENABLE=1;
    EvbRegs.COMCONB.bit.FCOMPOE=1;
    EvbRegs.COMCONB.bit.CLD=2;
    
    EvbRegs.DBTCONB.bit.DBT=10;
    EvbRegs.DBTCONB.bit.EDBT1=1;
    EvbRegs.DBTCONB.bit.EDBT2=1;
    EvbRegs.DBTCONB.bit.EDBT3=1;
    EvbRegs.DBTCONB.bit.DBTPS=4;

    EvbRegs.ACTRB.all=0x0999;

    EvbRegs.CMPR4=0x1D4C;
    EvbRegs.CMPR5=0x1D4C;
    EvbRegs.CMPR6=0x1D4C;

}

主函数:

代码语言:javascript复制
void main(void)
{
    InitSysCtrl();
    DINT;
    IER=0x0000;
    IFR=0x0000;
    InitPieCtrl();
    InitPieVectTable();
    InitGpio();
    InitEv();
    EvaRegs.T1CON.bit.TENABLE=1;
    EvaRegs.T2CON.bit.TENABLE=1;
    EvbRegs.T3CON.bit.TENABLE=1;
    EvbRegs.T4CON.bit.TENABLE=1;
}

Debug: "DSP28_Gpio.c", line 51: warning: last line of file ends without a newline 文件的最后一行没有换行符结束

0 人点赞