前面部分,包括F2802x_CodeStartBranch.asm文件,已经都有了,而且我们在前面的课程中,也基本都把这些东西给讲到了,至于CMD文件,TI已经提供了非常标准的链接文件,也是不用我们再另外去写,直接使用就行了,我们只要理解里面的代码含义,然后借用,做最高效的开发。我们唯一要做的就是用到什么文件或者功能,就修改对应的文件,其他的全部保持不变就行了。
既然我们这节课是LED流水灯,那肯定要用GPIO端口去输出高低电平去控制,所以需要GPIO控制文件F2802x_Gpio.c,把C: icontrolSUITEdevice_supportf2802xv200f2802x_commonsource路径下的F2802x_Gpio.c文件拷贝到
D:studyday001projectsrc路径下。
从上面的硬件环境中可以看到,我们要把GPIO0-GPIO7设置为GPIO输出端口,当输出低电平时,LED亮,输出高电平时,LED灭。
目的很明确了,那我们就去GPIO.c文件里面进行相应的设置操作:
1、选择GPIO0-GPIO7为普通GPIO引脚;
2、设置引脚为输出引脚;
3、输入鉴定滤波与SYSCLKOUT同步;
4、使能上拉电阻;
代码如下:
void InitGpio(void)
{
EALLOW;
// Each GPIO pin can be:// a) a GPIO input/output// b) peripheral function 1// c) peripheral function 2// d) peripheral function 3// By default, all are GPIO Inputs
GpioCtrlRegs.GPAMUX1.all = 0x0000; // GPIO functionality GPIO0-GPIO15
GpioCtrlRegs.GPAMUX2.all = 0x0000; // GPIO functionality GPIO16-GPIO31
GpioCtrlRegs.GPBMUX1.all = 0x0000; // GPIO functionality GPIO32-GPIO34
GpioCtrlRegs.AIOMUX1.all = 0x0000; // Dig.IO funct. applies to AIO2,4,6,10,12,14
GpioCtrlRegs.GPADIR.all = 0xFFFFFFFF; // GPIO0-GPIO31 are GP outputs
GpioCtrlRegs.GPBDIR.all = 0x0000; // GPIO32-GPIO34 are inputs
GpioCtrlRegs.AIODIR.all = 0x0000; // AIO2,4,6,19,12,14 are digital inputs// Each input can have different qualification// a) input synchronized to SYSCLKOUT// b) input qualified by a sampling window// c) input sent asynchronously (valid for peripheral inputs only)
GpioCtrlRegs.GPAQSEL1.all = 0x0000; // GPIO0-GPIO15 Synch to SYSCLKOUT
GpioCtrlRegs.GPAQSEL2.all = 0x0000; // GPIO16-GPIO31 Synch to SYSCLKOUT
GpioCtrlRegs.GPBQSEL1.all = 0x0000; // GPIO32-GPIO34 Synch to SYSCLKOUT// Pull-ups can be enabled or disabled.
GpioCtrlRegs.GPAPUD.all = 0x0000; // Pullup's enabled GPIO0-GPIO31
GpioCtrlRegs.GPBPUD.all = 0x0000; // Pullup's enabled GPIO32-GPIO34//GpioCtrlRegs.GPAPUD.all = 0xFFFF; // Pullup's disabled GPIO0-GPIO31//GpioCtrlRegs.GPBPUD.all = 0xFFFF; // Pullup's disabled GPIO32-GPIO34
EDIS;
}
GPIO.c文件设置完之后,去main.c主函数里面,给GPIO0-GPIO7一个初始值,然后用翻转寄存器进行GPADAT值的变换,代码如下:
void main(void)
{
// Step 1. Initialize System Control:// PLL, WatchDog, enable Peripheral Clocks// This example function is found in the DSP2802x_SysCtrl.c file.
InitSysCtrl();
// Step 2. Initalize GPIO:// This example function is found in the DSP2802x_Gpio.c file and// illustrates how to set the GPIO to it's default state.
InitGpio();
// Step 3. Clear all interrupts and initialize PIE vector table:// Disable CPU interrupts
DINT;
// Initialize PIE control registers to their default state.// The default state is all PIE interrupts disabled and flags// are cleared.// This function is found in the DSP2802x_PieCtrl.c file.
InitPieCtrl();
// Disable CPU interrupts and clear all CPU interrupt flags:
IER = 0x0000;
IFR = 0x0000;
// Initialize the PIE vector table with pointers to the shell Interrupt// Service Routines (ISR).// This will populate the entire table, even if the interrupt// is not used in this example. This is useful for debug purposes.// The shell ISR routines are found in DSP2802x_DefaultIsr.c.// This function is found in DSP2802x_PieVect.c.
InitPieVectTable();
// Step 4. Initialize all the Device Peripherals:// This function is found in DSP2802x_InitPeripherals.c// InitPeripherals(); // Not required for this example// Step 5. User specific code:
GpioDataRegs.GPADAT.all = 0x00000000; //GPIO0-GPIO31 initial value are 0while(1)
{
GpioDataRegs.GPATOGGLE.all=0x000000ff;
DELAY_US(1000);
}
}
写完之后进行编译,生成cof文件,在仿真环境里面点击运行