TMS320F28335GPIO Example - Light up the LED
[Copy link]
The circuit schematic is shown below:
代码:
#include "DSP2833x_Device.h" // DSP2833x Headerfile Include File
#include "DSP2833x_Examples.h" // DSP2833x Examples Include File
#define LED1 GpioDataRegs.GPBDAT.bit.GPIO60
#define LED2 GpioDataRegs.GPBDAT.bit.GPIO61
interrupt void ISRTimer0(void);
void configtestled(void);
Uint16 i;
void main(void)
{
InitSysCtrl();
InitXintf16Gpio();
DINT;
InitPieCtrl();
// Disable CPU interrupts and clear all CPU interrupt flags:
IER = 0x0000;
IFR = 0x0000;
InitPieVectTable();
EALLOW; // This is needed to write to EALLOW protected registers
PieVectTable.TINT0 = &ISRTimer0; //配置中断函数地址
//PieVectTable.XINT13 = &cpu_timer1_isr;
//PieVectTable.TINT2 = &cpu_timer2_isr;
EDIS; // This is needed to disable write to EALLOW protected registers
InitCpuTimers(); // For this example, only initialize the Cpu Timers
// Configure CPU-Timer 0, 1, and 2 to interrupt every second:
// 150MHz CPU Freq, 1 second Period (in uSeconds)
ConfigCpuTimer(&CpuTimer0, 150, 1000000); //配置定时时间 1s
//ConfigCpuTimer(&CpuTimer1, 150, 1000000);
//ConfigCpuTimer(&CpuTimer2, 150, 1000000);
StartCpuTimer0(); //定时器计数
// Enable CPU int1 which is connected to CPU-Timer 0, CPU int13
// which is connected to CPU-Timer 1, and CPU int 14, which is connected
// to CPU-Timer 2:
IER |= M_INT1;
//IER |= M_INT13;
//IER |= M_INT14;
// Enable TINT0 in the PIE: Group 1 interrupt 7
PieCtrlRegs.PIEIER1.bit.INTx7 = 1;//使能PIE中断
// Enable global Interrupts and higher priority real-time debug events:
EINT; // Enable Global interrupt INTM
ERTM; // Enable Global realtime interrupt DBGM
configtestled();
LED1 = 0;
LED2 = 0;
i = 0;
for(; ;)
{
}
}
interrupt void ISRTimer0(void)
{
CpuTimer0.InterruptCount++;
// Acknowledge this interrupt to receive more interrupts from group 1
PieCtrlRegs.PIEACK.all = PIEACK_GROUP1;//PIEACK清0
CpuTimer0Regs.TCR.bit.TIF=1; //外设中断标志位清0
CpuTimer0Regs.TCR.bit.TRB=1; //重新装载
LED1=~LED1;
LED2=~LED2;
}
void configtestled(void)
{
EALLOW;
GpioCtrlRegs.GPBMUX2.bit.GPIO60 = 0; // GPIO60 = GPIO60 is configured as a normal digital IO
GpioCtrlRegs.GPBDIR.bit.GPIO60 = 1; // Direction is output
GpioCtrlRegs.GPBMUX2.bit.GPIO61 = 0; // GPIO61 = GPIO61
GpioCtrlRegs.GPBDIR.bit.GPIO61 = 1;
EDIS;
}
//===========================================================================================
// No more.
//============================================================================
After burning the program, you will find that LED1 and LED2 flash alternately periodically!
|