?? 5502.txt
字號:
#include <stdio.h>
#include <csl.h>
#include <csl_pll.h>
#include <csl_chip.h>
#include <csl_irq.h>
#include <csl_gpt.h>
/* Define and initialize the GPT module configuration structure 對寄存器進行配置---楊*/
GPT_Config MyGptConfig = {
0, //Emulation management register
0, //GPIO interrupt control register
0, //GPIO enable register
0, //GPIO direction register
0, //GPIO data register
0xB9EF, //Timer period register 1
0x05F5, //Timer period register 2
0, //Timer period register 3
0, //Timer period register 4
GPT_GPTCTL1_RMK( //Timer control register 1 相應位填入寄存器的相應位。取最低位
GPT_GPTCTL1_TIEN_NOT_GATED,
GPT_GPTCTL1_CLKSRC_VBUS,
GPT_GPTCTL1_ENAMODE_CONTINUOUS,
GPT_GPTCTL1_PWID_INACTIVE_1CYCLE,
GPT_GPTCTL1_CP_CLOCK_MODE,
GPT_GPTCTL1_INVIN_DONT_INVERT_OUTPUT,
GPT_GPTCTL1_INVOUT_DONT_INVERT_OUTPUT
),
GPT_GPTCTL2_RMK( //Timer control register 2
GPT_GPTCTL2_TIEN_NOT_GATED,
GPT_GPTCTL2_CLKSRC_VBUS,
GPT_GPTCTL2_ENAMODE_CONTINUOUS,
GPT_GPTCTL2_PWID_INACTIVE_1CYCLE,
GPT_GPTCTL2_CP_CLOCK_MODE,
GPT_GPTCTL2_INVIN_DONT_INVERT_OUTPUT,
GPT_GPTCTL2_INVOUT_DONT_INVERT_OUTPUT
),
GPT_GPTGCTL1_RMK( //Global timer control register
GPT_GPTGCTL1_PSC34_DEFAULT,
GPT_GPTGCTL1_TIMMODE_DEFAULT,
GPT_GPTGCTL1_TIM34RS_NOT_IN_RESET,
GPT_GPTGCTL1_TIM12RS_NOT_IN_RESET
)
};
/* 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 */
GPT_Handle hGpt;
/* Define the power-off time length of LED */
#define TIMECONST 60000
Uint16 EventId0; // 定時器0所對應的事件ID號
Uint16 LEDMARK = 0; // 設置指示燈的開關標志
Uint16 i = 0;
Uint16 j = 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(1, 0xF, 0, 1, 3, 3, 0);
/* Set IVPH/IVPD to start of interrupt vector table */
IRQ_setVecs((Uint32)(&VECSTART)); / ector 為 中斷向量筆首地址
/* Temporarily disable all maskable interrupts */
IRQ_globalDisable();
/* Open Timer 0, set registers to power on defaults */
/* And return handle of Timer 0 */
hGpt = GPT_open(GPT_DEV0, GPT_OPEN_RESET);
/* Get Event Id associated with Timer 0, for use with */
/* CSL interrupt enable functions. */
EventId0 = GPT_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 */
GPT_config(hGpt, &MyGptConfig);
/* Enable Timer interrupt */
IRQ_enable(EventId0);
/* Enable all maskable interrupts */
IRQ_globalEnable();
/* Start Timer */
GPT_start(hGpt);
/* Config GPIO7 in order to ignite led D5*/
GPIODIR = 0x80; // config the GPIO7 as output pin
for(;;)
{
/* Enter system loop and waiting for interrupt */
}
}
/*定時器0的中斷程序*/
interrupt void Timer0Isr(void)
{
if(LEDMARK==0)
{
GPIODATA = 0x00; /* 關閉指示燈D5 */
LEDMARK = 1;
}
else
{
GPIODATA = 0x80; /* 打開指示燈D5 */
LEDMARK = 0;
for(i=0;i<TIMECONST;i++)
{
for(j=0;j<100;j++)
{
CHIP_FSET(ST1_55,XF,0); /* 關指示燈D1 */
}
}
}
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -