/**********************main.c*******************/
/* 本程序是利用定时器0计数产生中断来控制GPIO口3,4,5输出一个脉冲信号*/
/*************************************************/
#include <csl.h>
#include <csl_timer.h>
#include <csl_gpio.h>
#include <csl_irq.h>
#define PRDValue0 0x000F70E0
extern far void vectors();
Uint32 flag0 = 0;
GPIO_Handle hGpio;
TIMER_Handle hTimer0;
Uint32 TimerEventid;
//定时器配置系数结构体
TIMER_Config MyConfig0=
{
0x00000205,//CTL
PRDValue0,//PRD
0x00000000,//CNT
};
//中断处理函数
interrupt void timer0(void)
{
if(flag0==0)
{
GPIO_pinWrite(hGpio,GPIO_PIN3,0);
GPIO_pinWrite(hGpio,GPIO_PIN4,0);
GPIO_pinWrite(hGpio,GPIO_PIN5,0);
flag0=1;
}
else if(flag0==1)
{
GPIO_pinWrite(hGpio,GPIO_PIN3,1);
GPIO_pinWrite(hGpio,GPIO_PIN4,1);
GPIO_pinWrite(hGpio,GPIO_PIN5,1);
flag0=0;
}
}
void main()
{
Uint32 PinID = GPIO_PIN3 | GPIO_PIN4 | GPIO_PIN5;
//初始化CSL
CSL_init();
//打开定时器0及GPIO口
hTimer0 = TIMER_open(TIMER_DEV0, 0);
hGpio = GPIO_open(GPIO_DEV0,GPIO_OPEN_RESET);
//获取定时器0的事件号
TimerEventid = TIMER_getEventId(hTimer0);
//中断向量表的初始化
IRQ_setVecs(vectors);
IRQ_nmiEnable();
IRQ_globalEnable();
IRQ_map(TimerEventid, 14);
IRQ_reset(TimerEventid);
IRQ_enable(TimerEventid);
//对定时器0及GPIO口进行配置
TIMER_config(hTimer0, &MyConfig0);
GPIO_pinEnable(hGpio,PinID);
GPIO_pinDirection(hGpio,PinID,GPIO_OUTPUT);
//开始运行
TIMER_start(hTimer0);
for(;;);
TIMER_close(hTimer0);
GPIO_close(hGpio);
}