[资料分享] TMS320F28335GPIO实例——点亮发光二极管

fish001   2019-11-6 20:52 楼主

电路原理图如下所示:

360截图20191106205234699.jpg

代码:
#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配置为普通数字IO
   GpioCtrlRegs.GPBDIR.bit.GPIO60 = 1;  // 方向为输出
   GpioCtrlRegs.GPBMUX2.bit.GPIO61 = 0; // GPIO61 = GPIO61
   GpioCtrlRegs.GPBDIR.bit.GPIO61 = 1;
   EDIS;
}
 
//===========================================================================
// No more.
//===========================================================================

烧写程序后会发现LED1和LED2周期性交替闪烁!
 

回复评论

暂无评论,赶紧抢沙发吧
电子工程世界版权所有 京B2-20211791 京ICP备10001474号-1 京公网安备 11010802033920号
    写回复