DSP實驗程序
0.png (7.22 KB, 下載次數: 224)
下載附件
2019-5-11 03:42 上傳
dsp源程序如下:
- /********************************************************************************/
- /* 文件名: 5502_LED.c */
- /* 功能描述: 通過配置GPT和GPIO以及系統中斷來控制D5和D1兩個指示燈交替閃爍 */
- /* 從而達到驗證系統GPT,GPIO以及系統中斷的目的 */
- /* 作者:韓敬 */
- /* 版本:1.0 */
- /* 時間:2006-08-09 */
- /********************************************************************************/
- #include <stdio.h>
- #include <csl.h>
- #include <csl_pll.h>
- #include <csl_chip.h>
- #include <csl_irq.h>
- #include <csl_timer.h>
- /* Define and initialize the GPT module configuration structure */
- TIMER_Config MyTimerConfig = {0x0320,0x0ffff,0x0007};
- /* Function/ISR prototypes */
- interrupt void Timer0Isr(void);
- /* Reference start of interrupt vector table */
- /* This symbol is defined in file, vectors.s55 */
- extern void VECSTART(void);
- /* Create a TIMER_Handle object for use with TIMER_open */
- TIMER_Handle hGpt;
- Uint16 EventId0; // 定時器0所對應的事件ID號
- Uint16 LEDMARK = 0; // 設置指示燈的開關標志
- Uint16 i = 0;
- Uint16 j = 0;
- unsigned int timer_counter=0;
- /* 通過定義宏來控制兩個外圍存儲器映射的寄存器,從而實現對GPIO口的控制 */
- #define GPIODIR (*(volatile ioport Uint16*)(0x3400))
- #define GPIODATA (*(volatile ioport Uint16*)(0x3401))
- void main(void)
- {
- /* Initialize CSL library - This is REQUIRED !!! */
- CSL_init();
- /* PLL configuration structure used to set up PLL interface */
- // 主頻為300Mhz
- PLL_setFreq(4,1);
-
- /* Set IVPH/IVPD to start of interrupt vector table */
- IRQ_setVecs((Uint32)(&VECSTART));
-
- /* Temporarily disable all maskable interrupts */
- IRQ_globalDisable();
-
- /* Open Timer 0, set registers to power on defaults */
- /* And return handle of Timer 0 */
- hGpt = TIMER_open(TIMER_DEV0, TIMER_OPEN_RESET);
-
- /* Get Event Id associated with Timer 0, for use with */
- /* CSL interrupt enable functions. */
- EventId0 = TIMER_getEventId(hGpt);
-
- /* Clear any pending Timer interrupts */
- IRQ_clear(EventId0);
-
- /* Place interrupt service routine address at */
- /* associated vector location */
- IRQ_plug(EventId0,&Timer0Isr);
-
- /* Write configuration structure values to Timer control regs */
- TIMER_config(hGpt, &MyTimerConfig);
-
- /* Enable Timer interrupt */
- IRQ_enable(EventId0);
-
- /* Enable all maskable interrupts */
- IRQ_globalEnable();
-
- /* Start Timer */
- TIMER_start(hGpt);
-
- /* Config GPIO7 in order to ignite led D5*/
- GPIODIR = 0x40; // config the GPIO7 as output pin
- for(;;)
- {
- /* Enter system loop and waiting for interrupt */
-
- }
- }
- /*定時器0的中斷程序*/
- interrupt void Timer0Isr(void)
- {
- timer_counter++;
- if(timer_counter ==115)
- {
- timer_counter=0;
-
- if (LEDMARK==0)
- {
- GPIODATA = 0x00; /* 打開指示燈D5 */
- LEDMARK = 1; /*在此行設置短點*/
- }
- else
- {
- GPIODATA = 0x40; /* 打開指示燈D5 */
- LEDMARK = 0; /*在此行設置短點*/
- }
- }
- }
-
- /************************************************************************************/
- /*注意: (1) 關閉指示燈D1只是臨時的,共計100*TIMECONST個指令周期 */
- /* 這種臨時性主要體現在關閉指示燈D1的操作是在中斷處理子程序中進行的 */
- /* 而且是對CPU控制寄存器的操作,由于DSP的中斷保護和恢復機制 */
- /* 一旦退出中斷處理子程序,關閉指示燈D1的操作自動失效,即指示燈D1又自動點亮 */
- /************************************************************************************/
- /******************************************************************************\
- * End of 5502_LED.c
- \******************************************************************************/
復制代碼
所有資料51hei提供下載:
5509定時器實驗.7z
(6.27 MB, 下載次數: 22)
2019-5-11 03:43 上傳
點擊文件名下載附件
DSP實驗程序 下載積分: 黑幣 -5
|