找回密码
 立即注册

QQ登录

只需一步,快速开始

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

TMS325509定时器实验 DSP实验程序

[复制链接]
跳转到指定楼层
楼主
DSP实验程序


dsp源程序如下:

  1. /********************************************************************************/
  2. /* 文件名:                5502_LED.c                                                                                                                   */                                                                                                
  3. /* 功能描述:         通过配置GPT和GPIO以及系统中断来控制D5和D1两个指示灯交替闪烁                */
  4. /*                                从而达到验证系统GPT,GPIO以及系统中断的目的                                                */
  5. /* 作者:韩敬                                                                    */
  6. /* 版本:1.0                                                                     */
  7. /* 时间:2006-08-09                                                              */                                                                                                        
  8. /********************************************************************************/

  9. #include <stdio.h>
  10. #include <csl.h>
  11. #include <csl_pll.h>
  12. #include <csl_chip.h>
  13. #include <csl_irq.h>
  14. #include <csl_timer.h>

  15. /* Define and initialize the GPT module configuration structure  */
  16. TIMER_Config  MyTimerConfig = {0x0320,0x0ffff,0x0007};

  17. /* Function/ISR prototypes */
  18. interrupt void Timer0Isr(void);

  19. /* Reference start of interrupt vector table   */
  20. /* This symbol is defined in file, vectors.s55 */
  21. extern void VECSTART(void);

  22. /* Create a TIMER_Handle object for use with TIMER_open */
  23. TIMER_Handle          hGpt;

  24. Uint16 EventId0;                 // 定时器0所对应的事件ID号
  25. Uint16 LEDMARK = 0;                // 设置指示灯的开关标志
  26. Uint16 i = 0;
  27. Uint16 j = 0;

  28. unsigned int timer_counter=0;

  29. /* 通过定义宏来控制两个外围存储器映射的寄存器,从而实现对GPIO口的控制 */
  30. #define  GPIODIR          (*(volatile ioport Uint16*)(0x3400))
  31. #define  GPIODATA         (*(volatile ioport Uint16*)(0x3401))

  32. void main(void)
  33. {
  34.         /* Initialize CSL library - This is REQUIRED !!! */
  35.         CSL_init();

  36.         /* PLL configuration structure used to set up PLL interface */
  37.         // 主频为300Mhz
  38.     PLL_setFreq(4,1);
  39.    
  40.         /* Set IVPH/IVPD to start of interrupt vector table */
  41.         IRQ_setVecs((Uint32)(&VECSTART));
  42.          
  43.         /* Temporarily disable all maskable interrupts */
  44.         IRQ_globalDisable();   
  45.         
  46.         /* Open Timer 0, set registers to power on defaults */
  47.         /* And return handle of Timer 0 */
  48.         hGpt = TIMER_open(TIMER_DEV0, TIMER_OPEN_RESET);
  49.         
  50.         /* Get Event Id associated with Timer 0, for use with */
  51.         /* CSL interrupt enable functions.                    */         
  52.         EventId0 = TIMER_getEventId(hGpt);
  53.         
  54.         /* Clear any pending Timer interrupts */
  55.         IRQ_clear(EventId0);
  56.         
  57.         /* Place interrupt service routine address at */
  58.         /* associated vector location */
  59.         IRQ_plug(EventId0,&Timer0Isr);
  60.         
  61.         /* Write configuration structure values to Timer control regs */
  62.         TIMER_config(hGpt, &MyTimerConfig);
  63.         
  64.         /* Enable Timer interrupt */
  65.         IRQ_enable(EventId0);            
  66.         
  67.         /* Enable all maskable interrupts */
  68.         IRQ_globalEnable();      
  69.         
  70.         /* Start Timer */
  71.         TIMER_start(hGpt);
  72.          
  73.         /* Config GPIO7 in order to ignite led D5*/  
  74.         GPIODIR = 0x40;        // config the GPIO7 as output pin

  75.         for(;;)
  76.         {
  77.         /* Enter system loop and waiting for interrupt */
  78.            
  79.         }               
  80. }

  81. /*定时器0的中断程序*/
  82. interrupt void Timer0Isr(void)
  83. {
  84.     timer_counter++;

  85.           if(timer_counter ==115)
  86.           {
  87.         timer_counter=0;
  88.    
  89.             if (LEDMARK==0)
  90.                 {
  91.                           GPIODATA = 0x00;                                /* 打开指示灯D5 */
  92.                        LEDMARK = 1;                            /*在此行设置短点*/
  93.         }

  94.               else
  95.              {  
  96.                       GPIODATA = 0x40;                                /* 打开指示灯D5 */
  97.                        LEDMARK = 0;                            /*在此行设置短点*/     
  98.               }

  99.         }
  100. }
  101.   
  102. /************************************************************************************/
  103. /*注意:         (1)        关闭指示灯D1只是临时的,共计100*TIMECONST个指令周期                                        */
  104. /*                        这种临时性主要体现在关闭指示灯D1的操作是在中断处理子程序中进行的                */        
  105. /*                        而且是对CPU控制寄存器的操作,由于DSP的中断保护和恢复机制                                        */
  106. /*                        一旦退出中断处理子程序,关闭指示灯D1的操作自动失效,即指示灯D1又自动点亮        */
  107. /************************************************************************************/

  108. /******************************************************************************\
  109. * End of 5502_LED.c
  110. \******************************************************************************/
复制代码

所有资料51hei提供下载:
5509定时器实验.7z (6.27 MB, 下载次数: 22)


评分

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

查看全部评分

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

使用道具 举报

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

本版积分规则

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

Powered by 单片机教程网

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