找回密码
 立即注册

QQ登录

只需一步,快速开始

搜索
查看: 2589|回复: 0
打印 上一主题 下一主题
收起左侧

dsp DM642用定时器点亮LED 源程序

[复制链接]
跳转到指定楼层
楼主
这是dsp  DM642芯片用定时器点亮LED灯的程序


单片机源程序如下:
  1. // TI File $Revision: /main/1 $
  2. // Checkin $Date: September 21, 2007   08:58:44 $
  3. //###########################################################################
  4. //
  5. // FILE:    Example_2833xLedBlink.c
  6. //
  7. // TITLE:   DSP2833x eZdsp LED Blink Getting Started Program.
  8. //
  9. // ASSUMPTIONS:
  10. //
  11. //    This program requires the DSP2833x header files.
  12. //
  13. //
  14. //    As supplied, this project is configured for "boot to SARAM"
  15. //    operation.  The 2833x Boot Mode table is shown below.
  16. //    For information on configuring the boot mode of an eZdsp,
  17. //    please refer to the documentation included with the eZdsp,
  18. //
  19. //       $Boot_Table:
  20. //
  21. //         GPIO87   GPIO86     GPIO85   GPIO84
  22. //          XA15     XA14       XA13     XA12
  23. //           PU       PU         PU       PU
  24. //        ==========================================
  25. //            1        1          1        1    Jump to Flash
  26. //            1        1          1        0    SCI-A boot
  27. //            1        1          0        1    SPI-A boot
  28. //            1        1          0        0    I2C-A boot
  29. //            1        0          1        1    eCAN-A boot
  30. //            1        0          1        0    McBSP-A boot
  31. //            1        0          0        1    Jump to XINTF x16
  32. //            1        0          0        0    Jump to XINTF x32
  33. //            0        1          1        1    Jump to OTP
  34. //            0        1          1        0    Parallel GPIO I/O boot
  35. //            0        1          0        1    Parallel XINTF boot
  36. //            0        1          0        0    Jump to SARAM            <- "boot to SARAM"
  37. //            0        0          1        1    Branch to check boot mode
  38. //            0        0          1        0    Boot to flash, bypass ADC cal
  39. //            0        0          0        1    Boot to SARAM, bypass ADC cal
  40. //            0        0          0        0    Boot to SCI-A, bypass ADC cal
  41. //                                              Boot_Table_End$
  42. //
  43. // DESCRIPTION:
  44. //
  45. //    This example configures CPU Timer0 for a 500 msec period, and toggles the GPIO32
  46. //    LED on the 2833x eZdsp once per interrupt. For testing purposes, this example
  47. //    also increments a counter each time the timer asserts an interrupt.
  48. //
  49. //       Watch Variables:
  50. //          CpuTimer0.InterruptCount
  51. //
  52. //       Monitor the GPIO32 LED blink on (for 500 msec) and off (for 500 msec) on the 2833x eZdsp.
  53. //
  54. //###########################################################################
  55. // $TI Release: DSP2833x Header Files V1.10 $
  56. // $Release Date: February 15, 2008 $
  57. //###########################################################################


  58. #include "DSP2833x_Device.h"     // DSP2833x Headerfile Include File
  59. #include "DSP2833x_Examples.h"   // DSP2833x Examples Include File

  60. // Prototype statements for functions found within this file.
  61. interrupt void cpu_timer0_isr(void);
  62. unsigned int Count,Flag;

  63. void main(void)
  64. {

  65. // Step 1. Initialize System Control:
  66. // PLL, WatchDog, enable Peripheral Clocks
  67. // This example function is found in the DSP2833x_SysCtrl.c file.
  68.    InitSysCtrl();

  69. // Step 2. Initalize GPIO:
  70. // This example function is found in the DSP2833x_Gpio.c file and
  71. // illustrates how to set the GPIO to it's default state.
  72. // InitGpio();  // Skipped for this example


  73. // Step 3. Clear all interrupts and initialize PIE vector table:
  74. // Disable CPU interrupts
  75.    DINT;

  76. // Initialize the PIE control registers to their default state.
  77. // The default state is all PIE interrupts disabled and flags
  78. // are cleared.
  79. // This function is found in the DSP2833x_PieCtrl.c file.
  80.    InitPieCtrl();

  81. // Disable CPU interrupts and clear all CPU interrupt flags:
  82.    IER = 0x0000;
  83.    IFR = 0x0000;

  84. // Initialize the PIE vector table with pointers to the shell Interrupt
  85. // Service Routines (ISR).
  86. // This will populate the entire table, even if the interrupt
  87. // is not used in this example.  This is useful for debug purposes.
  88. // The shell ISR routines are found in DSP2833x_DefaultIsr.c.
  89. // This function is found in DSP2833x_PieVect.c.
  90.    InitPieVectTable();

  91. // Interrupts that are used in this example are re-mapped to
  92. // ISR functions found within this file.
  93.    EALLOW;  // This is needed to write to EALLOW protected registers
  94.    PieVectTable.TINT0 = &cpu_timer0_isr;

  95.    Count = 0;                                        //初始化变量
  96.    Flag=0;

  97.    EDIS;    // This is needed to disable write to EALLOW protected registers

  98. // Step 4. Initialize the Device Peripheral. This function can be
  99. //         found in DSP2833x_CpuTimers.c
  100.    InitCpuTimers();   // For this example, only initialize the Cpu Timers
  101. #if (CPU_FRQ_150MHZ)
  102. // Configure CPU-Timer 0 to interrupt every 500 milliseconds:
  103. // 150MHz CPU Freq, 50 millisecond Period (in uSeconds)
  104.    ConfigCpuTimer(&CpuTimer0, 150, 500000);
  105. #endif
  106. #if (CPU_FRQ_100MHZ)
  107. // Configure CPU-Timer 0 to interrupt every 500 milliseconds:
  108. // 100MHz CPU Freq, 50 millisecond Period (in uSeconds)
  109.    ConfigCpuTimer(&CpuTimer0, 100, 500000);
  110. #endif

  111. // To ensure precise timing, use write-only instructions to write to the entire register. Therefore, if any
  112. // of the configuration bits are changed in ConfigCpuTimer and InitCpuTimers (in DSP2833x_CpuTimers.h), the
  113. // below settings must also be updated.

  114.    CpuTimer0Regs.TCR.all = 0x4001; // Use write-only instruction to set TSS bit = 0

  115. // Step 5. User specific code, enable interrupts:

  116. // Configure GPIO0-3 as a GPIO output pin
  117.    EALLOW;
  118.    GpioCtrlRegs.GPAMUX1.bit.GPIO0 = 0;
  119.    GpioCtrlRegs.GPADIR.bit.GPIO0 = 1;
  120.    GpioCtrlRegs.GPAMUX1.bit.GPIO1 = 0;
  121.    GpioCtrlRegs.GPADIR.bit.GPIO1 = 1;
  122.    GpioCtrlRegs.GPAMUX1.bit.GPIO2 = 0;
  123.    GpioCtrlRegs.GPADIR.bit.GPIO2 = 1;
  124.    GpioCtrlRegs.GPAMUX1.bit.GPIO3 = 0;
  125.    GpioCtrlRegs.GPADIR.bit.GPIO3 = 1;
  126.    EDIS;

  127. // Enable CPU INT1 which is connected to CPU-Timer 0:
  128.    IER |= M_INT1;

  129. // Enable TINT0 in the PIE: Group 1 interrupt 7
  130.    PieCtrlRegs.PIEIER1.bit.INTx7 = 1;

  131. // Enable global Interrupts and higher priority real-time debug events:
  132.    EINT;   // Enable Global interrupt INTM
  133.    ERTM;   // Enable Global realtime interrupt DBGM

  134. // Step 6. IDLE loop. Just sit and loop forever (optional):
  135.    for(;;);
  136. }


  137. interrupt void cpu_timer0_isr(void)
  138. {
  139.    CpuTimer0.InterruptCount++;
  140.    GpioDataRegs.GPATOGGLE.bit.GPIO0 = 1; // Toggle GPIO0 once per 500 milliseconds
  141.    GpioDataRegs.GPATOGGLE.bit.GPIO1 = 1; // Toggle GPIO1 once per 500 milliseconds
  142.    GpioDataRegs.GPATOGGLE.bit.GPIO2 = 1; // Toggle GPIO2 once per 500 milliseconds
  143.    GpioDataRegs.GPATOGGLE.bit.GPIO3 = 1; // Toggle GPIO3 once per 500 milliseconds
  144.    // Acknowledge this interrupt to receive more interrupts from group 1
  145.    PieCtrlRegs.PIEACK.all = PIEACK_GROUP1;
  146. }


  147. //===========================================================================
  148. // No more.
  149. //===========================================================================
复制代码

所有资料51hei提供下载:
Ex01_ZQ28335_Timer0_LED.rar (387.17 KB, 下载次数: 4)


评分

参与人数 1黑币 +50 收起 理由
admin + 50 共享资料的黑币奖励!

查看全部评分

分享到:  QQ好友和群QQ好友和群 QQ空间QQ空间 腾讯微博腾讯微博 腾讯朋友腾讯朋友
收藏收藏 分享淘帖 顶 踩
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

手机版|小黑屋|51黑电子论坛 |51黑电子论坛6群 QQ 管理员QQ:125739409;技术交流QQ群281945664

Powered by 单片机教程网

快速回复 返回顶部 返回列表