转自:http://cchome.blog.sohu.com/88997267.html
/********************main.c********************/
//本程序利用定时器0的计数功能通过查询的方式控制GPIO口3,4,5输出脉冲
//*****************************************
#include <csl.h>
#include <csl_timer.h>
#include <csl_gpio.h>
#define PRDValue0 0x000F70E0
TIMER_Config MyConfig0=
{
0x00000205,//CTL
PRDValue0,//PRD
0x00000000,//CNT
};
void main()
{
GPIO_Handle hGpio;
TIMER_Handle hTimer0;
Uint32 PinID = GPIO_PIN3 | GPIO_PIN4 | GPIO_PIN5;
Uint32 flag0 = 0, cnt0;
//初始化CSL
CSL_init();
//打开定时器0,1及GPIO口
hTimer0 = TIMER_open(TIMER_DEV0, 0);
hGpio = GPIO_open(GPIO_DEV0,GPIO_OPEN_RESET);
//对定时器0,1及GPIO口进行配置
TIMER_config(hTimer0, &MyConfig0);
GPIO_pinEnable(hGpio,PinID);
GPIO_pinDirection(hGpio,PinID,GPIO_OUTPUT);
//开始运行
TIMER_start(hTimer0);
for(;;)
{
cnt0 = TIMER_getCount(hTimer0);
//定时器0的频率
if(cnt0==PRDValue0 &&flag0==0)
{
GPIO_pinWrite(hGpio,GPIO_PIN3,0);
GPIO_pinWrite(hGpio,GPIO_PIN4,0);
GPIO_pinWrite(hGpio,GPIO_PIN5,0);
flag0=1;
}
else if(cnt0==PRDValue0 &&flag0==1)
{
GPIO_pinWrite(hGpio,GPIO_PIN3,1);
GPIO_pinWrite(hGpio,GPIO_PIN4,1);
GPIO_pinWrite(hGpio,GPIO_PIN5,1);
flag0=0;
}
}
TIMER_close(hTimer0);
GPIO_close(hGpio);
}
//本程序只需要一个CMD文件就可以了,具体可参考前一篇文章写出的