00 建立开发版与仿真器的连接
打开文件TMS320F28335.ccxml 建立连接 显示下述信息说明连接成功
2 软件编程
1 系统时钟初始化
振荡器OSC和锁相环PLL初始化
注意: 在写PLLCR寄存器前,PLLSTS[DIVSEL]必须是0。
初始化函数
InitSysCtrl();
void InitSysCtrl(void)
{
DisableDog();
InitPll(DSP28_PLLCR, DSP28_DIVSEL);
InitPeripheralClocks();
}
//可选:等待PLL锁定。 //在此期间,CPU将切换至OSCCLK/2,直到 //锁相环是稳定的。一旦PLL稳定,CPU将 //切换到新的PLL值。 // //锁定时间由PLL锁定计数器监控。 // //代码不需要等待PLL锁定。 //但是,如果代码执行任何对时间至关重要的操作, //并且需要锁定正确的时钟,那么最好 //等待此切换完成。
使能外设时钟
使能有关外设时钟的寄存器为PCLKCR0/1/3,GPIO初始化在PCLKCR3中
SysCtrlRegs.PCLKCR3.bit.GPIOINENCLK = 1;
2 初始化GPIO
On the 2833x devices, up to three independent peripheral signals are multiplexed on a single GPIO-enabled pin in addition to individual pin bit I/O capability. There are three 32-bit I/O ports. Port A consists of GPIO0-GPIO31, port B consists of GPIO32-GPIO63, and port C consists of GPIO64-87. Figure 4-1 shows the basic modes of operation for the GPIO module. 初始化函数
InitGpio();
void InitGpio(void)
{
EALLOW;
GpioCtrlRegs.GPAMUX1.all = 0x0000;
GpioCtrlRegs.GPAMUX2.all = 0x0000;
GpioCtrlRegs.GPBMUX1.all = 0x0000;
GpioCtrlRegs.GPBMUX2.all = 0x0000;
GpioCtrlRegs.GPCMUX1.all = 0x0000;
GpioCtrlRegs.GPCMUX2.all = 0x0000;
GpioCtrlRegs.GPADIR.all = 0x0000;
GpioCtrlRegs.GPBDIR.all = 0x0000;
GpioCtrlRegs.GPCDIR.all = 0x0000;
GpioCtrlRegs.GPAQSEL1.all = 0x0000;
GpioCtrlRegs.GPAQSEL2.all = 0x0000;
GpioCtrlRegs.GPBQSEL1.all = 0x0000;
GpioCtrlRegs.GPBQSEL2.all = 0x0000;
GpioCtrlRegs.GPAPUD.all = 0x0000;
GpioCtrlRegs.GPBPUD.all = 0x0000;
GpioCtrlRegs.GPCPUD.all = 0x0000;
EDIS;
}
3 清除所有中断 和初始化 PIE 向量表
DINT;
InitPieCtrl();
IER = 0x0000;
IFR = 0x0000;
InitPieVectTable();
4 添加用户具体代码
LED_GPIO_Config();
void LED_GPIO_Config(void)
{
EALLOW;
GpioCtrlRegs.GPAMUX1.bit.GPIO0=0;
GpioCtrlRegs.GPAPUD.bit.GPIO0=0;
GpioCtrlRegs.GPADIR.bit.GPIO0=1;
GpioCtrlRegs.GPAMUX1.bit.GPIO1=0;
GpioCtrlRegs.GPAPUD.bit.GPIO1=0;
GpioCtrlRegs.GPADIR.bit.GPIO1=1;
GpioCtrlRegs.GPAMUX1.bit.GPIO2=0;
GpioCtrlRegs.GPAPUD.bit.GPIO2=0;
GpioCtrlRegs.GPADIR.bit.GPIO2=1;
GpioCtrlRegs.GPAMUX1.bit.GPIO3=0;
GpioCtrlRegs.GPAPUD.bit.GPIO3=0;
GpioCtrlRegs.GPADIR.bit.GPIO3=1;
GpioCtrlRegs.GPAMUX1.bit.GPIO4=0;
GpioCtrlRegs.GPAPUD.bit.GPIO4=0;
GpioCtrlRegs.GPADIR.bit.GPIO4=1;
GpioDataRegs. GPASET.bit.GPIO0=1;
GpioDataRegs. GPASET.bit.GPIO1=1;
GpioDataRegs. GPASET.bit.GPIO2=1;
GpioDataRegs. GPASET.bit.GPIO3=1;
GpioDataRegs. GPASET.bit.GPIO4=1;
EDIS;
}
输出高电平
GpioDataRegs. GPASET.bit.GPIO0 = 1;
输出低电平
GpioCtrlRegs.GPACLEAR.bit.GPIO0 = 1;
5 编写主循环
while(1)
{
for ( i = 0; i < 5; i++)
{
GpioDataRegs.GPACLEAR.all = (0x01 << i);
delay_1ms(1000);
GpioDataRegs.GPASET.all = (0x01 << i);
delay_1ms(1000);
}
}
|