找回密碼
 立即注冊

QQ登錄

只需一步,快速開始

搜索
查看: 3785|回復(fù): 0
收起左側(cè)

TMS325509定時(shí)器實(shí)驗(yàn) DSP實(shí)驗(yàn)程序

[復(fù)制鏈接]
ID:188297 發(fā)表于 2019-5-10 19:12 | 顯示全部樓層 |閱讀模式
DSP實(shí)驗(yàn)程序
0.png

dsp源程序如下:

  1. /********************************************************************************/
  2. /* 文件名:                5502_LED.c                                                                                                                   */                                                                                                
  3. /* 功能描述:         通過配置GPT和GPIO以及系統(tǒng)中斷來控制D5和D1兩個(gè)指示燈交替閃爍                */
  4. /*                                從而達(dá)到驗(yàn)證系統(tǒng)GPT,GPIO以及系統(tǒng)中斷的目的                                                */
  5. /* 作者:韓敬                                                                    */
  6. /* 版本:1.0                                                                     */
  7. /* 時(shí)間: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;                 // 定時(shí)器0所對應(yīng)的事件ID號
  25. Uint16 LEDMARK = 0;                // 設(shè)置指示燈的開關(guān)標(biāo)志
  26. Uint16 i = 0;
  27. Uint16 j = 0;

  28. unsigned int timer_counter=0;

  29. /* 通過定義宏來控制兩個(gè)外圍存儲器映射的寄存器,從而實(shí)現(xiàn)對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. /*定時(shí)器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;                            /*在此行設(shè)置短點(diǎn)*/
  93.         }

  94.               else
  95.              {  
  96.                       GPIODATA = 0x40;                                /* 打開指示燈D5 */
  97.                        LEDMARK = 0;                            /*在此行設(shè)置短點(diǎn)*/     
  98.               }

  99.         }
  100. }
  101.   
  102. /************************************************************************************/
  103. /*注意:         (1)        關(guān)閉指示燈D1只是臨時(shí)的,共計(jì)100*TIMECONST個(gè)指令周期                                        */
  104. /*                        這種臨時(shí)性主要體現(xiàn)在關(guān)閉指示燈D1的操作是在中斷處理子程序中進(jìn)行的                */        
  105. /*                        而且是對CPU控制寄存器的操作,由于DSP的中斷保護(hù)和恢復(fù)機(jī)制                                        */
  106. /*                        一旦退出中斷處理子程序,關(guān)閉指示燈D1的操作自動失效,即指示燈D1又自動點(diǎn)亮        */
  107. /************************************************************************************/

  108. /******************************************************************************\
  109. * End of 5502_LED.c
  110. \******************************************************************************/
復(fù)制代碼

所有資料51hei提供下載:
5509定時(shí)器實(shí)驗(yàn).7z (6.27 MB, 下載次數(shù): 22)


評分

參與人數(shù) 1黑幣 +50 收起 理由
admin + 50 共享資料的黑幣獎勵(lì)!

查看全部評分

回復(fù)

使用道具 舉報(bào)

您需要登錄后才可以回帖 登錄 | 立即注冊

本版積分規(guī)則

手機(jī)版|小黑屋|51黑電子論壇 |51黑電子論壇6群 QQ 管理員QQ:125739409;技術(shù)交流QQ群281945664

Powered by 單片機(jī)教程網(wǎng)

快速回復(fù) 返回頂部 返回列表